Skip to content

[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

Merged
merged 15 commits into from
Sep 6, 2018

Conversation

johnno1962
Copy link
Contributor

@johnno1962 johnno1962 commented Jul 2, 2018

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.

@johnno1962 johnno1962 force-pushed the master branch 5 times, most recently from fd59c17 to 985e2e3 Compare July 8, 2018 16:41
@johnno1962 johnno1962 changed the title [Parse][WIP] Revised implementation for raw strings [Parse] Revised implementation for raw strings Aug 10, 2018
@johnno1962
Copy link
Contributor Author

@gregomni, any chance you could do a @swift-ci please test for me so I can see what this breaks?

@gottesmm
Copy link
Contributor

@swift-ci test

@gottesmm
Copy link
Contributor

(just doing a drive by @swift-ci)

@johnno1962
Copy link
Contributor Author

Cheers.

@johnno1962 johnno1962 force-pushed the master branch 9 times, most recently from 3736766 to 3c5ad62 Compare August 13, 2018 17:59
/// CHECK: "\\#1"

_ = #"c:\windows\system32"#
/// CHCECK: "c:\\windows\\system32"
Copy link
Contributor

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 ##
###################################################################
"""#

@johnno1962
Copy link
Contributor Author

Tests fixed up and I’ve added the one you suggest and tested.

// CHECK: "a string with\n\"\"\"\nin it"

_ = #"a raw string containing \r\n"#
// CHECK "a raw string containing \\r\\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing colon. // CHECK => // CHECK:

Copy link
Contributor Author

@johnno1962 johnno1962 Aug 17, 2018

Choose a reason for hiding this comment

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

Crikey. Amended.

@johnno1962 johnno1962 force-pushed the master branch 2 times, most recently from b3496fc to 627361c Compare August 17, 2018 15:15
@swift-ci
Copy link
Contributor

swift-ci commented Sep 4, 2018

Build failed
Swift Test OS X Platform
Git Sha - 999bb40

@johnno1962 johnno1962 force-pushed the master branch 3 times, most recently from 7ff67f8 to 722b38e Compare September 5, 2018 16:33
@johnno1962
Copy link
Contributor Author

Ready when you are @brentdax, can you run another test please?

@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

@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.

@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

@swift-ci please test source compatibility

@johnno1962
Copy link
Contributor Author

johnno1962 commented Sep 6, 2018

Thanks @brentdax. Don’t forget to squash 👍 Be nice to see this in 4.2.1 ;)

Copy link
Collaborator

@xwu xwu left a 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.

/// 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.
Copy link
Collaborator

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.

return 0;
}

/// delimiterMatches - Does custom delimiter (# characters surrounding quotes)
Copy link
Collaborator

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).

if (IndentToStrip == ~0u && CustomDelimiterLen == ~0u) {
IndentToStrip = CustomDelimiterLen = 0;

// restore trailing indent removal for multiline
Copy link
Collaborator

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.

@@ -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
Copy link
Collaborator

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
Copy link
Contributor Author

Thanks @xwu, I have the changes ready and will commit after the source compatibility test runs and before @brentdax merges.

@johnno1962
Copy link
Contributor Author

johnno1962 commented Sep 6, 2018

@brentdax, source compatibility failures look unrelated so I’ve pushed the final nits that xwu mentions.

@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

@johnno1962 Yeah, I saw the same failures on the string interpolation PR.

@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 192587c into swiftlang:master Sep 6, 2018
@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

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".

@johnno1962
Copy link
Contributor Author

johnno1962 commented Sep 6, 2018

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 :(

@johnno1962
Copy link
Contributor Author

johnno1962 commented Sep 6, 2018

Could you revert it please and I can file the PR again and re-merge? There are a lot of commits.

@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

@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.

@johnno1962
Copy link
Contributor Author

The single commit with everything in it is what I’m after. I suspect a revert is not going to fix the history.

@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

@johnno1962 Okay, revert is in. Want to resubmit the PR?

@johnno1962
Copy link
Contributor Author

Trying to at the moment. There is “nothing to compare”. I can start from scratch.

@beccadax
Copy link
Contributor

beccadax commented Sep 6, 2018

If you revert the revert commit, that should get you the right diff. From there, just fill in the commit message you want.

@johnno1962
Copy link
Contributor Author

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.
Copy link
Member

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?

Copy link
Contributor Author

@johnno1962 johnno1962 Sep 18, 2018

Choose a reason for hiding this comment

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

What do you want me to do here? There is already a Jira SR-8678 for the zero-width problem. Should I raise a new PR to replace the link to the PR with a link to the Jira (which I’ve updated to include the code)? The implementation is under this commit: f0f08e1

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, please 1) add a link to f0f08e1 in SR-8678, and 2) raise a PR to replace the link.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: #19364.

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.

7 participants