Skip to content

Conversation

hamishknight
Copy link
Contributor

5.7-04182022 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 11, 2022 20:54
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit cd7f254 into swiftlang:release/5.7-04182022 May 12, 2022
@hamishknight hamishknight deleted the regulation-grammar-5.7-04182022 branch May 12, 2022 16:56
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