-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Do not merge] [Syntax] parse invalid chars as trivia #14979
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// To know about setup, see `tokens_invalids.swift`. | ||
|
||
// RUN: cat %s > %t | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a1")'/'$(echo -ne "\xc2")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a2")'/'$(echo -ne "\xcc\x82")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a3")'/'$(echo -ne "\xe2\x80\x9d")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a4")'/'$(echo -ne "\xe2\x80\x9c")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a5")'/'$(echo -ne "\xe1\x9a\x80")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
|
||
// RUN: %round-trip-syntax-test --swift-syntax-test %swift-syntax-test --file %t | ||
|
||
x | ||
Z1 x | ||
Z2 | ||
Z3 | ||
Z4 | ||
Z4 abcdef Z3 | ||
Z5 x |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// RUN: cat %s > %t | ||
|
||
// 5a is Z. "ZN" style marker is used for marker. N is number. | ||
|
||
// C2 is utf8 2 byte character start byte. | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a1")'/'$(echo -ne "\xc2")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
|
||
// CC 82 is U+0302, invalid for identifier start, valid for identifier body. | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a2")'/'$(echo -ne "\xcc\x82")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
|
||
// E2 80 9D is U+201D, right quote. | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a3")'/'$(echo -ne "\xe2\x80\x9d")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
|
||
// E2 80 9C is U+201C, left quote. | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a4")'/'$(echo -ne "\xe2\x80\x9c")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
|
||
// E1 9A 80 is U+1680, invalid for swift source. | ||
// RUN: cat %t | sed 's/'$(echo -ne "\x5a5")'/'$(echo -ne "\xe1\x9a\x80")'/g' > %t.sed | ||
// RUN: cp -f %t.sed %t | ||
|
||
// RUN: %swift-syntax-test -input-source-filename %t -dump-full-tokens 2>&1 | %FileCheck %t | ||
|
||
x | ||
Z1 x | ||
Z2 | ||
Z3 | ||
Z4 | ||
Z4 abcdef Z3 | ||
Z5 x | ||
|
||
// test diagnostics. | ||
|
||
// CHECK: 28:1: error: invalid UTF-8 found in source file | ||
// CHECK: 29:1: error: an identifier cannot begin with this character | ||
// CHECK: 30:1: error: unicode curly quote found | ||
// CHECK: 31:1: error: unicode curly quote found | ||
// CHECK: 32:12: error: unicode curly quote found | ||
// CHECK: 32:1: error: unicode curly quote found | ||
// CHECK: 33:1: error: invalid character in source file | ||
|
||
// test tokens and trivias. | ||
|
||
// CHECK-LABEL: 28:3 | ||
// CHECK-NEXT: (Token identifier | ||
// CHECK-NEXT: (trivia newline 1) | ||
// CHECK-NEXT: (trivia garbage_text \302) | ||
// CHECK-NEXT: (trivia space 1) | ||
// CHECK-NEXT: (text="x")) | ||
|
||
// CHECK-LABEL: 29:1 | ||
// CHECK-NEXT: (Token unknown | ||
// CHECK-NEXT: (trivia newline 1) | ||
// CHECK-NEXT: (text="\xCC\x82")) | ||
|
||
// CHECK-LABEL: 30:1 | ||
// CHECK-NEXT: (Token unknown | ||
// CHECK-NEXT: (trivia newline 1) | ||
// CHECK-NEXT: (text="\xE2\x80\x9D")) | ||
|
||
// CHECK-LABEL: 31:1 | ||
// CHECK-NEXT: (Token unknown | ||
// CHECK-NEXT: (trivia newline 1) | ||
// CHECK-NEXT: (text="\xE2\x80\x9C")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these characters invalid? If so, should they be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @harlanhaskins E2 80 9C is U+201C, unicode style left quote. E2 80 9D is U+201D, unicode style right quote. They becomes to single character unknown token, or, The reason of this test in here, just that the logic about handling them are there in invalid character detection control flow. And these characters are safe in text file, |
||
|
||
// CHECK-LABEL: 32:1 | ||
// CHECK-NEXT: (Token unknown | ||
// CHECK-NEXT: (trivia newline 1) | ||
// CHECK-NEXT: (text="\xE2\x80\x9C abcdef \xE2\x80\x9D")) | ||
|
||
// CHECK-LABEL: 33:5 | ||
// CHECK-NEXT: (Token identifier | ||
// CHECK-NEXT: (trivia newline 1) | ||
// CHECK-NEXT: (trivia garbage_text \341\232\200) | ||
// CHECK-NEXT: (trivia space 1) | ||
// CHECK-NEXT: (text="x")) |
Uh oh!
There was an error while loading. Please reload this page.
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.
// RUN: cat %t | sed 's/Z1/'$(echo -ne "\xc2")'/g' > %t.sed ^^
doesn't work? I think it's easier to read.
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.
No. If I do so,
Z1
in sed line also replaced by this sed itself.It makes problematic input source.
If Lexer is correct, it also skipped as line comment of course.
But for example it introduce other complex discussion about diagnostics about invalid character in comment.