mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Split float literal tokens at the .
This commit is contained in:
parent
502c519e7d
commit
1bc3305d95
23 changed files with 157 additions and 72 deletions
|
@ -373,7 +373,9 @@ Literal =
|
|||
)
|
||||
|
||||
FloatLiteral =
|
||||
'float_number'
|
||||
'float_number_part'
|
||||
'.'?
|
||||
'float_number_part'?
|
||||
|
||||
PathExpr =
|
||||
Attr* Path
|
||||
|
|
|
@ -345,7 +345,7 @@ impl ast::Literal {
|
|||
|
||||
impl ast::FloatLiteral {
|
||||
pub fn suffix(&self) -> Option<String> {
|
||||
ast::FloatNumber::cast(self.syntax().last_token()?)?.suffix().map(|s| s.to_string())
|
||||
ast::FloatNumberPart::cast(self.syntax().last_token()?)?.suffix().map(|s| s.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1090,9 +1090,10 @@ pub struct FloatLiteral {
|
|||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
impl FloatLiteral {
|
||||
pub fn float_number_token(&self) -> Option<SyntaxToken> {
|
||||
support::token(&self.syntax, T![float_number])
|
||||
pub fn float_number_part_token(&self) -> Option<SyntaxToken> {
|
||||
support::token(&self.syntax, T![float_number_part])
|
||||
}
|
||||
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
|
|
@ -112,16 +112,16 @@ impl AstToken for IntNumber {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FloatNumber {
|
||||
pub struct FloatNumberPart {
|
||||
pub(crate) syntax: SyntaxToken,
|
||||
}
|
||||
impl std::fmt::Display for FloatNumber {
|
||||
impl std::fmt::Display for FloatNumberPart {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
std::fmt::Display::fmt(&self.syntax, f)
|
||||
}
|
||||
}
|
||||
impl AstToken for FloatNumber {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == FLOAT_NUMBER }
|
||||
impl AstToken for FloatNumberPart {
|
||||
fn can_cast(kind: SyntaxKind) -> bool { kind == FLOAT_NUMBER_PART }
|
||||
fn cast(syntax: SyntaxToken) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
|
|
|
@ -555,7 +555,9 @@ impl ast::FieldExpr {
|
|||
self.syntax
|
||||
.children_with_tokens()
|
||||
// FIXME: Accepting floats here to reject them in validation later
|
||||
.find(|c| c.kind() == SyntaxKind::INT_NUMBER || c.kind() == SyntaxKind::FLOAT_NUMBER)
|
||||
.find(|c| {
|
||||
c.kind() == SyntaxKind::INT_NUMBER || c.kind() == SyntaxKind::FLOAT_NUMBER_PART
|
||||
})
|
||||
.as_ref()
|
||||
.and_then(SyntaxElement::as_token)
|
||||
.cloned()
|
||||
|
|
|
@ -321,7 +321,7 @@ impl ast::IntNumber {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::FloatNumber {
|
||||
impl ast::FloatNumberPart {
|
||||
pub fn suffix(&self) -> Option<&str> {
|
||||
let text = self.text();
|
||||
let mut indices = text.char_indices();
|
||||
|
|
|
@ -71,7 +71,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
|
|||
"super", "trait", "true", "try", "type", "unsafe", "use", "where", "while", "yield",
|
||||
],
|
||||
contextual_keywords: &["auto", "default", "existential", "union", "raw", "macro_rules"],
|
||||
literals: &["INT_NUMBER", "FLOAT_NUMBER", "CHAR", "BYTE", "STRING", "BYTE_STRING"],
|
||||
literals: &["INT_NUMBER", "FLOAT_NUMBER_PART", "CHAR", "BYTE", "STRING", "BYTE_STRING"],
|
||||
tokens: &["ERROR", "IDENT", "WHITESPACE", "LIFETIME_IDENT", "COMMENT", "SHEBANG"],
|
||||
nodes: &[
|
||||
"SOURCE_FILE",
|
||||
|
|
|
@ -462,7 +462,7 @@ fn generate_syntax_kinds(grammar: KindsSrc<'_>) -> String {
|
|||
[lifetime_ident] => { $crate::SyntaxKind::LIFETIME_IDENT };
|
||||
[ident] => { $crate::SyntaxKind::IDENT };
|
||||
[shebang] => { $crate::SyntaxKind::SHEBANG };
|
||||
[float_number] => { $crate::SyntaxKind::FLOAT_NUMBER };
|
||||
[float_number_part] => { $crate::SyntaxKind::FLOAT_NUMBER_PART };
|
||||
}
|
||||
pub use T;
|
||||
};
|
||||
|
@ -586,7 +586,7 @@ impl Field {
|
|||
|
||||
fn lower(grammar: &Grammar) -> AstSrc {
|
||||
let mut res = AstSrc {
|
||||
tokens: "Whitespace Comment String ByteString IntNumber FloatNumber Char Byte Ident"
|
||||
tokens: "Whitespace Comment String ByteString IntNumber FloatNumberPart Char Byte Ident"
|
||||
.split_ascii_whitespace()
|
||||
.map(|it| it.to_string())
|
||||
.collect::<Vec<_>>(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue