Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is pipeline used to define Expression rule? #380

Open
hagen666 opened this issue Aug 31, 2019 · 2 comments
Open

Why is pipeline used to define Expression rule? #380

hagen666 opened this issue Aug 31, 2019 · 2 comments

Comments

@hagen666
Copy link

Hi,
I read the Cypher.g4 file and have many questions.
One is about the Expression.

It seems that the oC_Expression rule use a pipeline:

oC_Expression : oC_OrExpression ;
oC_OrExpression : oC_XorExpression ( SP OR SP oC_XorExpression )* ;
oC_XorExpression : oC_AndExpression ( SP XOR SP oC_AndExpression )* ;
oC_AndExpression : oC_NotExpression ( SP AND SP oC_NotExpression )* ;
oC_NotExpression : ( NOT SP? )* oC_ComparisonExpression ;
oC_ComparisonExpression : oC_AddOrSubtractExpression ( SP? oC_PartialComparisonExpression )* ;
oC_AddOrSubtractExpression : oC_MultiplyDivideModuloExpression ( ( SP? '+' SP? oC_MultiplyDivideModuloExpression ) | ( SP? '-' SP? oC_MultiplyDivideModuloExpression ) )* ;
oC_MultiplyDivideModuloExpression : oC_PowerOfExpression ( ( SP? '' SP? oC_PowerOfExpression ) | ( SP? '/' SP? oC_PowerOfExpression ) | ( SP? '%' SP? oC_PowerOfExpression ) ) ;
oC_PowerOfExpression : oC_UnaryAddOrSubtractExpression ( SP? '^' SP? oC_UnaryAddOrSubtractExpression )* ;
oC_UnaryAddOrSubtractExpression : ( ( '+' | '-' ) SP? )* oC_StringListNullOperatorExpression ;

What's the advantage of the pipeline rules?
Why not use the rules like this?
For example, BooleanExpression:

oC_BoolExpression:
oC_BooleanLiteral
| oC_StringListNullOperatorExpression
| oC_ComparisonExpression
| (ops=NOT SP?) oC_BoolExpression
| '(' SP? oC_BoolExpression SP? ')'
| oC_BoolExpression SP ops=AND SP oC_BoolExpression
| oC_BoolExpression SP ops=OR SP oC_BoolExpression
| oC_BoolExpression SP ops=XOR SP oC_BoolExpression
;
I think the AST generated by this way may be more graceful.
Looking forward to your comments or opinion.

@Mats-SX
Copy link
Member

Mats-SX commented Sep 10, 2019

@hagen666 I can not directly see a reason where either of these is more expressive, which indicates that it may only be a matter of style. You could try to rewrite the source definitions and issue a PR, to see if the tests still pass. The file you'd need to edit is this one: https://github.com/opencypher/openCypher/blob/master/grammar/basic-grammar.xml#L188-L314

@hagen666
Copy link
Author

OK. I'll have a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants