Skip to content
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

Merged
merged 3 commits into from
Jan 27, 2022
Merged

Unify handling of calls #614

merged 3 commits into from
Jan 27, 2022

Conversation

Kijewski
Copy link
Collaborator

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.
@@ -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 {
Copy link
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
Collaborator 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(..)), ..).

Copy link
Owner

@djc djc left a 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.

}

Ok((i, res))
fn expr_attr<'a>(i: &'a str) -> IResult<&'a str, Box<dyn 'a + FnOnce(Expr<'a>) -> Expr<'a>>> {
Copy link
Owner

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
Collaborator 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

Copy link
Owner

@djc djc left a comment

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 djc: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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants