-
Notifications
You must be signed in to change notification settings - Fork 440
Complete regex literal lexing #1463
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
Complete regex literal lexing #1463
Conversation
5cc3792
to
03cbd45
Compare
03cbd45
to
3b4c494
Compare
@ahoppen Addressed review feedback, let me know what you think. Also noticed that we needed to properly classify the prefix operators we're splitting, so pushed a commit to fix that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept two discussions as unresolved (bump pointer allocator slab size + performance impact of passing previousKeyword
around). Once those are resolved, this looks good to me.
- 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.
3b4c494
to
b2a2e75
Compare
@swift-ci please test |
@swift-ci please test Windows |
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