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

Insert parentheses based on precedence #78

Open
marijnvanwezel opened this issue Nov 26, 2022 · 0 comments
Open

Insert parentheses based on precedence #78

marijnvanwezel opened this issue Nov 26, 2022 · 0 comments
Assignees
Labels
good first issue Opportunity for newcomers to contribute to php-cypher-dsl subject/query-readability Issues related to the readability of generated queries type/enhancement New feature or request

Comments

@marijnvanwezel
Copy link
Collaborator

marijnvanwezel commented Nov 26, 2022

Currently, parentheses are always inserted when creating an expression (unless $insertParentheses is false). This leads to less readable expressions: compare ((a AND b) OR (c AND d)) to a AND b OR c AND d.

I propose to only insert parentheses when this is required by precedence rules. There is no explicit document on the precedence of operators in Cypher AFAIK, but it can be derived from the grammar:

  1. IN, STARTS WITH, ENDS WITH, CONTAINS, =~, IS NULL, IS NOT NULL
  2. +, - (unary)
  3. ^
  4. *, /, %
  5. +, - (binary)
  6. =, <>, <, >, <=, >=
  7. NOT
  8. AND
  9. XOR
  10. OR
@marijnvanwezel marijnvanwezel added type/enhancement New feature or request good first issue Opportunity for newcomers to contribute to php-cypher-dsl labels Nov 26, 2022
@marijnvanwezel marijnvanwezel added this to the php-cypher-dsl 6.0 milestone Nov 26, 2022
@marijnvanwezel marijnvanwezel self-assigned this Nov 26, 2022
@marijnvanwezel marijnvanwezel changed the title Only insert parentheses based on precedence Insert parentheses based on precedence Nov 26, 2022
@marijnvanwezel marijnvanwezel added the subject/query-readability Issues related to the readability of generated queries label Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Opportunity for newcomers to contribute to php-cypher-dsl subject/query-readability Issues related to the readability of generated queries type/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant