mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Encode ident rawness and literal kind separately in tt::Leaf
This commit is contained in:
parent
5784915618
commit
e846c04fbe
33 changed files with 860 additions and 412 deletions
|
@ -35,20 +35,21 @@ pub(crate) fn to_parser_input<S: Copy + fmt::Debug>(buffer: &TokenBuffer<'_, S>)
|
|||
Some(tt::buffer::TokenTreeRef::Leaf(leaf, _)) => {
|
||||
match leaf {
|
||||
tt::Leaf::Literal(lit) => {
|
||||
let is_negated = lit.text.starts_with('-');
|
||||
let inner_text = &lit.text[if is_negated { 1 } else { 0 }..];
|
||||
|
||||
let kind = parser::LexedStr::single_token(inner_text)
|
||||
.map(|(kind, _error)| kind)
|
||||
.filter(|kind| {
|
||||
kind.is_literal()
|
||||
&& (!is_negated || matches!(kind, FLOAT_NUMBER | INT_NUMBER))
|
||||
})
|
||||
.unwrap_or_else(|| panic!("Fail to convert given literal {:#?}", &lit));
|
||||
|
||||
let kind = match lit.kind {
|
||||
tt::LitKind::Byte => SyntaxKind::BYTE,
|
||||
tt::LitKind::Char => SyntaxKind::CHAR,
|
||||
tt::LitKind::Integer => SyntaxKind::INT_NUMBER,
|
||||
tt::LitKind::Float => SyntaxKind::FLOAT_NUMBER,
|
||||
tt::LitKind::Str | tt::LitKind::StrRaw(_) => SyntaxKind::STRING,
|
||||
tt::LitKind::ByteStr | tt::LitKind::ByteStrRaw(_) => {
|
||||
SyntaxKind::BYTE_STRING
|
||||
}
|
||||
tt::LitKind::CStr | tt::LitKind::CStrRaw(_) => SyntaxKind::C_STRING,
|
||||
tt::LitKind::Err(_) => SyntaxKind::ERROR,
|
||||
};
|
||||
res.push(kind);
|
||||
|
||||
if kind == FLOAT_NUMBER && !inner_text.ends_with('.') {
|
||||
if kind == FLOAT_NUMBER && !lit.text.ends_with('.') {
|
||||
// Tag the token as joint if it is float with a fractional part
|
||||
// we use this jointness to inform the parser about what token split
|
||||
// event to emit when we encounter a float literal in a field access
|
||||
|
@ -58,6 +59,7 @@ pub(crate) fn to_parser_input<S: Copy + fmt::Debug>(buffer: &TokenBuffer<'_, S>)
|
|||
tt::Leaf::Ident(ident) => match ident.text.as_ref() {
|
||||
"_" => res.push(T![_]),
|
||||
i if i.starts_with('\'') => res.push(LIFETIME_IDENT),
|
||||
_ if ident.is_raw.yes() => res.push(IDENT),
|
||||
_ => match SyntaxKind::from_keyword(&ident.text) {
|
||||
Some(kind) => res.push(kind),
|
||||
None => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue