Created
July 19, 2017 16:07
-
-
Save haya14busa/0c38bf1a55618dc1d7da09c87d3f732a to your computer and use it in GitHub Desktop.
vimlparser diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- vim-jp/vim-vimlparser/autoload/vimlparser.vim 2017-07-19 15:49:59.859034000 +0000 | |
+++ haya14busa/go-vimlparser/autoload/vimlparser.vim 2017-07-19 15:57:45.642696899 +0000 | |
@@ -137,6 +137,7 @@ | |
let s:NODE_CURLYNAMEPART = 90 | |
let s:NODE_CURLYNAMEEXPR = 91 | |
let s:NODE_LAMBDA = 92 | |
+let s:NODE_PARENEXPR = 93 | |
let s:TOKEN_EOF = 1 | |
let s:TOKEN_EOL = 2 | |
@@ -403,6 +404,7 @@ | |
" CURLYNAMEPART .value | |
" CURLYNAMEEXPR .value | |
" LAMBDA .rlist .left | |
+" PARENEXPR .value | |
function! s:Node(type) | |
return {'type': a:type} | |
endfunction | |
@@ -745,7 +747,7 @@ | |
let self.ea.forceit = s:FALSE | |
endif | |
- if self.ea.cmd.flags !~# '\<BANG\>' && self.ea.forceit && self.ea.cmd.flags !~# '\<USERCMD\>' | |
+ if self.ea.cmd.flags !~# '\<BANG\>' && self.ea.forceit && self.ea.cmd.flags !~# 'USERCMD' | |
throw s:Err('E477: No ! allowed', self.ea.cmdpos) | |
endif | |
@@ -796,9 +798,16 @@ | |
call self.parse_argcmd() | |
endif | |
+ " call self[self.ea.cmd.parser]() | |
call self._parse_command(self.ea.cmd.parser) | |
endfunction | |
+" let s:parsers = sort(keys(filter(copy(s:VimLParser), { k -> k =~# '\v^parse_(win)?cmd' }))) | |
+" for s:parser in s:parsers | |
+" echo printf("elseif a:parser == '%s'", s:parser) | |
+" echo printf(" call self.%s()", s:parser) | |
+" endfor | |
+" echo 'endif' | |
function! s:VimLParser._parse_command(parser) abort | |
if a:parser == 'parse_cmd_append' | |
call self.parse_cmd_append() | |
@@ -892,8 +901,6 @@ | |
call self.parse_wincmd() | |
elseif a:parser == 'parse_cmd_syntax' | |
call self.parse_cmd_syntax() | |
- else | |
- throw printf('unknown parser: %s', string(a:parser)) | |
endif | |
endfunction | |
@@ -939,7 +946,7 @@ | |
endif | |
endfor | |
- if self.neovim | |
+ if self.neovim | |
for x in self.neovim_additional_commands | |
if stridx(x.name, name) == 0 && len(name) >= x.minlen | |
unlet cmd | |
@@ -956,7 +963,7 @@ | |
endif | |
endfor | |
endif | |
- | |
+ | |
" FIXME: user defined command | |
if (cmd is s:NIL || cmd.name ==# 'Print') && name =~# '^[A-Z]' | |
let name .= self.reader.read_alnum() | |
@@ -3517,7 +3524,9 @@ | |
endwhile | |
return node | |
elseif token.type == s:TOKEN_POPEN | |
- let node = self.parse_expr1() | |
+ let node = s:Node(s:NODE_PARENEXPR) | |
+ let node.pos = token.pos | |
+ let node.value = self.parse_expr1() | |
let token = self.tokenizer.get() | |
if token.type != s:TOKEN_PCLOSE | |
throw s:Err(printf('unexpected token: %s', token.value), token.pos) | |
@@ -4030,73 +4039,50 @@ | |
return self.compile_toplevel(a:node) | |
elseif a:node.type == s:NODE_COMMENT | |
call self.compile_comment(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_EXCMD | |
call self.compile_excmd(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_FUNCTION | |
call self.compile_function(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_DELFUNCTION | |
call self.compile_delfunction(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_RETURN | |
call self.compile_return(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_EXCALL | |
call self.compile_excall(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_LET | |
call self.compile_let(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_UNLET | |
call self.compile_unlet(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_LOCKVAR | |
call self.compile_lockvar(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_UNLOCKVAR | |
call self.compile_unlockvar(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_IF | |
call self.compile_if(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_WHILE | |
call self.compile_while(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_FOR | |
call self.compile_for(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_CONTINUE | |
call self.compile_continue(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_BREAK | |
call self.compile_break(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_TRY | |
call self.compile_try(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_THROW | |
call self.compile_throw(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_ECHO | |
call self.compile_echo(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_ECHON | |
call self.compile_echon(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_ECHOHL | |
call self.compile_echohl(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_ECHOMSG | |
call self.compile_echomsg(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_ECHOERR | |
call self.compile_echoerr(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_EXECUTE | |
call self.compile_execute(a:node) | |
- return s:NIL | |
elseif a:node.type == s:NODE_TERNARY | |
return self.compile_ternary(a:node) | |
elseif a:node.type == s:NODE_OR | |
@@ -4213,6 +4199,8 @@ | |
return self.compile_curlynameexpr(a:node) | |
elseif a:node.type == s:NODE_LAMBDA | |
return self.compile_lambda(a:node) | |
+ elseif a:node.type == s:NODE_PARENEXPR | |
+ return self.compile_parenexpr(a:node) | |
else | |
throw printf('Compiler: unknown node: %s', string(a:node)) | |
endif | |
@@ -4296,7 +4284,7 @@ | |
if a:node.depth is s:NIL | |
call self.out('(lockvar %s)', join(list, ' ')) | |
else | |
- call self.out('(lockvar %s %s)', a:node.depth, join(list, ' ')) | |
+ call self.out('(lockvar %d %s)', a:node.depth, join(list, ' ')) | |
endif | |
endfunction | |
@@ -4305,7 +4293,7 @@ | |
if a:node.depth is s:NIL | |
call self.out('(unlockvar %s)', join(list, ' ')) | |
else | |
- call self.out('(unlockvar %s %s)', a:node.depth, join(list, ' ')) | |
+ call self.out('(unlockvar %d %s)', a:node.depth, join(list, ' ')) | |
endif | |
endfunction | |
@@ -4676,6 +4664,10 @@ | |
return printf('(lambda (%s) %s)', join(rlist, ' '), self.compile(a:node.left)) | |
endfunction | |
+function! s:Compiler.compile_parenexpr(node) | |
+ return self.compile(a:node.value) | |
+endfunction | |
+ | |
" TODO: under construction | |
let s:RegexpParser = {} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment