cpchung
cpchung

Reputation: 844

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?

Upvotes: 0

Views: 64

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170308

Change:

oC_StringListNullOperatorExpression
 :  oC_PropertyOrLabelsExpression ( oC_StringOperatorExpression
                                  | oC_ListOperatorExpression
                                  | oC_NullOperatorExpression
                                  )*
 ;

into:

oC_StringListNullOperatorExpression
 :  oC_PropertyOrLabelsExpression ( oC_StringOperatorExpression
                                  | oC_ListOperatorExpression
                                  | oC_NullOperatorExpression
                                  | oC_PropertyLookup
                                  )*
 ;

Upvotes: 1

Related Questions