aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-14 13:03:27 +0100
committerAleksey Kladov <[email protected]>2018-08-14 13:03:27 +0100
commit109658332a75ca91d6dc2bf573e0ab77fa5619ca (patch)
tree9227430826c75e184577623c25e54489b1033865 /crates/libsyntax2
parent199e3b73c712a74e36bbb75eebf9e9418f1b1341 (diff)
Support raw strings in lexer
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r--crates/libsyntax2/src/lexer/strings.rs14
-rw-r--r--crates/libsyntax2/tests/data/lexer/0013_raw_strings.rs1
-rw-r--r--crates/libsyntax2/tests/data/lexer/0013_raw_strings.txt2
3 files changed, 16 insertions, 1 deletions
diff --git a/crates/libsyntax2/src/lexer/strings.rs b/crates/libsyntax2/src/lexer/strings.rs
index e3704fbb3..fbae767e5 100644
--- a/crates/libsyntax2/src/lexer/strings.rs
+++ b/crates/libsyntax2/src/lexer/strings.rs
@@ -55,6 +55,11 @@ pub(crate) fn scan_string(ptr: &mut Ptr) {
55} 55}
56 56
57pub(crate) fn scan_raw_string(ptr: &mut Ptr) { 57pub(crate) fn scan_raw_string(ptr: &mut Ptr) {
58 let mut hashes = 0;
59 while ptr.next_is('#') {
60 hashes += 1;
61 ptr.bump();
62 }
58 if !ptr.next_is('"') { 63 if !ptr.next_is('"') {
59 return; 64 return;
60 } 65 }
@@ -62,7 +67,14 @@ pub(crate) fn scan_raw_string(ptr: &mut Ptr) {
62 67
63 while let Some(c) = ptr.bump() { 68 while let Some(c) = ptr.bump() {
64 if c == '"' { 69 if c == '"' {
65 return; 70 let mut hashes_left = hashes;
71 while ptr.next_is('#') && hashes_left > 0{
72 hashes_left -= 1;
73 ptr.bump();
74 }
75 if hashes_left == 0 {
76 return;
77 }
66 } 78 }
67 } 79 }
68} 80}
diff --git a/crates/libsyntax2/tests/data/lexer/0013_raw_strings.rs b/crates/libsyntax2/tests/data/lexer/0013_raw_strings.rs
new file mode 100644
index 000000000..e5ed0b693
--- /dev/null
+++ b/crates/libsyntax2/tests/data/lexer/0013_raw_strings.rs
@@ -0,0 +1 @@
r###"this is a r##"raw"## string"###
diff --git a/crates/libsyntax2/tests/data/lexer/0013_raw_strings.txt b/crates/libsyntax2/tests/data/lexer/0013_raw_strings.txt
new file mode 100644
index 000000000..9cf0957d1
--- /dev/null
+++ b/crates/libsyntax2/tests/data/lexer/0013_raw_strings.txt
@@ -0,0 +1,2 @@
1RAW_STRING 36 "r###\"this is a r##\"raw\"## string\"###"
2WHITESPACE 1 "\n"