-
Notifications
You must be signed in to change notification settings - Fork 440
[5.9] Complete regex literal lexing #1486
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
hamishknight
merged 12 commits into
swiftlang:release/5.9
from
hamishknight:lets-go-back-to-the-island-5.9
Apr 5, 2023
Merged
[5.9] Complete regex literal lexing #1486
hamishknight
merged 12 commits into
swiftlang:release/5.9
from
hamishknight:lets-go-back-to-the-island-5.9
Apr 5, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Run swift-format over them - Update expectations now that we diagnose unterminated regex literals - Remove semantic errors - Fix test splitting in a few cases - Add TODOs where we should error
We currently track the previous raw token kind, but that is not sufficient to identify keyword kinds. Additionally store the keyword kind.
The SwiftSyntax parser doesn't have a way of disabling bare slash regex literals, so this is unnecessary.
Many of these can fall through to the default case to lex the operator. Also factor out `lexPostfixOptionalChain` in preparation for a bit of custom state transition logic.
Generalize in preparation for its use by regex literals.
The previous regex literal lexing logic didn't implement all the heuristics needed to parse all the regex literals that the old C++ parser handles. Update it with the heuristics it needs, and better handle diagnostics for invalid cases. This unfortunately requires a bit of lexical hackery, including a heuristic to classify previous token kinds to determine if we're in regex literal position, but it's needed to handle pathological cases such as `x /^ y/` where there's an ambiguity with a binary operator.
Previously we always produced `.prefixOperator`, which is wrong for cases like prefix `&`, `=`, and `?` which should produce different token kinds. Factor out the classification code, and use it to produce the correct token kind.
We can confidently lex unless we have a previous token that indicates that we're in an argument list. In such a case, an unapplied operator can be parsed, and we want to ensure we maintain that behavior.
ahoppen
approved these changes
Apr 4, 2023
@swift-ci please test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
5.9 cherry-pick of #1463
Medium risk, but fixes a whole bunch of regex literal parsing issues.
The previous regex literal lexing logic didn't implement all the heuristics needed to parse all the regex literals that the old C++ parser handles. Update it with the heuristics it needs, and better handle diagnostics for invalid cases.
This unfortunately requires a bit of lexical hackery, including a heuristic to classify previous token kinds to determine if we're in regex literal position, but it's needed to handle pathological cases such as
x /^ y/
where there's an ambiguity with a binary operator.Resolves #1059
rdar://102213809