Copilot commented on code in PR #2360:
URL: https://github.com/apache/age/pull/2360#discussion_r2996979904
##########
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:
The new `%expect 7` / `%expect-rr 3` conflict budget is sensitive to the
exact Bison conflict counts. Since CI installs `bison` from `apt` without
pinning a version (see `.github/workflows/installcheck.yaml`), a future Bison
upgrade (or differences across distros) could change the reported conflict
counts and reintroduce parser-generation warnings/failures. Consider pinning
the Bison version in CI and/or documenting the minimum supported Bison version
for GLR + `%expect-rr`, so builds stay reproducible across environments.
##########
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:
This adds `anonymous_path` as an `expr_atom`, which makes bare pattern
expressions legal anywhere `expr` is accepted (e.g., `RETURN (a)-[:R]->(b)` /
`SET n.flag = (a)-[:R]->(b)`), not just in `WHERE`. If the intent is strictly
“pattern expressions in WHERE”, consider restricting this production to a
boolean/WHERE-specific expression nonterminal, or update the PR
description/tests to reflect the broader surface area.
--
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]