mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Lexer: underscore
This commit is contained in:
parent
ff5a6549b4
commit
8103772a10
4 changed files with 24 additions and 0 deletions
|
@ -22,6 +22,14 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
|
||||||
// They are not identifiers, and are handled further down.
|
// They are not identifiers, and are handled further down.
|
||||||
let ident_start = is_ident_start(c) && !string_literal_start(c, ptr.next(), ptr.nnext());
|
let ident_start = is_ident_start(c) && !string_literal_start(c, ptr.next(), ptr.nnext());
|
||||||
if ident_start {
|
if ident_start {
|
||||||
|
let is_single_letter = match ptr.next() {
|
||||||
|
None => true,
|
||||||
|
Some(c) if !is_ident_continue(c) => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
if is_single_letter {
|
||||||
|
return if c == '_' { UNDERSCORE } else { IDENT };
|
||||||
|
}
|
||||||
ptr.bump_while(is_ident_continue);
|
ptr.bump_while(is_ident_continue);
|
||||||
return IDENT;
|
return IDENT;
|
||||||
}
|
}
|
||||||
|
|
1
tests/data/lexer/0003_ident.rs
Normal file
1
tests/data/lexer/0003_ident.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo foo_ _foo _ __ x привет
|
14
tests/data/lexer/0003_ident.txt
Normal file
14
tests/data/lexer/0003_ident.txt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
IDENT 3
|
||||||
|
WHITESPACE 1
|
||||||
|
IDENT 4
|
||||||
|
WHITESPACE 1
|
||||||
|
IDENT 4
|
||||||
|
WHITESPACE 1
|
||||||
|
UNDERSCORE 1
|
||||||
|
WHITESPACE 1
|
||||||
|
IDENT 2
|
||||||
|
WHITESPACE 1
|
||||||
|
IDENT 1
|
||||||
|
WHITESPACE 1
|
||||||
|
IDENT 12
|
||||||
|
WHITESPACE 1
|
|
@ -1,4 +1,5 @@
|
||||||
Fixmes:
|
Fixmes:
|
||||||
|
|
||||||
* Fix `is_whitespace`, add more test
|
* Fix `is_whitespace`, add more test
|
||||||
|
* Add more thorough tests for idents for XID_Start & XID_Continue
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue