-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Parse] Implementation for SE-200 (raw strings) #17668
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
Conversation
fd59c17
to
985e2e3
Compare
@swift-ci test |
(just doing a drive by @swift-ci) |
Cheers. |
3736766
to
3c5ad62
Compare
test/Parse/raw_string.swift
Outdated
/// CHECK: "\\#1" | ||
|
||
_ = #"c:\windows\system32"# | ||
/// CHCECK: "c:\\windows\\system32" |
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.
Typo: CHCECK
=> CHECK
Does it matter how many forward slash characters are used?
i.e. /// CHECK:
versus // CHECK:
Would the following also be a valid raw string test?
_ = #"""
###################################################################
## This source file is part of the Swift.org open source project ##
###################################################################
"""#
Tests fixed up and I’ve added the one you suggest and tested. |
test/Parse/raw_string.swift
Outdated
// CHECK: "a string with\n\"\"\"\nin it" | ||
|
||
_ = #"a raw string containing \r\n"# | ||
// CHECK "a raw string containing \\r\\n" |
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.
Missing colon. // CHECK
=> // CHECK:
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.
Crikey. Amended.
b3496fc
to
627361c
Compare
Build failed |
7ff67f8
to
722b38e
Compare
Ready when you are @brentdax, can you run another test please? |
@johnno1962 I'll run the source compatibility suite now just to make sure there's no weird parsing issues. Then, in a few hours, I'll smoke test and merge. |
@swift-ci please test source compatibility |
Thanks @brentdax. Don’t forget to squash 👍 Be nice to see this in 4.2.1 ;) |
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.
Some minor comments about comments; nothing major and can be addressed after the fact. Bravo on a great feature and implementation.
lib/Parse/Lexer.cpp
Outdated
/// the literal beyond what it would appear creating potential security bugs. | ||
static bool diagnoseZeroWidthMatchAndAdvance(char Target, const char *&CurPtr, | ||
DiagnosticEngine *Diags) { | ||
// Detect, diagnose and skip over zero-width characters here if required. |
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.
Marking this as “TODO:” might be a good idea.
lib/Parse/Lexer.cpp
Outdated
return 0; | ||
} | ||
|
||
/// delimiterMatches - Does custom delimiter (# characters surrounding quotes) |
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.
If you surround “#” with single quotes within this comment, it might alleviate the misread that the custom delimiter is the “number of characters surrounding quotes” (as opposed to the number of ‘#’ characters surrounding—specifically, on either side of—the quotation marks).
lib/Parse/Lexer.cpp
Outdated
if (IndentToStrip == ~0u && CustomDelimiterLen == ~0u) { | ||
IndentToStrip = CustomDelimiterLen = 0; | ||
|
||
// restore trailing indent removal for multiline |
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.
Nit: capitalize and punctuate, here and below.
lib/Parse/Lexer.cpp
Outdated
@@ -1204,6 +1206,68 @@ static bool maybeConsumeNewlineEscape(const char *&CurPtr, ssize_t Offset) { | |||
} | |||
} | |||
|
|||
/// diagnoseZeroWidthMatchAndAdvance - Error zerowidth characters in delimiters. | |||
/// A non visible character in the middle of a delimter can be used to extend |
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.
Nits: “zero-width” instead of “zerowidth,” “invisible” instead of “non visible.”
Typo in the word “delimiter.”
@johnno1962 Yeah, I saw the same failures on the string interpolation PR. |
@swift-ci please smoke test and merge |
Ugh, forgot to squash it. I don't think we can clean up history on this repo once it's committed, though. I guess I've learned a lesson about "smoke test and merge". |
Thanks Brent. My fault for not squashing it myself but I wanted to keep the history. It’s going to make cherrypicking a bit of a pain though. Does anybody have permission to do a rebase -i on apple/swift to clean it up? Scratch that — the commits are spread over the last few months :( |
Could you revert it please and I can file the PR again and re-merge? There are a lot of commits. |
@johnno1962 Would a revert without actually changing the history meet your goal? I guess if you're just trying to make sure there's one commit to cherry-pick, it would. |
The single commit with everything in it is what I’m after. I suspect a revert is not going to fix the history. |
@johnno1962 Okay, revert is in. Want to resubmit the PR? |
Trying to at the moment. There is “nothing to compare”. I can start from scratch. |
If you revert the revert commit, that should get you the right diff. From there, just fill in the commit message you want. |
Top tip, thanks. I’ve created a new single commit PR. #19170 |
static bool diagnoseZeroWidthMatchAndAdvance(char Target, const char *&CurPtr, | ||
DiagnosticEngine *Diags) { | ||
// TODO: Detect, diagnose and skip over zero-width characters if required. | ||
// See https://github.com/apple/swift/pull/17668 for possible implementation. |
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.
@johnno1962 This URL (this PR) doesn't have possible implementation anymore.
Could you file a JIRA issue in https://bugs.swift.org/ . And update the comment?
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.
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.
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.
Done: #19364.
As per discussion in second pitch of raw strings on swift-evolution https://forums.swift.org/t/pure-bikeshedding-raw-strings-why-yes-again/13866. Work in progress, submitting now to get PR link.
Resolves #48912 and also lays groundwork for #51192.