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

Add ! suffix to parser #6586

Merged
merged 5 commits into from
Mar 15, 2024
Merged

Add ! suffix to parser #6586

merged 5 commits into from
Mar 15, 2024

Conversation

lukewilliamboswell
Copy link
Collaborator

@lukewilliamboswell lukewilliamboswell commented Mar 14, 2024

This PR;

  • Adds support for parsing and formatting the suffix ! for idents e.g. foo! (bar! baz) (blah stuff) as described in chaining syntax proposal

@lukewilliamboswell lukewilliamboswell changed the title Add bang suffix to parser WIP add bang suffix to parser Mar 14, 2024
@lukewilliamboswell lukewilliamboswell changed the title WIP add bang suffix to parser Add ! suffix to parser Mar 14, 2024
if state.bytes().starts_with(b"!") {
(
progress,
Loc::at(expr.region, Expr::Suffixed(arena.alloc(expr.value))),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm really unsure about this. My concern is the that Loc in expr here points to just the ident and doesn't include the ! in it. I'm not sure if that is an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

If so, we'll see this in error messages when we get to testing those - the red underline either will or won't include the ! depending on this. That might actually be what we want in some cases, but maybe not others!

loc_possibly_negative_or_negated_term(options).parse(arena, state, min_indent)?;
let (_, expr, state) = loc_possibly_negative_or_negated_term(options)
.parse(arena, state, min_indent)
.map(|(progress, expr, state)| {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought this wouldn't be needed as the map in parse_expr_end would wrap the expressions in Suffix, but the loc_possibly_negative_or_negated_term parser doesn't seem to catch everything.

@@ -619,6 +619,7 @@ pub fn desugar_expr<'a>(
})
}
LowLevelDbg(_, _, _) => unreachable!("Only exists after desugaring"),
Suffixed(_) => todo!(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To be completed in follow up PRs. One for each flavour of sugar.

# and modify it, and it will modify all the fixture tests.
#
# If this file is in the fixtures/ directory, on the other hand, then
# it is gitignored and will be overwritten the next time tests run.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, according to this comment, this file should be gitignored... 🤨

Seems like we might not be doing this correctly, although I didn't set up the fixture system and I'm not sure how it's supposed to work. 😅

@rtfeldman
Copy link
Contributor

Looks good overall! 😍

I'd like to get clarification from someone who knows how the fixtures are supposed to work before merging though, in case those are things we shouldn't be checking in (which seems to be the case, based on the comment at the top, but that comment also says they should be gitignored...so I'm not sure what's correct!)

Copy link
Contributor

@rtfeldman rtfeldman left a comment

Choose a reason for hiding this comment

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

Fantastic, thanks so much @lukewilliamboswell! 😍

@rtfeldman rtfeldman merged commit 7ab50cf into main Mar 15, 2024
17 checks passed
@rtfeldman rtfeldman deleted the bang-suffix branch March 15, 2024 10:49
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.

2 participants