mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Refactor parser handle mult-char punct internally
This commit is contained in:
parent
1dd3d9bc2d
commit
d436ab0581
9 changed files with 183 additions and 130 deletions
|
@ -88,65 +88,18 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
|
|||
}
|
||||
|
||||
match c {
|
||||
// Multi-byte tokens.
|
||||
'.' => {
|
||||
return match (ptr.current(), ptr.nth(1)) {
|
||||
(Some('.'), Some('.')) => {
|
||||
ptr.bump();
|
||||
ptr.bump();
|
||||
DOTDOTDOT
|
||||
}
|
||||
(Some('.'), Some('=')) => {
|
||||
ptr.bump();
|
||||
ptr.bump();
|
||||
DOTDOTEQ
|
||||
}
|
||||
(Some('.'), _) => {
|
||||
ptr.bump();
|
||||
DOTDOT
|
||||
}
|
||||
_ => DOT,
|
||||
};
|
||||
}
|
||||
':' => {
|
||||
return match ptr.current() {
|
||||
Some(':') => {
|
||||
ptr.bump();
|
||||
COLONCOLON
|
||||
}
|
||||
_ => COLON,
|
||||
};
|
||||
}
|
||||
'=' => {
|
||||
return match ptr.current() {
|
||||
Some('=') => {
|
||||
ptr.bump();
|
||||
EQEQ
|
||||
}
|
||||
Some('>') => {
|
||||
ptr.bump();
|
||||
FAT_ARROW
|
||||
}
|
||||
_ => EQ,
|
||||
};
|
||||
}
|
||||
'!' => {
|
||||
return match ptr.current() {
|
||||
Some('=') => {
|
||||
ptr.bump();
|
||||
NEQ
|
||||
}
|
||||
_ => EXCL,
|
||||
};
|
||||
}
|
||||
'-' => {
|
||||
return if ptr.at('>') {
|
||||
ptr.bump();
|
||||
THIN_ARROW
|
||||
} else {
|
||||
MINUS
|
||||
};
|
||||
}
|
||||
// Possiblily multi-byte tokens,
|
||||
// but we only produce single byte token now
|
||||
// DOTDOTDOT, DOTDOT, DOTDOTEQ, DOT
|
||||
'.' => return DOT,
|
||||
// COLONCOLON COLON
|
||||
':' => return COLON,
|
||||
// EQEQ FATARROW EQ
|
||||
'=' => return EQ,
|
||||
// NEQ EXCL
|
||||
'!' => return EXCL,
|
||||
// THIN_ARROW MINUS
|
||||
'-' => return MINUS,
|
||||
|
||||
// If the character is an ident start not followed by another single
|
||||
// quote, then this is a lifetime name:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue