@@ -3234,56 +3234,17 @@ function! s:ExprParser.parse_expr9()
32343234 endwhile
32353235 endif
32363236 elseif token.type == s: TOKEN_COPEN
3237- let node = s: Node (-1 )
3238- let p = token.pos
3239- let token = self .tokenizer.peek ()
3240- if token.type == s: TOKEN_CCLOSE
3241- " dict
3242- call self .tokenizer.get ()
3243- let node = s: Node (s: NODE_DICT )
3244- let node.pos = p
3245- let node.value = []
3246- elseif token.type == s: TOKEN_DQUOTE || token.type == s: TOKEN_SQUOTE
3247- " dict
3248- let node = s: Node (s: NODE_DICT )
3249- let node.pos = p
3250- let node.value = []
3251- while 1
3252- let key = self .parse_expr1 ()
3253- let token = self .tokenizer.get ()
3254- if token.type == s: TOKEN_CCLOSE
3255- if ! empty (node.value)
3256- throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
3257- endif
3258- call self .reader.seek_set (pos)
3259- let node = self .parse_identifier ()
3260- break
3261- endif
3262- if token.type != s: TOKEN_COLON
3263- throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
3264- endif
3265- let val = self .parse_expr1 ()
3266- call add (node.value, [key , val])
3267- let token = self .tokenizer.get ()
3268- if token.type == s: TOKEN_COMMA
3269- if self .tokenizer.peek ().type == s: TOKEN_CCLOSE
3270- call self .tokenizer.get ()
3271- break
3272- endif
3273- elseif token.type == s: TOKEN_CCLOSE
3274- break
3275- else
3276- throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
3277- endif
3278- endwhile
3279- else
3280- " lambda ref: s:NODE_FUNCTION
3237+ let savepos = self .reader.tell ()
3238+ let nodepos = token.pos
3239+ 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
3242+ " lambda {token,...} {->...} {token->...}
32813243 let node = s: Node (s: NODE_LAMBDA )
3282- let node.pos = p
3244+ let node.pos = nodepos
32833245 let node.rlist = []
32843246 let named = {}
32853247 while 1
3286- let token = self .tokenizer.get ()
32873248 if token.type == s: TOKEN_ARROW
32883249 break
32893250 elseif token.type == s: TOKEN_IDENTIFIER
@@ -3301,19 +3262,11 @@ function! s:ExprParser.parse_expr9()
33013262 throw s: Err (' E475: Invalid argument: White space is not allowed before comma' , self .reader.getpos ())
33023263 endif
33033264 let token = self .tokenizer.get ()
3304- " handle curly_parts
3305- if token.type == s: TOKEN_COPEN || token.type == s: TOKEN_CCLOSE
3306- if ! empty (node.rlist)
3307- throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
3308- endif
3309- call self .reader.seek_set (pos)
3310- let node = self .parse_identifier ()
3311- return node
3312- endif
33133265 call add (node.rlist, varnode)
33143266 if token.type == s: TOKEN_COMMA
33153267 " XXX: Vim allows last comma. {a, b, -> ...} => OK
3316- if self .reader.peekn (2 ) == ' ->'
3268+ let token = self .tokenizer.peek ()
3269+ if token.type == s: TOKEN_ARROW
33173270 call self .tokenizer.get ()
33183271 break
33193272 endif
@@ -3327,22 +3280,64 @@ function! s:ExprParser.parse_expr9()
33273280 let varnode.pos = token.pos
33283281 let varnode.value = token.value
33293282 call add (node.rlist, varnode)
3330- let token = self .tokenizer.get ()
3283+ let token = self .tokenizer.peek ()
33313284 if token.type == s: TOKEN_ARROW
3285+ call self .tokenizer.get ()
33323286 break
33333287 else
33343288 throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
33353289 endif
33363290 else
33373291 throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
33383292 endif
3293+ let token = self .tokenizer.get ()
33393294 endwhile
33403295 let node.left = self .parse_expr1 ()
33413296 let token = self .tokenizer.get ()
33423297 if token.type != s: TOKEN_CCLOSE
33433298 throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
33443299 endif
3300+ return node
3301+ endif
3302+ " dict
3303+ let node = s: Node (s: NODE_DICT )
3304+ let node.pos = nodepos
3305+ let node.value = []
3306+ call self .reader.seek_set (savepos)
3307+ let token = self .tokenizer.peek ()
3308+ if token.type == s: TOKEN_CCLOSE
3309+ call self .tokenizer.get ()
3310+ return node
33453311 endif
3312+ while 1
3313+ let key = self .parse_expr1 ()
3314+ let token = self .tokenizer.get ()
3315+ if token.type == s: TOKEN_CCLOSE
3316+ if ! empty (node.value)
3317+ throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
3318+ endif
3319+ call self .reader.seek_set (pos)
3320+ let node = self .parse_identifier ()
3321+ break
3322+ endif
3323+ if token.type != s: TOKEN_COLON
3324+ throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
3325+ endif
3326+ let val = self .parse_expr1 ()
3327+ call add (node.value, [key , val])
3328+ let token = self .tokenizer.get ()
3329+ if token.type == s: TOKEN_COMMA
3330+ if self .tokenizer.peek ().type == s: TOKEN_CCLOSE
3331+ call self .tokenizer.get ()
3332+ break
3333+ endif
3334+ elseif token.type == s: TOKEN_CCLOSE
3335+ break
3336+ else
3337+ throw s: Err (printf (' unexpected token: %s' , token.value), token.pos)
3338+ endif
3339+ endwhile
3340+ return node
33463341 elseif token.type == s: TOKEN_POPEN
33473342 let node = self .parse_expr1 ()
33483343 let token = self .tokenizer.get ()
0 commit comments