better char lexing

This commit is contained in:
Aleksey Kladov 2018-08-18 12:13:34 +03:00
parent c7b1be6be3
commit a5eeef0eee
3 changed files with 27 additions and 13 deletions

View file

@ -15,14 +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) { 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 {
@ -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();
}

View file

@ -1 +1 @@
'x' ' ' '0' 'x' ' ' '0' 'hello' '\x7f' '\n' '\\' '\''

View file

@ -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"