Wrap floats in token trees in FLOAT_LITERAL node

This commit is contained in:
Jonas Schievink 2022-05-04 19:25:32 +02:00
parent 90bd99f1bb
commit 34dc8e9383
6 changed files with 33 additions and 22 deletions

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::{literal, LITERAL_FIRST};
pub(super) use self::atom::{float_literal, literal, LITERAL_FIRST};
#[derive(PartialEq, Eq)]
pub(super) enum Semicolon {

View file

@ -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(&[

View file

@ -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(),
}
}