Skip to content

Commit f48fbe0

Browse files
committed
fix peeking inside string
1 parent c52c73c commit f48fbe0

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

autoload/vimlparser.vim

+8-2
Original file line numberDiff line numberDiff line change
@@ -3237,8 +3237,14 @@ function! s:ExprParser.parse_expr9()
32373237
let savepos = self.reader.tell()
32383238
let nodepos = token.pos
32393239
let token = self.tokenizer.get()
3240-
let token2 = self.tokenizer.peek()
3241-
if token.type == s:TOKEN_ARROW || token2.type == s:TOKEN_ARROW || token2.type == s:TOKEN_COMMA
3240+
let lambda = token.type == s:TOKEN_ARROW
3241+
if !lambda && !(token.type == s:TOKEN_SQUOTE || token.type == s:TOKEN_DQUOTE)
3242+
" if the token type is stirng, we cannot peek next token and we can
3243+
" assume it's not lambda.
3244+
let token2 = self.tokenizer.peek()
3245+
let lambda = token2.type == s:TOKEN_ARROW || token2.type == s:TOKEN_COMMA
3246+
endif
3247+
if lambda
32423248
" lambda {token,...} {->...} {token->...}
32433249
let node = s:Node(s:NODE_LAMBDA)
32443250
let node.pos = nodepos

test/test_dict.ok

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
(echo (dict ('1' 1)))
44
(echo (dict (1 1)))
55
(echo (dict (x 1)))
6+
(echo (dict ("\<cr>" 1)))
7+
(echo (dict ("vim" 1)))
8+
(echo (dict ((+ 1 1) 2)))
69
; XXX: echo {x:1}

test/test_dict.vim

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ echo {}
33
echo {'1': 1}
44
echo {1: 1}
55
echo {x : 1}
6+
echo {"\<cr>": 1}
7+
echo {"vim": 1}
8+
echo {1+1:2}
69
" XXX: echo {x:1}
7-

0 commit comments

Comments
 (0)