-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Unify handling of calls #614
Conversation
Instead of having `Expr::VarCall`, `Expr::PathCall` and `Expr::MethodCall`, this PR unifies the handling of calls by removing the former three variants, and introducing `Expr::Call`. This makes parsing postfix operators easier.
askama_shared/src/generator.rs
Outdated
@@ -1329,16 +1319,27 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { | |||
_ => return Err("loop.cycle(…) expects exactly one argument".into()), | |||
}, | |||
s => return Err(format!("unknown loop method: {:?}", s).into()), | |||
}, | |||
left => { | |||
match *left { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like something that could easily be forgotten, to be updated, when changing the parser. Could it maybe be "simplified" or handled in the parser, by having some enum CallKind
, which is a third value of Expr::Call()
? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comment in #590: #590 (comment). I think the list of special cases is exhaustive. I think not even the Expr::Unary(..) | Expr::BinOp(..) | Expr::Range(..)
case is actually need, because the parser won't ever generate an Expr::Call(Expr::Unary(..), ..)
, only Call(Group(Unary(..)), ..)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good. One open question about the parser setup.
askama_shared/src/parser.rs
Outdated
} | ||
|
||
Ok((i, res)) | ||
fn expr_attr<'a>(i: &'a str) -> IResult<&'a str, Box<dyn 'a + FnOnce(Expr<'a>) -> Expr<'a>>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this Box<dyn 'a + FnOnce(Expr<'a>) -> Expr<'a>>
contraption?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't. I guess I wanted to make it hyper-extensible for no proper reason. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, nice improvement!
Instead of having
Expr::VarCall
,Expr::PathCall
andExpr::MethodCall
, this PR unifies the handling of calls by removingthe former three variants, and introducing
Expr::Call
.This makes parsing postfix operators easier.
Extracted from #590.