-
Notifications
You must be signed in to change notification settings - Fork 299
Unable to match "x AND x AND x ..." #1066
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
Comments
Aha, it is an associative and precedence problem. See https://lalrpop.github.io/lalrpop/tutorial/004_full_expressions.html. The error msg already told you that
it could be either left-associative or right-associative, and that's the ambiguity. So IMO, if the
|
@chanbengz Thanks. The recursive approach works, but it produces a tree like this: (((x AND x) AND x) AND x). That's what I'm trying to avoid because it requires a post-processing step to flatten it into (x AND x AND x AND x). |
Post-processing is inevitable if you'd evaluate expressions, not to mention that recursive form has advantage that the precedence is clear if enables braces like
|
If you're trying to match a sequence of conjunctive expression and flatten it, my approach would be to define a variant <starts:Expr> "And" <end:Expr> => {
match starts {
Expr::AndSeq(ref mut v) => v.push(Expr::Something(end));
_ => panic!("not an And expression")
}
starts
} |
I'm trying to match a list of Exprs connected by "AND". Nothing seems to work.
Here's one attempt:
<starts:(<Expr> "And")+> <end:Expr> => {...},
which yields:
I can't make heads or tails of this.
In another attempt I had a lone
Expr
first, followed by("And" <Expr>)+
and got a similar local ambiguity error.This problem is similar to the Comma problem describe here: https://lalrpop.github.io/lalrpop/tutorial/006_macros.html. I attempted to use the Comma macro straight out of the docs and got a voluminous error message similar to the one above.
I don't get it. Where's the ambiguity?
The text was updated successfully, but these errors were encountered: