mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Lexer: strings
This commit is contained in:
parent
b704eb708f
commit
d76d7d2a74
6 changed files with 39 additions and 2 deletions
|
@ -11,7 +11,7 @@ mod numbers;
|
||||||
use self::numbers::scan_number;
|
use self::numbers::scan_number;
|
||||||
|
|
||||||
mod strings;
|
mod strings;
|
||||||
use self::strings::{string_literal_start, scan_char, scan_byte_char_or_string};
|
use self::strings::{string_literal_start, scan_char, scan_byte_char_or_string, scan_string, scan_raw_string};
|
||||||
|
|
||||||
pub fn next_token(text: &str) -> Token {
|
pub fn next_token(text: &str) -> Token {
|
||||||
assert!(!text.is_empty());
|
assert!(!text.is_empty());
|
||||||
|
@ -128,6 +128,16 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
|
||||||
scan_literal_suffix(ptr);
|
scan_literal_suffix(ptr);
|
||||||
return kind
|
return kind
|
||||||
},
|
},
|
||||||
|
'"' => {
|
||||||
|
scan_string(ptr);
|
||||||
|
scan_literal_suffix(ptr);
|
||||||
|
return STRING;
|
||||||
|
}
|
||||||
|
'r' => {
|
||||||
|
scan_raw_string(ptr);
|
||||||
|
scan_literal_suffix(ptr);
|
||||||
|
return RAW_STRING;
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
ERROR
|
ERROR
|
||||||
|
|
|
@ -47,6 +47,27 @@ 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn scan_raw_string(ptr: &mut Ptr) {
|
||||||
|
if !ptr.next_is('"') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ptr.bump();
|
||||||
|
|
||||||
|
while let Some(c) = ptr.bump() {
|
||||||
|
if c == '"' {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn scan_byte(ptr: &mut Ptr) {
|
fn scan_byte(ptr: &mut Ptr) {
|
||||||
if ptr.next_is('\'') {
|
if ptr.next_is('\'') {
|
||||||
ptr.bump();
|
ptr.bump();
|
||||||
|
@ -84,3 +105,4 @@ fn scan_char_or_byte(ptr: &mut Ptr) {
|
||||||
//FIXME: deal with escape sequencies
|
//FIXME: deal with escape sequencies
|
||||||
ptr.bump();
|
ptr.bump();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
tests/data/lexer/0009_strings.rs
Normal file
1
tests/data/lexer/0009_strings.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
"hello" r"world"
|
4
tests/data/lexer/0009_strings.txt
Normal file
4
tests/data/lexer/0009_strings.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
STRING 7 "\"hello\""
|
||||||
|
WHITESPACE 1 " "
|
||||||
|
RAW_STRING 8 "r\"world\""
|
||||||
|
WHITESPACE 1 "\n"
|
Loading…
Reference in a new issue