Skip to content

Conversation

@hamishknight
Copy link
Contributor

5.7 cherry-pick of #58835

When lexing a regex literal, treat a prefix operator containing / the same as the unapplied infix operator case, where we tentatively lex. This means that we bail if there is no closing / or the starting character is invalid. This leaves binary operator containing / in expression position as the last place where we know that we definitely have a regex literal.

Additionally, expand the starting ) character heuristic to cover the entire range of the regex literal, ensuring to take escapes and custom character classes into account. This means we will not lex a regex literal if there is an unbalanced ) somewhere in the body.

Treat a prefix operator containing `/` the same as
the unapplied infix operator case, where we
tentatively lex. This means that we bail if there
is no closing `/` or the starting character is
invalid. This leaves binary operator containing
`/` in expression position as the last place where
we know that we definitely have a regex literal.
Previously we would only check for a starting
character of `)` when performing a tentative
lex of a regex literal. Expand this to cover the
entire range of the regex literal, ensuring to
take escapes and custom character classes into
account.
@hamishknight hamishknight requested a review from a team as a code owner May 12, 2022 16:29
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit 384ea9e into swiftlang:release/5.7 May 12, 2022
@hamishknight hamishknight deleted the allow-prefix-slash-5.7 branch May 12, 2022 20:53
@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