-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Lexer] Allow multiline delimiter to be escaped in raw Strings #23115
Conversation
…strings. The multiline delimiter for Strings (aka. """ or triple quote) can now be escaped when the correct number of terminating '#' marks are found within the same line. Before, #"""# was invalid because the multiline delimiter only allowed a newline character following the triple quote. Now, #"""# is a valid String equivalent to "\"". [See SR-10011](https://bugs.swift.org/browse/SR-10011)
cc @rintaro |
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.
Hi Michael, welcome to the project!
Thank you for the PR. This is a good start!
For testing, the content of the literals are tested in test/Parse/raw_string.swift
. Please add test cases there. As for error cases like #"""meow#\n
, please add them to test/Parse/raw_string_errors.swift
.
Tests have been moved; logic has been rewritten. Thank you for the warm welcome:) |
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.
This is awesome! Minor nits :)
Co-Authored-By: maustinstar <maustinstar@gmail.com>
Conflicts: lib/Parse/Lexer.cpp
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.
Implementation looks good! Could you add several test cases?
@swift-ci Please smoke test |
@swift-ci Please smoke test |
This is because |
Changed the test case to something that won't eat the whole file but still ensures that the raw string would act like a single-liner. Sorry for being out of touch for so long. |
@swift-ci Please smoke test |
Does Should I change the logic to look for any delimiter (not necessarily of matching length) and treat the raw string as a one-liner? And inherently the parse tests would behave like the one-line counterparts? |
@maustinstar Are you still interested in working on this issue? |
@xwu If someone else wants to take it, that's okay. But if I attempt this again, I'll start from scratch and open a different PR. |
The Lexer currently eats triple-quotes as a multiline delimiter for Strings. This Pull request allows the delimiter to be escaped in raw Strings when the correct number of terminating '#' marks are found at the end of the line.
E.g.
#"""#
is now equivalent to"\""
#"""text"#
equates to"\"\"text"
#"""
is still the beginning of a multiline raw string.Resolves SR-10011.