@@ -128,6 +128,7 @@ let s:NODE_CURLYNAME = 87
128
128
let s: NODE_ENV = 88
129
129
let s: NODE_REG = 89
130
130
let s: NODE_CURLYNAMEPART = 90
131
+ let s: NODE_CURLYNAMEEXPR = 91
131
132
132
133
let s: TOKEN_EOF = 1
133
134
let s: TOKEN_EOL = 2
@@ -390,6 +391,8 @@ endfunction
390
391
" CURLYNAME .value
391
392
" ENV .value
392
393
" REG .value
394
+ " CURLYNAMEPART .value
395
+ " CURLYNAMEEXPR .value
393
396
function ! s: Node (type )
394
397
return {' type' : a: type }
395
398
endfunction
@@ -3265,8 +3268,7 @@ function! s:ExprParser.parse_identifier()
3265
3268
if c == # ' <' && self .reader.peekn (5 ) == ? ' <SID>'
3266
3269
let name = self .reader.getn (5 )
3267
3270
let node_1 = s: Node (s: NODE_CURLYNAMEPART )
3268
- let node_1.curly = 0
3269
- let node_1.pos = npos
3271
+ let node_1.pos = self .reader.getpos ()
3270
3272
let node_1.value = name
3271
3273
call add (id, node_1)
3272
3274
endif
@@ -3275,29 +3277,28 @@ function! s:ExprParser.parse_identifier()
3275
3277
if s: isnamec (c )
3276
3278
let name = self .reader.read_name ()
3277
3279
let node_2 = s: Node (s: NODE_CURLYNAMEPART )
3278
- let node_2.curly = 0
3279
- let node_2.pos = npos
3280
+ let node_2.pos = self .reader.getpos ()
3280
3281
let node_2.value = name
3281
3282
call add (id, node_2)
3282
3283
elseif c == # ' {'
3283
3284
call self .reader.get ()
3285
+ let pos_3 = self .reader.getpos ()
3284
3286
let node = self .parse_expr1 ()
3285
3287
call self .reader.skip_white ()
3286
3288
let c = self .reader.p (0 )
3287
3289
if c !=# ' }'
3288
3290
throw s: Err (printf (' unexpected token: %s' , c ), self .reader.getpos ())
3289
3291
endif
3290
3292
call self .reader.seek_cur (1 )
3291
- let node_3 = s: Node (s: NODE_CURLYNAMEPART )
3292
- let node_3.curly = 1
3293
- let node_3.pos = npos
3294
- let node_3.value = id[0 ].value
3293
+ let node_3 = s: Node (s: NODE_CURLYNAMEEXPR )
3294
+ let node_3.pos = pos_3
3295
+ let node_3.value = node
3295
3296
call add (id, node_3)
3296
3297
else
3297
3298
break
3298
3299
endif
3299
3300
endwhile
3300
- if len (id) == 1 && id[0 ].curly == 0
3301
+ if len (id) == 1 && id[0 ].type == s: NODE_CURLYNAMEPART
3301
3302
let node = s: Node (s: NODE_IDENTIFIER )
3302
3303
let node.pos = npos
3303
3304
let node.value = id[0 ].value
@@ -3851,6 +3852,10 @@ function! s:Compiler.compile(node)
3851
3852
return self .compile_env (a: node )
3852
3853
elseif a: node .type == s: NODE_REG
3853
3854
return self .compile_reg (a: node )
3855
+ elseif a: node .type == s: NODE_CURLYNAMEPART
3856
+ return self .compile_curlynamepart (a: node )
3857
+ elseif a: node .type == s: NODE_CURLYNAMEEXPR
3858
+ return self .compile_curlynameexpr (a: node )
3854
3859
else
3855
3860
throw printf (' Compiler: unknown node: %s' , string (a: node ))
3856
3861
endif
@@ -4287,15 +4292,7 @@ function! s:Compiler.compile_identifier(node)
4287
4292
endfunction
4288
4293
4289
4294
function ! s: Compiler .compile_curlyname (node)
4290
- let name = ' '
4291
- for x in a: node .value
4292
- if x .curly
4293
- let name .= ' {' . self .compile (x .value) . ' }'
4294
- else
4295
- let name .= x .value
4296
- endif
4297
- endfor
4298
- return name
4295
+ return join (map (a: node .value, ' self.compile(v:val)' ), ' ' )
4299
4296
endfunction
4300
4297
4301
4298
function ! s: Compiler .compile_env (node)
@@ -4306,6 +4303,14 @@ function! s:Compiler.compile_reg(node)
4306
4303
return a: node .value
4307
4304
endfunction
4308
4305
4306
+ function ! s: Compiler .compile_curlynamepart (node)
4307
+ return a: node .value
4308
+ endfunction
4309
+
4310
+ function ! s: Compiler .compile_curlynameexpr (node)
4311
+ return ' {' . self .compile (a: node .value) . ' }'
4312
+ endfunction
4313
+
4309
4314
" TODO: under construction
4310
4315
let s: RegexpParser = {}
4311
4316
0 commit comments