-
Notifications
You must be signed in to change notification settings - Fork 15
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
Precedence Climbing #12
Comments
Initial draft idea: #[derive(Debug, PrecClimb)]
#[prec_climb(rule(Rule::expression))]
pub enum Expression<'i> {
#[prec_climb(infix(Rule::op_choice), assoc(Left), prec(2))]
Choice(Box<Expression<'i>>, op::Choice, Box<Expression<'i>>),
#[prec_climb(infix(Rule::op_strict_sequence), assoc(Left), prec(1))]
StrictSequence(Box<Expression<'i>>, op::StrictSeq, Box<Expression<'i>>),
#[prec_climb(infix(Rule::op_trivia_sequence), assoc(Left), prec(1))]
TriviaSequence(Box<Expression<'i>>, op::TriviaSeq, Box<Expression<'i>>),
#[prec_climb(primary)]
Term(Term<'i>),
} Potential knobs:
|
This looks really good. Should we consider unary ops here as well? The reason why they're not implemented in |
How would you bundle prefix and postfix operator handling into this? I understand how precedence climbing works for binary ops, but I'm unsure how it's extended to handle unary ops (and, forbid, tertiary ops). And at this point, I'm thinking we'll want to add a This "runtime" support is starting to look like the direction to grow from here. An interesting datapoint, however: |
It's possible to combine precedence climbing with pest-ast derives, but it currently requires doing so by implementing
FromPest
directly.This is a fairly rote transformation; we could offer a way to automate this slightly.
The text was updated successfully, but these errors were encountered: