Reply to message «Re: Vim Script grammer», 
sent 22:38:50 11 July 2011, Monday
by Peter Odding:

>  - Vim script commands determine how their arguments are parsed so there
> doesn't seem to be a universal way to parse Vim script code -- it
> depends on the commands involved (e.g. normally you can use | to begin a
> new command on the same line but this does not work if the line starts
> with any of the :map commands)
It applies only to builtins and there is only three behaviors that should be 
taken into consideration while splitting stream into sequence of commands:
1. Bar and NL can be taken as a part of a string literal (only for builtins, NL 
behavior depends on context), in other cases they terminate the command. 
Comments are not allowed.
2. Bar and NL terminate the command. Comments are allowed.
3. Bar does not terminate the command. Comments are not allowed. NL behavior 
depends on context.
If you know more, please write this here.

Arguments parsing seems less problematic then splitting into a sequence of 
commands.

>  - Every command can be abbreviated (:function can be shortened to :fu,
It can be solved by using an ordered list of commands and taking first partial 
match if there are no full matches, can't it?

Original message:
> > Hello,
> > 
> > Is the Vim Script grammar documented anywhere? I'd like to write a
> > parser.
> > 
> > (Searching for "vim script grammar/parser" brings up grammars/parsers
> > written _in_ vim script, unfortunately...)
> > 
> > 
> > Thanks!
> > 
> > -Charles
> 
> I've never seen a Vim script parser except for the one included in the
> Vim sources and not to discourage you (I myself like a good challenge
> ;-) but I suspect that writing a parser for Vim script will turn ugly
> very quickly:
> 
>  - Vim script commands determine how their arguments are parsed so there
> doesn't seem to be a universal way to parse Vim script code -- it
> depends on the commands involved (e.g. normally you can use | to begin a
> new command on the same line but this does not work if the line starts
> with any of the :map commands)
> 
>  - Every command can be abbreviated (:function can be shortened to :fu,
> 
> :fun, :func, :funct, you get the point) and some abbreviated commands
> 
> have priority over other commands (:e always means :edit, no matter
> which commands starting with :e have been defined)
> 
> Good luck if you decide to go through with writing a Vim script parser!
> I suspect that your best starting point would be :help eval.txt.
> 
>  - Peter Odding

Attachment: signature.asc
Description: This is a digitally signed message part.

Raspunde prin e-mail lui