Skip to content

Commit

Permalink
fix: correct recovery of positional parameters
Browse files Browse the repository at this point in the history
We'd otherwise recover incomplete path expressions inside
function invocations as `NamedParameters` rather than
`PositionalParameters`.

Before this change:

```
// correctly handled as positional (with error)
bar(foo., baz)

// incorrectly handled as named
bar(foo., bazzzzzz)
```
  • Loading branch information
nikku committed Jun 14, 2024
1 parent f4a4270 commit 6753218
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/feel.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pathExpressionStart[@export] {
"."
}

PathExpression {
PathExpression[@dynamicPrecedence=1] {
expression !path pathExpressionStart VariableName
}

Expand Down
87 changes: 87 additions & 0 deletions test/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,35 @@ Expressions(
)


# FunctionInvocation (positional, error) { "top": "Expressions" }

bar(foo., bazzzzzz);
bar(foo., baz)

==>

Expressions(

FunctionInvocation(VariableName(...), "(",
PositionalParameters(
PathExpression(
VariableName(...), ⚠
),
VariableName(...)
),
")"),

FunctionInvocation(VariableName(...), "(",
PositionalParameters(
PathExpression(
VariableName(...), ⚠
),
VariableName(...)
),
")")
)


# FunctionInvocation (named) { "top": "Expressions" }

a(foo: f, bar: b, other: o);
Expand All @@ -1679,6 +1708,64 @@ Expressions(
)


# FunctionInvocation (named, error) { "top": "Expressions" }

bar(foo: foo., baz: bazzzzzz);
bar(foo: foo., baz: baz);
bar(foo: foo., bazzzzzz);
bar(foo: foo., baz)

==>

Expressions(

FunctionInvocation(VariableName(Identifier),"(",
NamedParameters(
NamedParameter(
ParameterName(...),
PathExpression(VariableName(...),⚠)
),
NamedParameter(
ParameterName(...),
VariableName(...)
)
),
")"),

FunctionInvocation(VariableName(Identifier),"(",
NamedParameters(
NamedParameter(
ParameterName(...),
PathExpression(VariableName(...),⚠)
),
NamedParameter(
ParameterName(...),
VariableName(...)
)
),
")"),

FunctionInvocation(VariableName(Identifier),"(",
NamedParameters(
NamedParameter(
ParameterName(...),
PathExpression(VariableName(...),⚠,VariableName(...))
)
),
")"),

FunctionInvocation(VariableName(Identifier),"(",
NamedParameters(
NamedParameter(
ParameterName(...),
PathExpression(VariableName(...),⚠,VariableName(...))
)
),
")")

)


# FunctionInvocation (positional, arithmetics) { "top": "Expressions" }

a(x-y);
Expand Down

0 comments on commit 6753218

Please sign in to comment.