mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
no escape
This commit is contained in:
parent
e8dfb92641
commit
a4f140b0f3
7 changed files with 39 additions and 17 deletions
|
@ -15,22 +15,23 @@ pub(crate) fn is_string_literal_start(c: char, c1: Option<char>, c2: Option<char
|
|||
}
|
||||
|
||||
pub(crate) fn scan_char(ptr: &mut Ptr) {
|
||||
loop {
|
||||
if ptr.next_is('\\') {
|
||||
ptr.bump();
|
||||
if ptr.next_is('\\') || ptr.next_is('\'') {
|
||||
while let Some(c) = ptr.next() {
|
||||
match c {
|
||||
'\\' => {
|
||||
ptr.bump();
|
||||
if ptr.next_is('\\') || ptr.next_is('\'') {
|
||||
ptr.bump();
|
||||
}
|
||||
}
|
||||
'\'' => {
|
||||
ptr.bump();
|
||||
return;
|
||||
}
|
||||
'\n' => return,
|
||||
_ => {
|
||||
ptr.bump();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ptr.next_is('\'') {
|
||||
ptr.bump();
|
||||
return;
|
||||
}
|
||||
if ptr.next_is('\n') {
|
||||
break;
|
||||
}
|
||||
ptr.bump();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,9 +57,21 @@ pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind {
|
|||
}
|
||||
|
||||
pub(crate) fn scan_string(ptr: &mut Ptr) {
|
||||
while let Some(c) = ptr.bump() {
|
||||
if c == '"' {
|
||||
return;
|
||||
while let Some(c) = ptr.next() {
|
||||
match c {
|
||||
'\\' => {
|
||||
ptr.bump();
|
||||
if ptr.next_is('\\') || ptr.next_is('"') {
|
||||
ptr.bump();
|
||||
}
|
||||
}
|
||||
'"' => {
|
||||
ptr.bump();
|
||||
return;
|
||||
}
|
||||
_ => {
|
||||
ptr.bump();
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
"hello" r"world"
|
||||
"hello" r"world" "\n\"\\no escape" "multi
|
||||
line"
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
STRING 7 "\"hello\""
|
||||
WHITESPACE 1 " "
|
||||
RAW_STRING 8 "r\"world\""
|
||||
WHITESPACE 1 " "
|
||||
STRING 17 "\"\\n\\\"\\\\no escape\""
|
||||
WHITESPACE 1 " "
|
||||
STRING 12 "\"multi\nline\""
|
||||
WHITESPACE 1 "\n"
|
||||
|
|
1
crates/libsyntax2/tests/data/lexer/0014_unclosed_char.rs
Normal file
1
crates/libsyntax2/tests/data/lexer/0014_unclosed_char.rs
Normal file
|
@ -0,0 +1 @@
|
|||
'1
|
|
@ -0,0 +1 @@
|
|||
CHAR 2 "\'1"
|
|
@ -0,0 +1 @@
|
|||
"hello
|
|
@ -0,0 +1 @@
|
|||
STRING 7 "\"hello\n"
|
Loading…
Reference in a new issue