Split float literal tokens at the .

This commit is contained in:
Jonas Schievink 2022-05-04 16:51:05 +02:00
parent 502c519e7d
commit 1bc3305d95
23 changed files with 157 additions and 72 deletions

View file

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

View file

@ -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)]

View file

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

View file

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

View file

@ -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();