Skip to content

Commit 685ad2c

Browse files
committed
feat: support last argument append with comma
1 parent c4d4625 commit 685ad2c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

parser/parser.go

+7
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,10 @@ func (p *parser) parseCall(token Token, arguments []Node, checkOverrides bool) N
451451
arguments = append(arguments, node)
452452
}
453453

454+
// skip last comma
455+
if p.current.Is(Operator, ",") {
456+
p.next()
457+
}
454458
p.expect(Bracket, ")")
455459

456460
node = &BuiltinNode{
@@ -486,6 +490,9 @@ func (p *parser) parseArguments(arguments []Node) []Node {
486490
if len(arguments) > offset {
487491
p.expect(Operator, ",")
488492
}
493+
if p.current.Is(Bracket, ")") {
494+
break
495+
}
489496
node := p.parseExpression(0)
490497
arguments = append(arguments, node)
491498
}

parser/parser_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,39 @@ world`},
647647
Right: &BoolNode{Value: true},
648648
},
649649
},
650+
{
651+
`all(
652+
[true, false],
653+
#,
654+
)`,
655+
&BuiltinNode{
656+
Name: "all",
657+
Arguments: []Node{
658+
&ArrayNode{
659+
Nodes: []Node{
660+
&BoolNode{Value: true},
661+
&BoolNode{Value: false},
662+
},
663+
},
664+
&ClosureNode{
665+
Node: &PointerNode{},
666+
},
667+
},
668+
},
669+
},
670+
{
671+
`func(
672+
parameter1,
673+
parameter2,
674+
)`,
675+
&CallNode{
676+
Callee: &IdentifierNode{Value: "func"},
677+
Arguments: []Node{
678+
&IdentifierNode{Value: "parameter1"},
679+
&IdentifierNode{Value: "parameter2"},
680+
},
681+
},
682+
},
650683
}
651684
for _, test := range tests {
652685
t.Run(test.input, func(t *testing.T) {

0 commit comments

Comments
 (0)