Maybe everything else *should* have to deal with it

This commit is contained in:
Jonas Schievink 2022-05-05 16:26:16 +02:00
parent 2fe38d3b63
commit 37443eb9a1
10 changed files with 34 additions and 39 deletions

View file

@ -30,8 +30,13 @@ pub(super) fn token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Optio
INT_NUMBER if token.ancestors().nth(1).map(|it| it.kind()) == Some(FIELD_EXPR) => {
SymbolKind::Field.into()
}
INT_NUMBER | FLOAT_NUMBER_PART => HlTag::NumericLiteral.into(),
DOT if token.parent().map(|n| n.kind()) == Some(FLOAT_LITERAL) => {
INT_NUMBER | FLOAT_NUMBER_PART | FLOAT_NUMBER_START_0 | FLOAT_NUMBER_START_1
| FLOAT_NUMBER_START_2 => HlTag::NumericLiteral.into(),
DOT if matches!(
token.prev_token().map(|n| n.kind()),
Some(FLOAT_NUMBER_START_1 | FLOAT_NUMBER_START_2)
) =>
{
HlTag::NumericLiteral.into()
}
BYTE => HlTag::ByteLiteral.into(),

View file

@ -260,23 +260,19 @@ fn convert_tokens<C: TokenConvertor>(conv: &mut C) -> tt::Subtree {
IDENT => make_leaf!(Ident),
UNDERSCORE => make_leaf!(Ident),
k if k.is_keyword() => make_leaf!(Ident),
FLOAT_NUMBER_PART => {
FLOAT_NUMBER_START_0 | FLOAT_NUMBER_START_1 | FLOAT_NUMBER_START_2 => {
// Reassemble a split-up float token.
let mut range = range;
let mut text = token.to_text(conv).to_string();
if let Some(dot) = conv.peek() {
if dot.kind(conv) == DOT {
let (_, dot_range) = conv.bump().unwrap();
text += &*dot.to_text(conv);
range = TextRange::new(range.start(), dot_range.end());
if kind == FLOAT_NUMBER_START_1 || kind == FLOAT_NUMBER_START_2 {
let (dot, dot_range) = conv.bump().unwrap();
text += &*dot.to_text(conv);
range = TextRange::new(range.start(), dot_range.end());
if let Some(tail) = conv.peek() {
if tail.kind(conv) == FLOAT_NUMBER_PART {
let (_, tail_range) = conv.bump().unwrap();
text += &*tail.to_text(conv);
range = TextRange::new(range.start(), tail_range.end());
}
}
if kind == FLOAT_NUMBER_START_2 {
let (tail, tail_range) = conv.bump().unwrap();
text += &*tail.to_text(conv);
range = TextRange::new(range.start(), tail_range.end());
}
}

View file

@ -3,7 +3,7 @@ mod atom;
use super::*;
pub(crate) use self::atom::{block_expr, match_arm_list};
pub(super) use self::atom::{float_literal, literal, FLOAT_LITERAL_FIRST, LITERAL_FIRST};
pub(super) use self::atom::{literal, FLOAT_LITERAL_FIRST, LITERAL_FIRST};
#[derive(PartialEq, Eq)]
pub(super) enum Semicolon {

View file

@ -53,16 +53,14 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
// }
pub(crate) fn float_literal(p: &mut Parser) {
// Floats can be up to 3 tokens. The first token indicates how many there are.
// We remap the first token to `FLOAT_NUMBER_PART` so that no subsequent code has to deal with
// this awful, awful hack.
let f = p.start();
if p.at(FLOAT_NUMBER_START_0) {
p.bump_remap(FLOAT_NUMBER_PART);
p.bump(FLOAT_NUMBER_START_0);
} else if p.at(FLOAT_NUMBER_START_1) {
p.bump_remap(FLOAT_NUMBER_PART);
p.bump(FLOAT_NUMBER_START_1);
p.bump(DOT);
} else if p.at(FLOAT_NUMBER_START_2) {
p.bump_remap(FLOAT_NUMBER_PART);
p.bump(FLOAT_NUMBER_START_2);
p.bump(DOT);
p.bump(FLOAT_NUMBER_PART);
} else {

View file

@ -9,7 +9,7 @@ pub(crate) use self::{
traits::assoc_item_list,
use_item::use_tree_list,
};
use super::{expressions::float_literal, *};
use super::*;
// test mod_contents
// fn foo() {}
@ -457,9 +457,6 @@ pub(crate) fn token_tree(p: &mut Parser) {
return;
}
T![')'] | T![']'] => p.err_and_bump("unmatched brace"),
FLOAT_NUMBER_START_0 | FLOAT_NUMBER_START_1 | FLOAT_NUMBER_START_2 => {
float_literal(p);
}
_ => p.bump_any(),
}
}

View file

@ -32,10 +32,9 @@ SOURCE_FILE
INT_NUMBER "1"
COMMA ","
WHITESPACE " "
FLOAT_LITERAL
FLOAT_NUMBER_PART "2"
DOT "."
FLOAT_NUMBER_PART "0"
FLOAT_NUMBER_START_2 "2"
DOT "."
FLOAT_NUMBER_PART "0"
WHITESPACE "\n "
R_CURLY "}"
WHITESPACE " "

View file

@ -58,7 +58,7 @@ SOURCE_FILE
WHITESPACE " "
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "2"
FLOAT_NUMBER_START_2 "2"
DOT "."
FLOAT_NUMBER_PART "0"
SEMICOLON ";"

View file

@ -63,7 +63,7 @@ SOURCE_FILE
METHOD_CALL_EXPR
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "0e0"
FLOAT_NUMBER_START_0 "0e0"
DOT "."
NAME_REF
IDENT "sin"
@ -76,7 +76,7 @@ SOURCE_FILE
METHOD_CALL_EXPR
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "0e0f32"
FLOAT_NUMBER_START_0 "0e0f32"
DOT "."
NAME_REF
IDENT "sin"

View file

@ -15,7 +15,7 @@ SOURCE_FILE
EXPR_STMT
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "0"
FLOAT_NUMBER_START_2 "0"
DOT "."
FLOAT_NUMBER_PART "0"
SEMICOLON ";"
@ -23,26 +23,26 @@ SOURCE_FILE
EXPR_STMT
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "1"
FLOAT_NUMBER_START_1 "1"
DOT "."
SEMICOLON ";"
WHITESPACE "\n "
EXPR_STMT
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "0e0"
FLOAT_NUMBER_START_0 "0e0"
SEMICOLON ";"
WHITESPACE "\n "
EXPR_STMT
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "0e0f32"
FLOAT_NUMBER_START_0 "0e0f32"
SEMICOLON ";"
WHITESPACE "\n "
EXPR_STMT
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "1"
FLOAT_NUMBER_START_2 "1"
DOT "."
FLOAT_NUMBER_PART "23f64"
SEMICOLON ";"

View file

@ -20,7 +20,7 @@ SOURCE_FILE
METHOD_CALL_EXPR
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "1"
FLOAT_NUMBER_START_2 "1"
DOT "."
FLOAT_NUMBER_PART "0f32"
DOT "."
@ -44,7 +44,7 @@ SOURCE_FILE
METHOD_CALL_EXPR
LITERAL
FLOAT_LITERAL
FLOAT_NUMBER_PART "1"
FLOAT_NUMBER_START_2 "1"
DOT "."
FLOAT_NUMBER_PART "0f32"
DOT "."