-
Notifications
You must be signed in to change notification settings - Fork 49
Description
In languages with array/list indexing, an index into an array/list counts as an expression, so you should be able to index that thing and use it in other expression operations. Examples are things like:
a[0]
a[0][0]
[1, 2, 3][0] + [[1, 2], 1][0][0]
but it also needs to be the case that you can identify that, like a bare identifier, something like a[x]
can be assigned to, which is the case for bare identifiers (like a
), but not for expressions in general (like a + 2
).
Should I try to handle this inside the ExpressionBuilder
(by, say, creating a postfix
group with a seq3(char('['), loopback, char(']'))
parser or should I move this outside so that I have something like a listRef
parser.
The issue with the first is that something of the form a[0]
is just an expression, so determining if something is assignable would have to be a semantic check and can't be guaranteed by the parser.
The issue with the second is that any strings of the form a[0]
would not automatically be part of the ExpressionBuilder
and so handling the operations on expressions (like prefix, wrapping, and left and right associative operations) wouldn't be included automatically.
I checked the Dart example grammar, but it doesn't use ExpressionBuilder
. The regexp parser uses postfix for the range, but you can only have numbers in the brackets, so there's no recursion. So I guess the other possibility is that I should just forgo using ExpressionBuilder
and define the family of grammars that encodes all the operations separately and handle precedence and grouping and stuff manually.
Any insight appreciated.