Skip to content

Commit

Permalink
feat: support last argument append with comma
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuliquan committed Apr 9, 2024
1 parent c4d4625 commit 685ad2c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ func (p *parser) parseCall(token Token, arguments []Node, checkOverrides bool) N
arguments = append(arguments, node)
}

// skip last comma
if p.current.Is(Operator, ",") {
p.next()
}
p.expect(Bracket, ")")

node = &BuiltinNode{
Expand Down Expand Up @@ -486,6 +490,9 @@ func (p *parser) parseArguments(arguments []Node) []Node {
if len(arguments) > offset {
p.expect(Operator, ",")
}
if p.current.Is(Bracket, ")") {
break
}
node := p.parseExpression(0)
arguments = append(arguments, node)
}
Expand Down
33 changes: 33 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,39 @@ world`},
Right: &BoolNode{Value: true},
},
},
{
`all(
[true, false],
#,
)`,
&BuiltinNode{
Name: "all",
Arguments: []Node{
&ArrayNode{
Nodes: []Node{
&BoolNode{Value: true},
&BoolNode{Value: false},
},
},
&ClosureNode{
Node: &PointerNode{},
},
},
},
},
{
`func(
parameter1,
parameter2,
)`,
&CallNode{
Callee: &IdentifierNode{Value: "func"},
Arguments: []Node{
&IdentifierNode{Value: "parameter1"},
&IdentifierNode{Value: "parameter2"},
},
},
},
}
for _, test := range tests {
t.Run(test.input, func(t *testing.T) {
Expand Down

0 comments on commit 685ad2c

Please sign in to comment.