aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/libsyntax2/src/lexer/strings.rs45
-rw-r--r--crates/libsyntax2/tests/data/lexer/0009_strings.rs3
-rw-r--r--crates/libsyntax2/tests/data/lexer/0009_strings.txt4
-rw-r--r--crates/libsyntax2/tests/data/lexer/0014_unclosed_char.rs1
-rw-r--r--crates/libsyntax2/tests/data/lexer/0014_unclosed_char.txt1
-rw-r--r--crates/libsyntax2/tests/data/lexer/0015_unclosed_string.rs1
-rw-r--r--crates/libsyntax2/tests/data/lexer/0015_unclosed_string.txt1
7 files changed, 39 insertions, 17 deletions
diff --git a/crates/libsyntax2/src/lexer/strings.rs b/crates/libsyntax2/src/lexer/strings.rs
index 795ea97b7..a6da97d47 100644
--- a/crates/libsyntax2/src/lexer/strings.rs
+++ b/crates/libsyntax2/src/lexer/strings.rs
@@ -15,22 +15,23 @@ pub(crate) fn is_string_literal_start(c: char, c1: Option<char>, c2: Option<char
15} 15}
16 16
17pub(crate) fn scan_char(ptr: &mut Ptr) { 17pub(crate) fn scan_char(ptr: &mut Ptr) {
18 loop { 18 while let Some(c) = ptr.next() {
19 if ptr.next_is('\\') { 19 match c {
20 ptr.bump(); 20 '\\' => {
21 if ptr.next_is('\\') || ptr.next_is('\'') { 21 ptr.bump();
22 if ptr.next_is('\\') || ptr.next_is('\'') {
23 ptr.bump();
24 }
25 }
26 '\'' => {
27 ptr.bump();
28 return;
29 }
30 '\n' => return,
31 _ => {
22 ptr.bump(); 32 ptr.bump();
23 } 33 }
24 continue;
25 }
26 if ptr.next_is('\'') {
27 ptr.bump();
28 return;
29 }
30 if ptr.next_is('\n') {
31 break;
32 } 34 }
33 ptr.bump();
34 } 35 }
35} 36}
36 37
@@ -56,9 +57,21 @@ pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind {
56} 57}
57 58
58pub(crate) fn scan_string(ptr: &mut Ptr) { 59pub(crate) fn scan_string(ptr: &mut Ptr) {
59 while let Some(c) = ptr.bump() { 60 while let Some(c) = ptr.next() {
60 if c == '"' { 61 match c {
61 return; 62 '\\' => {
63 ptr.bump();
64 if ptr.next_is('\\') || ptr.next_is('"') {
65 ptr.bump();
66 }
67 }
68 '"' => {
69 ptr.bump();
70 return;
71 }
72 _ => {
73 ptr.bump();
74 },
62 } 75 }
63 } 76 }
64} 77}
diff --git a/crates/libsyntax2/tests/data/lexer/0009_strings.rs b/crates/libsyntax2/tests/data/lexer/0009_strings.rs
index 7b7faa5d8..4ddb5bffc 100644
--- a/crates/libsyntax2/tests/data/lexer/0009_strings.rs
+++ b/crates/libsyntax2/tests/data/lexer/0009_strings.rs
@@ -1 +1,2 @@
1"hello" r"world" 1"hello" r"world" "\n\"\\no escape" "multi
2line"
diff --git a/crates/libsyntax2/tests/data/lexer/0009_strings.txt b/crates/libsyntax2/tests/data/lexer/0009_strings.txt
index 7fb6b7b36..4cb4d711d 100644
--- a/crates/libsyntax2/tests/data/lexer/0009_strings.txt
+++ b/crates/libsyntax2/tests/data/lexer/0009_strings.txt
@@ -1,4 +1,8 @@
1STRING 7 "\"hello\"" 1STRING 7 "\"hello\""
2WHITESPACE 1 " " 2WHITESPACE 1 " "
3RAW_STRING 8 "r\"world\"" 3RAW_STRING 8 "r\"world\""
4WHITESPACE 1 " "
5STRING 17 "\"\\n\\\"\\\\no escape\""
6WHITESPACE 1 " "
7STRING 12 "\"multi\nline\""
4WHITESPACE 1 "\n" 8WHITESPACE 1 "\n"
diff --git a/crates/libsyntax2/tests/data/lexer/0014_unclosed_char.rs b/crates/libsyntax2/tests/data/lexer/0014_unclosed_char.rs
new file mode 100644
index 000000000..9c0007077
--- /dev/null
+++ b/crates/libsyntax2/tests/data/lexer/0014_unclosed_char.rs
@@ -0,0 +1 @@
'1 \ No newline at end of file
diff --git a/crates/libsyntax2/tests/data/lexer/0014_unclosed_char.txt b/crates/libsyntax2/tests/data/lexer/0014_unclosed_char.txt
new file mode 100644
index 000000000..812dfbc18
--- /dev/null
+++ b/crates/libsyntax2/tests/data/lexer/0014_unclosed_char.txt
@@ -0,0 +1 @@
CHAR 2 "\'1"
diff --git a/crates/libsyntax2/tests/data/lexer/0015_unclosed_string.rs b/crates/libsyntax2/tests/data/lexer/0015_unclosed_string.rs
new file mode 100644
index 000000000..d771a26d4
--- /dev/null
+++ b/crates/libsyntax2/tests/data/lexer/0015_unclosed_string.rs
@@ -0,0 +1 @@
"hello
diff --git a/crates/libsyntax2/tests/data/lexer/0015_unclosed_string.txt b/crates/libsyntax2/tests/data/lexer/0015_unclosed_string.txt
new file mode 100644
index 000000000..728c40b66
--- /dev/null
+++ b/crates/libsyntax2/tests/data/lexer/0015_unclosed_string.txt
@@ -0,0 +1 @@
STRING 7 "\"hello\n"