Skip to content

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

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
merged 3 commits into from
May 5, 2022

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Apr 28, 2022

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

@hamishknight hamishknight requested a review from rintaro April 28, 2022 21:07
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
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

@swift-ci please test

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