Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Unify handling of calls - #614

Merged
djc merged 3 commits into
askama-rs:mainfrom
Kijewski:pr-calls
Jan 27, 2022
Merged

Unify handling of calls#614
djc merged 3 commits into
askama-rs:mainfrom
Kijewski:pr-calls

Conversation

@Kijewski

Copy link
Copy Markdown
Member

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.

Extracted from #590.

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.
Comment thread askama_shared/src/generator.rs Outdated
s => return Err(format!("unknown loop method: {:?}", s).into()),
},
left => {
match *left {

Copy link
Copy Markdown
Collaborator

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()? :)

Copy link
Copy Markdown
Member Author

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(..)), ..).

@djc djc left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread 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>>> {

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Member Author

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

@djc djc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, nice improvement!

@djc
djc merged commit cb351fe into askama-rs:main Jan 27, 2022
@Kijewski
Kijewski deleted the pr-calls branch January 27, 2022 09:33
@djc djc mentioned this pull request Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants