mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
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]>
This commit is contained in:
committed by
GitHub
co-authored by
Anton Medvedev
parent
80eb95bf5f
commit
18e2e03c5a
@@ -549,6 +549,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 = p.createNode(&BuiltinNode{
|
||||
@@ -593,6 +597,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)
|
||||
}
|
||||
|
||||
@@ -839,6 +839,42 @@ world`},
|
||||
Expr: &IdentifierNode{Value: "x"},
|
||||
},
|
||||
},
|
||||
{
|
||||
`all(
|
||||
[
|
||||
true,
|
||||
false,
|
||||
],
|
||||
#,
|
||||
)`,
|
||||
&BuiltinNode{
|
||||
Name: "all",
|
||||
Arguments: []Node{
|
||||
&ArrayNode{
|
||||
Nodes: []Node{
|
||||
&BoolNode{Value: true},
|
||||
&BoolNode{Value: false},
|
||||
},
|
||||
},
|
||||
&PredicateNode{
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user