mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Wrap floats in token trees in FLOAT_LITERAL
node
This commit is contained in:
parent
90bd99f1bb
commit
34dc8e9383
6 changed files with 33 additions and 22 deletions
|
@ -3,7 +3,7 @@ mod atom;
|
|||
use super::*;
|
||||
|
||||
pub(crate) use self::atom::{block_expr, match_arm_list};
|
||||
pub(super) use self::atom::{literal, LITERAL_FIRST};
|
||||
pub(super) use self::atom::{float_literal, literal, LITERAL_FIRST};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub(super) enum Semicolon {
|
||||
|
|
|
@ -30,16 +30,7 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
|
|||
}
|
||||
let m = p.start();
|
||||
if p.at(FLOAT_NUMBER_PART) {
|
||||
// Floats can be up to 3 tokens: 2 `FLOAT_NUMBER_PART`s separated by 1 `DOT`
|
||||
let f = p.start();
|
||||
p.bump(FLOAT_NUMBER_PART);
|
||||
if p.at(DOT) {
|
||||
p.bump(DOT);
|
||||
if p.at(FLOAT_NUMBER_PART) {
|
||||
p.bump(FLOAT_NUMBER_PART);
|
||||
}
|
||||
}
|
||||
f.complete(p, FLOAT_LITERAL);
|
||||
float_literal(p);
|
||||
} else {
|
||||
// Everything else is just one token.
|
||||
p.bump_any();
|
||||
|
@ -47,6 +38,19 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
|
|||
Some(m.complete(p, LITERAL))
|
||||
}
|
||||
|
||||
pub(crate) fn float_literal(p: &mut Parser) {
|
||||
// Floats can be up to 3 tokens: 2 `FLOAT_NUMBER_PART`s separated by 1 `DOT`
|
||||
let f = p.start();
|
||||
p.bump(FLOAT_NUMBER_PART);
|
||||
if p.at(DOT) {
|
||||
p.bump(DOT);
|
||||
if p.at(FLOAT_NUMBER_PART) {
|
||||
p.bump(FLOAT_NUMBER_PART);
|
||||
}
|
||||
}
|
||||
f.complete(p, FLOAT_LITERAL);
|
||||
}
|
||||
|
||||
// E.g. for after the break in `if break {}`, this should not match
|
||||
pub(super) const ATOM_EXPR_FIRST: TokenSet =
|
||||
LITERAL_FIRST.union(paths::PATH_FIRST).union(TokenSet::new(&[
|
||||
|
|
|
@ -9,7 +9,7 @@ pub(crate) use self::{
|
|||
traits::assoc_item_list,
|
||||
use_item::use_tree_list,
|
||||
};
|
||||
use super::*;
|
||||
use super::{expressions::float_literal, *};
|
||||
|
||||
// test mod_contents
|
||||
// fn foo() {}
|
||||
|
@ -457,6 +457,9 @@ pub(crate) fn token_tree(p: &mut Parser) {
|
|||
return;
|
||||
}
|
||||
T![')'] | T![']'] => p.err_and_bump("unmatched brace"),
|
||||
FLOAT_NUMBER_PART => {
|
||||
float_literal(p);
|
||||
}
|
||||
_ => p.bump_any(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue