Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Ramstack.ExpressionParser/ExpressionParser.Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ private static Parser<Expr> CreateParser()
Seq(L(')'), S))
.Do(Func<Expr, Expr> (parameters) => expr => new Expr.Call(expr, parameters));

// Unlike a call, an indexer takes at least one argument, as in C#.
var indexer =
expression_list
expression
.Separated(
Seq(L(','), S),
min: 1).As("expression")
.Between(
Seq(L('['), S),
Seq(L(']'), S))
Expand Down
10 changes: 8 additions & 2 deletions tests/Ramstack.ExpressionParser.Tests/Data/Errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Method name expected (expression: 3).
Cannot apply indexing with [] to an expression of type 'System.Int32'.

1 + 2 * 3[
(1:11) Expected ']'
(1:11) Expected expression

1 + 2 * 3]
(1:10) Expected '(', '[', '.', ':>', [%*/], [+-], '<<', '>>', '>>>', '<', '>', '<=', '>=', '==', '!=', '&', '^', '|', '&&', '||', '??', '?', or end of input
Expand Down Expand Up @@ -101,7 +101,13 @@ Cannot apply indexing with [] to an expression of type 'System.Int32'.
(1:2) Expected '(', '[', '.', ':>', [%*/], [+-], '<<', '>>', '>>>', '<', '>', '<=', '>=', '==', '!=', '&', '^', '|', '&&', '||', '??', '?', or end of input

"test"[]
Ambiguous match found:\n Char Chars [Int32] (in System.String)
(1:8) Expected expression

"test"[ ]
(1:9) Expected expression

"test".Split(',')[]
(1:19) Expected expression

"test"["a"]
Ambiguous match found:\n Char Chars [Int32] (in System.String)
Expand Down