php-cypher-dsl icon indicating copy to clipboard operation
php-cypher-dsl copied to clipboard

Insert parentheses based on precedence

Open marijnvanwezel opened this issue 3 years ago • 0 comments

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 avatar Nov 26 '22 11:11 marijnvanwezel