diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 2e3271dc31..bafbf6d9cc 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -30,8 +30,13 @@ pub(super) fn token(sema: &Semantics, 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(), diff --git a/crates/mbe/src/syntax_bridge.rs b/crates/mbe/src/syntax_bridge.rs index 8b8577986d..79fd1250e0 100644 --- a/crates/mbe/src/syntax_bridge.rs +++ b/crates/mbe/src/syntax_bridge.rs @@ -260,23 +260,19 @@ fn convert_tokens(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()); } } diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index 15dba362a9..290083b343 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -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 { diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs index c191b5593d..5ab148ff28 100644 --- a/crates/parser/src/grammar/expressions/atom.rs +++ b/crates/parser/src/grammar/expressions/atom.rs @@ -53,16 +53,14 @@ pub(crate) fn literal(p: &mut Parser) -> Option { // } 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 { diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs index 6516603402..7bfd9ef8c8 100644 --- a/crates/parser/src/grammar/items.rs +++ b/crates/parser/src/grammar/items.rs @@ -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(), } } diff --git a/crates/parser/test_data/parser/err/0023_mismatched_paren.rast b/crates/parser/test_data/parser/err/0023_mismatched_paren.rast index a13dcd77f5..70cd030da1 100644 --- a/crates/parser/test_data/parser/err/0023_mismatched_paren.rast +++ b/crates/parser/test_data/parser/err/0023_mismatched_paren.rast @@ -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 " " diff --git a/crates/parser/test_data/parser/inline/ok/0085_expr_literals.rast b/crates/parser/test_data/parser/inline/ok/0085_expr_literals.rast index 367aff324a..b3236976b9 100644 --- a/crates/parser/test_data/parser/inline/ok/0085_expr_literals.rast +++ b/crates/parser/test_data/parser/inline/ok/0085_expr_literals.rast @@ -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 ";" diff --git a/crates/parser/test_data/parser/inline/ok/0107_method_call_expr.rast b/crates/parser/test_data/parser/inline/ok/0107_method_call_expr.rast index 0a14e20da8..69f1055b7e 100644 --- a/crates/parser/test_data/parser/inline/ok/0107_method_call_expr.rast +++ b/crates/parser/test_data/parser/inline/ok/0107_method_call_expr.rast @@ -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" diff --git a/crates/parser/test_data/parser/inline/ok/0201_float_literal.rast b/crates/parser/test_data/parser/inline/ok/0201_float_literal.rast index a5cd2dffa4..df4fb6eb41 100644 --- a/crates/parser/test_data/parser/inline/ok/0201_float_literal.rast +++ b/crates/parser/test_data/parser/inline/ok/0201_float_literal.rast @@ -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 ";" diff --git a/crates/parser/test_data/parser/ok/0056_neq_in_type.rast b/crates/parser/test_data/parser/ok/0056_neq_in_type.rast index 5fd9271c62..b2f66e2f1e 100644 --- a/crates/parser/test_data/parser/ok/0056_neq_in_type.rast +++ b/crates/parser/test_data/parser/ok/0056_neq_in_type.rast @@ -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 "."