mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
better char lexing
This commit is contained in:
parent
c7b1be6be3
commit
a5eeef0eee
3 changed files with 27 additions and 13 deletions
|
@ -15,15 +15,24 @@ pub(crate) fn is_string_literal_start(c: char, c1: Option<char>, c2: Option<char
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn scan_char(ptr: &mut Ptr) {
|
pub(crate) fn scan_char(ptr: &mut Ptr) {
|
||||||
if ptr.bump().is_none() {
|
loop {
|
||||||
return; // TODO: error reporting is upper in the stack
|
if ptr.next_is('\\') {
|
||||||
|
ptr.bump();
|
||||||
|
if ptr.next_is('\\') || ptr.next_is('\'') {
|
||||||
|
ptr.bump();
|
||||||
}
|
}
|
||||||
scan_char_or_byte(ptr);
|
continue;
|
||||||
if !ptr.next_is('\'') {
|
}
|
||||||
return; // TODO: error reporting
|
if ptr.next_is('\'') {
|
||||||
|
ptr.bump();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ptr.next_is('\n') {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ptr.bump();
|
ptr.bump();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind {
|
pub(crate) fn scan_byte_char_or_string(ptr: &mut Ptr) -> SyntaxKind {
|
||||||
// unwrapping and not-exhaustive match are ok
|
// unwrapping and not-exhaustive match are ok
|
||||||
|
@ -111,8 +120,3 @@ fn scan_raw_byte_string(ptr: &mut Ptr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scan_char_or_byte(ptr: &mut Ptr) {
|
|
||||||
//FIXME: deal with escape sequencies
|
|
||||||
ptr.bump();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
'x' ' ' '0'
|
'x' ' ' '0' 'hello' '\x7f' '\n' '\\' '\''
|
||||||
|
|
|
@ -3,4 +3,14 @@ WHITESPACE 1 " "
|
||||||
CHAR 3 "\' \'"
|
CHAR 3 "\' \'"
|
||||||
WHITESPACE 1 " "
|
WHITESPACE 1 " "
|
||||||
CHAR 3 "\'0\'"
|
CHAR 3 "\'0\'"
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
CHAR 7 "\'hello\'"
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
CHAR 6 "\'\\x7f\'"
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
CHAR 4 "\'\\n\'"
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
CHAR 4 "\'\\\\\'"
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
CHAR 4 "\'\\\'\'"
|
||||||
WHITESPACE 1 "\n"
|
WHITESPACE 1 "\n"
|
||||||
|
|
Loading…
Reference in a new issue