Skip to content

[5.7] [Parse] Split prefix operators from regex in the lexer #58682

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

Merged

Conversation

hamishknight
Copy link
Contributor

5.7 cherry-pick of #58505


Teach the lexer not to consider / an operator character when attempting to re-lex a regex literal. This allows us to split off a prefix operator for cases such as foo(!/^/) and foo(!/, /) rather than treating them as unapplied infix operators. This matches the behavior outside of an argument list.

This also improves diagnostics for cases such as foo(&/.../), as we now correctly produce a tok::amp_prefix.

rdar://92469917

We already check this in `Parser::tryLexRegexLiteral`,
and the failure case doesn't make sense here as
we call `discardToken` afterwards.
Teach the lexer not to consider `/` an operator
character when attempting to re-lex a regex
literal. This allows us to split off a prefix
operator.

Previously this was done after-the-fact in the
parser, but that didn't cover the unapplied infix
operator case, and didn't form a `tok::amp_prefix`
for `foo(&/.../)`, which led to a suboptimal
diagnostic.

This also now means we'll split an operator for
cases such as `foo(!/^/)` rather than treating it
as an unapplied infix operator.

rdar://92469917
@hamishknight hamishknight requested a review from a team as a code owner May 5, 2022 10:55
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit 0a0972d into swiftlang:release/5.7 May 5, 2022
@hamishknight hamishknight deleted the regulation-grammar-5.7 branch May 5, 2022 15:19
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.7 labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants