gregfelice commented on code in PR #2360:
URL: https://github.com/apache/age/pull/2360#discussion_r3089620914
##########
src/backend/parser/cypher_gram.y:
##########
@@ -49,6 +49,30 @@
%locations
%name-prefix="cypher_yy"
%pure-parser
+/*
+ * GLR mode handles the ambiguity between parenthesized expressions and
+ * graph patterns. For example, WHERE (a)-[:KNOWS]->(b) starts with (a)
+ * which is valid as both an expression and a path_node. The parser forks
+ * at the conflict point and discards the failing path. %dprec annotations
+ * on expr_var/var_name_opt and '(' expr ')'/anonymous_path resolve cases
+ * where both paths succeed (bare (a) prefers the expression interpretation).
+ */
+%glr-parser
+/*
+ * Conflict budget for the GLR parser. Update these counts if grammar
+ * rules change.
+ *
+ * %expect 7 (shift/reduce) -- All arise from the ambiguity between
+ * path extension ('-' '[' ... ']' '-' '>') and arithmetic operators
+ * on '-' and '<'. GLR forks at these points and discards the
+ * failing alternative.
+ *
+ * %expect-rr 3 (reduce/reduce) -- From the overlap between expr_var
+ * and var_name_opt on ')' / '}' / '='. Resolved by %dprec
+ * annotations that prefer the expression interpretation.
+ */
+%expect 7
+%expect-rr 3
Review Comment:
Addressed — `%expect` / `%expect-rr` have been removed. The grammar now uses
`-Wno-conflicts-sr -Wno-conflicts-rr` via `BISONFLAGS` in the Makefile (see
Makefile:166 and the comment block at cypher_gram.y:74). A block comment
documents what the 7 s/r and 3 r/r conflicts are and why GLR + `%dprec` handles
them correctly. This keeps builds clean across Bison versions without pinning.
##########
src/backend/parser/cypher_gram.y:
##########
@@ -1953,6 +1966,17 @@ expr_atom:
}
$$ = n;
}
+ | anonymous_path %dprec 1
+ {
+ /*
+ * Bare pattern in expression context is semantically
+ * equivalent to EXISTS(pattern). Example:
+ * WHERE (a)-[:KNOWS]->(b)
+ * becomes
+ * WHERE EXISTS((a)-[:KNOWS]->(b))
+ */
+ $$ = make_exists_pattern_sublink($1, @1);
+ }
Review Comment:
Good catch — this is intentional, and the PR description has been updated to
reflect it. Adding `anonymous_path` to `expr_atom` legalizes pattern
expressions in every expression context (RETURN, SET, CASE, WITH, boolean
combinators), which matches openCypher semantics and what Neo4j users expect.
Rather than restrict to a WHERE-only nonterminal, the PR now explicitly
embraces the broader surface area and covers it with regression tests — see
regress/sql/pattern_expression.sql lines 156-183 (RETURN projection, mixed
projections, CASE WHEN) plus the SET/WITH/AND/OR examples in the PR
description. See also the "Note on scope" block at the top of the description.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]