Skip to content

Commit c1461d0

Browse files
committed
vim: add NODE_PARENEXPR
1 parent be58314 commit c1461d0

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

autoload/vimlparser.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ let s:NODE_REG = 89
137137
let s:NODE_CURLYNAMEPART = 90
138138
let s:NODE_CURLYNAMEEXPR = 91
139139
let s:NODE_LAMBDA = 92
140+
let s:NODE_PARENEXPR = 93
140141

141142
let s:TOKEN_EOF = 1
142143
let s:TOKEN_EOL = 2
@@ -403,6 +404,7 @@ endfunction
403404
" CURLYNAMEPART .value
404405
" CURLYNAMEEXPR .value
405406
" LAMBDA .rlist .left
407+
" PARENEXPR .value
406408
function! s:Node(type)
407409
return {'type': a:type}
408410
endfunction
@@ -3514,7 +3516,9 @@ function! s:ExprParser.parse_expr9()
35143516
endwhile
35153517
return node
35163518
elseif token.type == s:TOKEN_POPEN
3517-
let node = self.parse_expr1()
3519+
let node = s:Node(s:NODE_PARENEXPR)
3520+
let node.pos = token.pos
3521+
let node.value = self.parse_expr1()
35183522
let token = self.tokenizer.get()
35193523
if token.type != s:TOKEN_PCLOSE
35203524
throw s:Err(printf('unexpected token: %s', token.value), token.pos)
@@ -4185,6 +4189,8 @@ function! s:Compiler.compile(node)
41854189
return self.compile_curlynameexpr(a:node)
41864190
elseif a:node.type == s:NODE_LAMBDA
41874191
return self.compile_lambda(a:node)
4192+
elseif a:node.type == s:NODE_PARENEXPR
4193+
return self.compile_parenexpr(a:node)
41884194
else
41894195
throw printf('Compiler: unknown node: %s', string(a:node))
41904196
endif
@@ -4648,6 +4654,10 @@ function! s:Compiler.compile_lambda(node)
46484654
return printf('(lambda (%s) %s)', join(rlist, ' '), self.compile(a:node.left))
46494655
endfunction
46504656

4657+
function! s:Compiler.compile_parenexpr(node)
4658+
return self.compile(a:node.value)
4659+
endfunction
4660+
46514661
" TODO: under construction
46524662
let s:RegexpParser = {}
46534663

test/test_parenexpr.ok

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; test_parenexpr
2+
(echo 1)
3+
(echo 1)
4+
(echo (+ (+ 1 1) 2))
5+
(echo (+ (+ 1 1) (* 2 (+ 3 4))))

test/test_parenexpr.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
" test_parenexpr
2+
echo (1)
3+
echo ((1))
4+
echo ((1+1) + 2)
5+
echo ((1+1) + 2 * (3 + 4))

0 commit comments

Comments
 (0)