From 109658332a75ca91d6dc2bf573e0ab77fa5619ca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 14 Aug 2018 15:03:27 +0300 Subject: Support raw strings in lexer --- crates/libsyntax2/src/lexer/strings.rs | 14 +++++++++++++- crates/libsyntax2/tests/data/lexer/0013_raw_strings.rs | 1 + crates/libsyntax2/tests/data/lexer/0013_raw_strings.txt | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 crates/libsyntax2/tests/data/lexer/0013_raw_strings.rs create mode 100644 crates/libsyntax2/tests/data/lexer/0013_raw_strings.txt (limited to 'crates/libsyntax2') 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) { } pub(crate) fn scan_raw_string(ptr: &mut Ptr) { + let mut hashes = 0; + while ptr.next_is('#') { + hashes += 1; + ptr.bump(); + } if !ptr.next_is('"') { return; } @@ -62,7 +67,14 @@ pub(crate) fn scan_raw_string(ptr: &mut Ptr) { while let Some(c) = ptr.bump() { if c == '"' { - return; + let mut hashes_left = hashes; + while ptr.next_is('#') && hashes_left > 0{ + hashes_left -= 1; + ptr.bump(); + } + if hashes_left == 0 { + return; + } } } } 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 @@ +RAW_STRING 36 "r###\"this is a r##\"raw\"## string\"###" +WHITESPACE 1 "\n" -- cgit v1.2.3