Skip to content

Commit 8f83203

Browse files
zhuliquanantonmedv
andauthored
Allow tailing comma in arguments (#623)
* feat: extract code for compiling equal operator * feat: support last argument append with comma --------- Co-authored-by: Anton Medvedev <[email protected]>
1 parent 435b79d commit 8f83203

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

parser/parser.go

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

552+
// skip last comma
553+
if p.current.Is(Operator, ",") {
554+
p.next()
555+
}
552556
p.expect(Bracket, ")")
553557

554558
node = p.createNode(&BuiltinNode{
@@ -593,6 +597,9 @@ func (p *parser) parseArguments(arguments []Node) []Node {
593597
if len(arguments) > offset {
594598
p.expect(Operator, ",")
595599
}
600+
if p.current.Is(Bracket, ")") {
601+
break
602+
}
596603
node := p.parseExpression(0)
597604
arguments = append(arguments, node)
598605
}

parser/parser_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,42 @@ world`},
839839
Expr: &IdentifierNode{Value: "x"},
840840
},
841841
},
842+
{
843+
`all(
844+
[
845+
true,
846+
false,
847+
],
848+
#,
849+
)`,
850+
&BuiltinNode{
851+
Name: "all",
852+
Arguments: []Node{
853+
&ArrayNode{
854+
Nodes: []Node{
855+
&BoolNode{Value: true},
856+
&BoolNode{Value: false},
857+
},
858+
},
859+
&PredicateNode{
860+
Node: &PointerNode{},
861+
},
862+
},
863+
},
864+
},
865+
{
866+
`func(
867+
parameter1,
868+
parameter2,
869+
)`,
870+
&CallNode{
871+
Callee: &IdentifierNode{Value: "func"},
872+
Arguments: []Node{
873+
&IdentifierNode{Value: "parameter1"},
874+
&IdentifierNode{Value: "parameter2"},
875+
},
876+
},
877+
},
842878
}
843879
for _, test := range tests {
844880
t.Run(test.input, func(t *testing.T) {

0 commit comments

Comments
 (0)