Skip to content

[Parse] Fix skipping string interpolation in Lexer #10246

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 1 commit into from
Jun 15, 2017

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jun 14, 2017

Maintain inner most string literal mode to determine whether we allow
newline character or not.

  • Disallow newline after multiline string in string interpolation. (SR-5171)

    "abc\("""
          defg
          """ // ← This newline should be rejected.
          )hij"
  • Allow unbalanced " in multiline string in string interpolation.

    "abc\("""
          "defg ← This unbalanced quote should be accepted
          """)hij"

@rintaro
Copy link
Member Author

rintaro commented Jun 14, 2017

@swift-ci Please smoke test

@rintaro rintaro force-pushed the lexer-multiline-interpolation branch from a140fcb to 3fb3789 Compare June 15, 2017 01:46
@rintaro
Copy link
Member Author

rintaro commented Jun 15, 2017

@swift-ci Please smoke test

@rintaro rintaro requested a review from milseman June 15, 2017 16:07
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!

@@ -1244,6 +1244,9 @@ static const char *skipToEndOfInterpolatedExpression(const char *CurPtr,
DiagnosticEngine *Diags,
bool MultilineString) {
llvm::SmallVector<char, 4> OpenDelimiters;
llvm::SmallVector<bool, 3> AllowNewline;
Copy link
Member

Choose a reason for hiding this comment

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

Very minor nitpick: why 3? Might as well go with 4 or 8, as the small vector will be pointer-size aligned. This doesn't block this PR, though.

Copy link
Member Author

Choose a reason for hiding this comment

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

My thought was: if size of OpenDelimiters is 4, size of AllowNewline is at most 3.

str = "a\(  "b\(  "c\(  something  )")")"
            "  (  "  (   -> OpenDelimiters : {'"', '(', '"', '('}
         f  f     f      -> AllowNewline : {false, false, false}

That was unnecessary restriction though. Updated to 4.

Maintain inner most string literal mode to determine whether we allow
newline character or not.

* Disallow newline after multiline string in string interpolation. (SR-5171)
* Allow unbalanced `"` in multiline string in string interpolation.
@rintaro rintaro force-pushed the lexer-multiline-interpolation branch from 3fb3789 to c8bd1aa Compare June 15, 2017 17:23
@rintaro
Copy link
Member Author

rintaro commented Jun 15, 2017

Thanks!
@swift-ci Please smoke test and merge

@rintaro
Copy link
Member Author

rintaro commented Jun 15, 2017

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit b9db212 into swiftlang:master Jun 15, 2017
@rintaro rintaro deleted the lexer-multiline-interpolation branch June 15, 2017 18:12
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.

3 participants