Skip to content

Multi-line and extended delimiter literal lexing #242

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 7 commits into from
Apr 1, 2022

Conversation

hamishknight
Copy link
Contributor

Update the delimiter lexing logic to handle /.../, an extended variant that allows an arbitrary number of balanced pounds, e.g ##/.../##, and a multi-line mode when the extended variant starts with a newline. The multi-line mode uses extended regex syntax by default, allowing for non-semantic whitespace and end-of-line comments.

Additionally, disable the #|...|#, re'...', and rx'...' spellings for now.

Make sure we don't try and print things like
empty comma lists `,,,,` or redundant parens for
concatenations that had their trivia filtered out.
Turns out this is a Unicode-defined thing.
Previously we would just lex to the end of the
input, as it was assumed only single-line regex
would be supported. Update the implementation to
handle multi-line, and take account of PCRE global
options.
Start lexing `/.../`, and allow any number of
pound signs to surround it.
When an extended delimiter `#/` is followed by a
newline, enter a multi-line mode where the literal
may span multiple lines, and extended syntax is
enabled by default.
Leave only `/.../` (and its extended syntax)
enabled for now.
@hamishknight hamishknight requested a review from milseman April 1, 2022 13:38
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight
Copy link
Contributor Author

Given this patch allows the lexing of /.../, we can actually update swiftlang/swift#42119 to lex using that logic (though the heuristics remain on the compiler side for now).

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hamishknight hamishknight merged commit c45450f into swiftlang:main Apr 1, 2022
@hamishknight hamishknight deleted the unlimited-delimiters branch April 1, 2022 14:11
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