'How can I modify ANTLR4 grammar such that left association of operator can be supported?
I want to support the following input as it is with a provided grammar.
This does not work
with [{id: 1},{id: 2}] as a
return a[0].id, a[1].id
It works if we change it to be:
with [{id: 1},{id: 2}] as a
return (a[0]).id, (a[1]).id
The relevant part of the grammar is here:
oC_PropertyOrLabelsExpression
: oC_Atom ( SP? oC_PropertyLookup )* ( SP? oC_NodeLabels )? ;
This is the full grammar: https://s3.amazonaws.com/artifacts.opencypher.org/M18/Cypher.g4
Is there anything we can do by modifying the grammar?
Solution 1:[1]
Change:
oC_StringListNullOperatorExpression
: oC_PropertyOrLabelsExpression ( oC_StringOperatorExpression
| oC_ListOperatorExpression
| oC_NullOperatorExpression
)*
;
into:
oC_StringListNullOperatorExpression
: oC_PropertyOrLabelsExpression ( oC_StringOperatorExpression
| oC_ListOperatorExpression
| oC_NullOperatorExpression
| oC_PropertyLookup
)*
;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bart Kiers |
