@@ -1495,7 +1495,14 @@ function! s:VimLParser.parse_cmd_let() abort
1495
1495
" :let
1496
1496
if self .ends_excmds (self .reader.peek ())
1497
1497
call self .reader.seek_set (pos)
1498
- call self .parse_cmd_common ()
1498
+ let node = s: Node (s: NODE_LET )
1499
+ let node.pos = self .ea .cmdpos
1500
+ let node.ea = self .ea
1501
+ let node.left = s: NIL
1502
+ let node.list = s: NIL
1503
+ let node.rest = s: NIL
1504
+ let node.right = s: NIL
1505
+ call self .add_node (node)
1499
1506
return
1500
1507
endif
1501
1508
@@ -1510,8 +1517,14 @@ function! s:VimLParser.parse_cmd_let() abort
1510
1517
1511
1518
" :let {var-name} ..
1512
1519
if self .ends_excmds (s1) || (s2 !=# ' +=' && s2 !=# ' -=' && s2 !=# ' .=' && s2 !=# ' ..=' && s2 !=# ' *=' && s2 !=# ' /=' && s2 !=# ' %=' && s1 !=# ' =' )
1513
- call self .reader.seek_set (pos)
1514
- call self .parse_cmd_common ()
1520
+ let node = s: Node (s: NODE_LET )
1521
+ let node.pos = self .ea .cmdpos
1522
+ let node.ea = self .ea
1523
+ let node.left = lhs.left
1524
+ let node.list = lhs.list
1525
+ let node.rest = lhs.rest
1526
+ let node.right = s: NIL
1527
+ call self .add_node (node)
1515
1528
return
1516
1529
endif
1517
1530
@@ -1543,8 +1556,14 @@ function! s:VimLParser.parse_cmd_const() abort
1543
1556
1544
1557
" :const
1545
1558
if self .ends_excmds (self .reader.peek ())
1546
- call self .reader.seek_set (pos)
1547
- call self .parse_cmd_common ()
1559
+ let node = s: Node (s: NODE_CONST )
1560
+ let node.pos = self .ea .cmdpos
1561
+ let node.ea = self .ea
1562
+ let node.left = s: NIL
1563
+ let node.list = s: NIL
1564
+ let node.rest = s: NIL
1565
+ let node.right = s: NIL
1566
+ call self .add_node (node)
1548
1567
return
1549
1568
endif
1550
1569
@@ -1554,8 +1573,14 @@ function! s:VimLParser.parse_cmd_const() abort
1554
1573
1555
1574
" :const {var-name}
1556
1575
if self .ends_excmds (s1) || s1 !=# ' ='
1557
- call self .reader.seek_set (pos)
1558
- call self .parse_cmd_common ()
1576
+ let node = s: Node (s: NODE_CONST )
1577
+ let node.pos = self .ea .cmdpos
1578
+ let node.ea = self .ea
1579
+ let node.left = lhs.left
1580
+ let node.list = lhs.list
1581
+ let node.rest = lhs.rest
1582
+ let node.right = s: NIL
1583
+ call self .add_node (node)
1559
1584
return
1560
1585
endif
1561
1586
@@ -4996,23 +5021,20 @@ function! s:Compiler.compile_excall(node) abort
4996
5021
endfunction
4997
5022
4998
5023
function ! s: Compiler .compile_let (node) abort
4999
- let left = ' '
5000
- if a: node .left isnot # s: NIL
5001
- let left = self .compile (a: node .left )
5002
- else
5003
- let left = join (map (a: node .list , ' self.compile(v:val)' ), ' ' )
5004
- if a: node .rest isnot # s: NIL
5005
- let left .= ' . ' . self .compile (a: node .rest)
5006
- endif
5007
- let left = ' (' . left . ' )'
5008
- endif
5009
- let right = self .compile (a: node .right )
5010
- call self .out (' (let %s %s %s)' , a: node .op , left , right )
5024
+ call self .compile_letconst (a: node , ' let' )
5011
5025
endfunction
5012
5026
5013
- " TODO: merge with s:Compiler.compile_let() ?
5014
5027
function ! s: Compiler .compile_const (node) abort
5028
+ call self .compile_letconst (a: node , ' const' )
5029
+ endfunction
5030
+
5031
+ function ! s: Compiler .compile_letconst (node, cmd) abort
5015
5032
let left = ' '
5033
+ let right = ' '
5034
+ if a: node .left is # s: NIL && a: node .right is # s: NIL
5035
+ call self .out (' (%s)' , a: cmd )
5036
+ return
5037
+ endif
5016
5038
if a: node .left isnot # s: NIL
5017
5039
let left = self .compile (a: node .left )
5018
5040
else
@@ -5022,8 +5044,14 @@ function! s:Compiler.compile_const(node) abort
5022
5044
endif
5023
5045
let left = ' (' . left . ' )'
5024
5046
endif
5025
- let right = self .compile (a: node .right )
5026
- call self .out (' (const %s %s %s)' , a: node .op , left , right )
5047
+ if a: node .right isnot # s: NIL
5048
+ let right = self .compile (a: node .right )
5049
+ endif
5050
+ if a: node .left isnot # s: NIL && a: node .right is # s: NIL
5051
+ call self .out (' (%s () %s)' , a: cmd , left )
5052
+ else
5053
+ call self .out (' (%s %s %s %s)' , a: cmd , a: node .op , left , right )
5054
+ endif
5027
5055
endfunction
5028
5056
5029
5057
function ! s: Compiler .compile_unlet (node) abort
0 commit comments