mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-18 09:30:31 +00:00
Wrap float literals in their own node
This commit is contained in:
parent
2d5d16f18c
commit
502c519e7d
13 changed files with 113 additions and 49 deletions
|
@ -282,7 +282,7 @@ pub enum LiteralKind {
|
|||
String(ast::String),
|
||||
ByteString(ast::ByteString),
|
||||
IntNumber(ast::IntNumber),
|
||||
FloatNumber(ast::FloatNumber),
|
||||
FloatNumber(ast::FloatLiteral),
|
||||
Char(ast::Char),
|
||||
Byte(ast::Byte),
|
||||
Bool(bool),
|
||||
|
@ -297,16 +297,17 @@ impl ast::Literal {
|
|||
}
|
||||
pub fn kind(&self) -> LiteralKind {
|
||||
let token = match self.value() {
|
||||
rowan::NodeOrToken::Node(_node) => unreachable!(),
|
||||
rowan::NodeOrToken::Node(node) => {
|
||||
return LiteralKind::FloatNumber(
|
||||
ast::FloatLiteral::cast(node).expect("unreachable"),
|
||||
);
|
||||
}
|
||||
rowan::NodeOrToken::Token(token) => token,
|
||||
};
|
||||
|
||||
if let Some(t) = ast::IntNumber::cast(token.clone()) {
|
||||
return LiteralKind::IntNumber(t);
|
||||
}
|
||||
if let Some(t) = ast::FloatNumber::cast(token.clone()) {
|
||||
return LiteralKind::FloatNumber(t);
|
||||
}
|
||||
if let Some(t) = ast::String::cast(token.clone()) {
|
||||
return LiteralKind::String(t);
|
||||
}
|
||||
|
@ -326,6 +327,26 @@ impl ast::Literal {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_string(&self) -> Option<ast::String> {
|
||||
match self.kind() {
|
||||
LiteralKind::String(it) => Some(it),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_byte_string(&self) -> Option<ast::ByteString> {
|
||||
match self.kind() {
|
||||
LiteralKind::ByteString(it) => Some(it),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::FloatLiteral {
|
||||
pub fn suffix(&self) -> Option<String> {
|
||||
ast::FloatNumber::cast(self.syntax().last_token()?)?.suffix().map(|s| s.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub enum BlockModifier {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue