mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Revert "Auto merge of #12149 - jonas-schievink:literally-just-a-literal, r=jonas-schievink"
This reverts commitcc9ae2b89e
, reversing changes made to7dfd1cb572
.
This commit is contained in:
parent
2287ae22c6
commit
9bd11459ba
36 changed files with 121 additions and 502 deletions
|
@ -39,7 +39,6 @@ mod generic_params;
|
|||
mod types;
|
||||
|
||||
use crate::{
|
||||
grammar::expressions::FLOAT_LITERAL_FIRST,
|
||||
parser::{CompletedMarker, Marker, Parser},
|
||||
SyntaxKind::{self, *},
|
||||
TokenSet, T,
|
||||
|
@ -319,15 +318,9 @@ fn name_ref(p: &mut Parser) {
|
|||
}
|
||||
|
||||
fn name_ref_or_index(p: &mut Parser) {
|
||||
assert!(
|
||||
p.at(IDENT) || p.at(INT_NUMBER) || p.at(FLOAT_NUMBER_PART) || p.at_ts(FLOAT_LITERAL_FIRST)
|
||||
);
|
||||
assert!(p.at(IDENT) || p.at(INT_NUMBER));
|
||||
let m = p.start();
|
||||
if p.at_ts(FLOAT_LITERAL_FIRST) {
|
||||
p.bump_remap(FLOAT_NUMBER_PART);
|
||||
} else {
|
||||
p.bump_any();
|
||||
}
|
||||
p.bump_any();
|
||||
m.complete(p, NAME_REF);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ mod atom;
|
|||
use super::*;
|
||||
|
||||
pub(crate) use self::atom::{block_expr, match_arm_list};
|
||||
pub(super) use self::atom::{literal, FLOAT_LITERAL_FIRST, LITERAL_FIRST};
|
||||
pub(super) use self::atom::{literal, LITERAL_FIRST};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub(super) enum Semicolon {
|
||||
|
@ -452,9 +452,6 @@ fn index_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
|||
// fn foo() {
|
||||
// x.foo();
|
||||
// y.bar::<T>(1, 2,);
|
||||
//
|
||||
// 0e0.sin();
|
||||
// 0e0f32.sin();
|
||||
// }
|
||||
fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
||||
assert!(p.at(T![.]) && p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth_at(2, T![::])));
|
||||
|
@ -472,16 +469,17 @@ fn method_call_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
|||
// fn foo() {
|
||||
// x.foo;
|
||||
// x.0.bar;
|
||||
// x.0. bar;
|
||||
// x.0.1;
|
||||
// x.0();
|
||||
// }
|
||||
fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
|
||||
assert!(p.at(T![.]));
|
||||
let m = lhs.precede(p);
|
||||
p.bump(T![.]);
|
||||
if p.at(IDENT) || p.at(INT_NUMBER) || p.at(FLOAT_NUMBER_PART) || p.at_ts(FLOAT_LITERAL_FIRST) {
|
||||
if p.at(IDENT) || p.at(INT_NUMBER) {
|
||||
name_ref_or_index(p);
|
||||
} else if p.at(FLOAT_NUMBER) {
|
||||
// FIXME: How to recover and instead parse INT + T![.]?
|
||||
p.bump_any();
|
||||
} else {
|
||||
p.error("expected field name or number");
|
||||
}
|
||||
|
|
|
@ -17,58 +17,22 @@ pub(crate) const LITERAL_FIRST: TokenSet = TokenSet::new(&[
|
|||
T![true],
|
||||
T![false],
|
||||
INT_NUMBER,
|
||||
FLOAT_NUMBER_START_0,
|
||||
FLOAT_NUMBER_START_1,
|
||||
FLOAT_NUMBER_START_2,
|
||||
FLOAT_NUMBER,
|
||||
BYTE,
|
||||
CHAR,
|
||||
STRING,
|
||||
BYTE_STRING,
|
||||
]);
|
||||
|
||||
pub(crate) const FLOAT_LITERAL_FIRST: TokenSet =
|
||||
TokenSet::new(&[FLOAT_NUMBER_START_0, FLOAT_NUMBER_START_1, FLOAT_NUMBER_START_2]);
|
||||
|
||||
pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
|
||||
if !p.at_ts(LITERAL_FIRST) {
|
||||
return None;
|
||||
}
|
||||
let m = p.start();
|
||||
if p.at_ts(FLOAT_LITERAL_FIRST) {
|
||||
float_literal(p);
|
||||
} else {
|
||||
// Everything else is just one token.
|
||||
p.bump_any();
|
||||
}
|
||||
p.bump_any();
|
||||
Some(m.complete(p, LITERAL))
|
||||
}
|
||||
|
||||
// test float_literal
|
||||
// fn f() {
|
||||
// 0.0;
|
||||
// 1.;
|
||||
// 0e0;
|
||||
// 0e0f32;
|
||||
// 1.23f64;
|
||||
// }
|
||||
pub(crate) fn float_literal(p: &mut Parser) {
|
||||
// Floats can be up to 3 tokens. The first token indicates how many there are.
|
||||
let f = p.start();
|
||||
if p.at(FLOAT_NUMBER_START_0) {
|
||||
p.bump(FLOAT_NUMBER_START_0);
|
||||
} else if p.at(FLOAT_NUMBER_START_1) {
|
||||
p.bump(FLOAT_NUMBER_START_1);
|
||||
p.bump(DOT);
|
||||
} else if p.at(FLOAT_NUMBER_START_2) {
|
||||
p.bump(FLOAT_NUMBER_START_2);
|
||||
p.bump(DOT);
|
||||
p.bump(FLOAT_NUMBER_PART);
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
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(&[
|
||||
|
|
|
@ -140,7 +140,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
|
|||
}
|
||||
|
||||
fn is_literal_pat_start(p: &Parser) -> bool {
|
||||
p.at(T![-]) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER_PART)
|
||||
p.at(T![-]) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER)
|
||||
|| p.at_ts(expressions::LITERAL_FIRST)
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ impl<'a> Converter<'a> {
|
|||
|
||||
rustc_lexer::TokenKind::RawIdent => IDENT,
|
||||
rustc_lexer::TokenKind::Literal { kind, .. } => {
|
||||
self.extend_literal(token_text, kind);
|
||||
self.extend_literal(token_text.len(), kind);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ impl<'a> Converter<'a> {
|
|||
self.push(syntax_kind, token_text.len(), err);
|
||||
}
|
||||
|
||||
fn extend_literal(&mut self, token_text: &str, kind: &rustc_lexer::LiteralKind) {
|
||||
fn extend_literal(&mut self, len: usize, kind: &rustc_lexer::LiteralKind) {
|
||||
let mut err = "";
|
||||
|
||||
let syntax_kind = match *kind {
|
||||
|
@ -237,27 +237,7 @@ impl<'a> Converter<'a> {
|
|||
if empty_exponent {
|
||||
err = "Missing digits after the exponent symbol";
|
||||
}
|
||||
|
||||
// In order to correctly parse nested tuple accesses like `tup.0.0`, where the `0.0`
|
||||
// is lexed as a float, we split floats that contain a `.` into 3 tokens.
|
||||
// To ensure that later stages can always reconstruct the token correctly, the first
|
||||
// token in the sequence indicates the number of following tokens that are part of
|
||||
// the float literal.
|
||||
if let Some((before, after)) = token_text.split_once('.') {
|
||||
let err = if err.is_empty() { None } else { Some(err) };
|
||||
|
||||
assert!(!before.is_empty());
|
||||
let tok =
|
||||
if after.is_empty() { FLOAT_NUMBER_START_1 } else { FLOAT_NUMBER_START_2 };
|
||||
self.push(tok, before.len(), None);
|
||||
self.push(DOT, 1, None);
|
||||
if !after.is_empty() {
|
||||
self.push(FLOAT_NUMBER_PART, after.len(), err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FLOAT_NUMBER_START_0
|
||||
FLOAT_NUMBER
|
||||
}
|
||||
rustc_lexer::LiteralKind::Char { terminated } => {
|
||||
if !terminated {
|
||||
|
@ -315,6 +295,6 @@ impl<'a> Converter<'a> {
|
|||
};
|
||||
|
||||
let err = if err.is_empty() { None } else { Some(err) };
|
||||
self.push(syntax_kind, token_text.len(), err);
|
||||
self.push(syntax_kind, len, err);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue