diff options
Diffstat (limited to 'crates/syntax/src/ast/token_ext.rs')
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index bf0035986..e4e512f2e 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs | |||
@@ -517,10 +517,9 @@ impl HasFormatSpecifier for ast::String { | |||
517 | } | 517 | } |
518 | 518 | ||
519 | impl ast::IntNumber { | 519 | impl ast::IntNumber { |
520 | #[rustfmt::skip] | 520 | const SUFFIXES: &'static [&'static str] = &[ |
521 | pub(crate) const SUFFIXES: &'static [&'static str] = &[ | 521 | "u8", "u16", "u32", "u64", "u128", "usize", // Unsigned. |
522 | "u8", "u16", "u32", "u64", "u128", "usize", | 522 | "i8", "i16", "i32", "i64", "i128", "isize", // Signed. |
523 | "i8", "i16", "i32", "i64", "i128", "isize", | ||
524 | ]; | 523 | ]; |
525 | 524 | ||
526 | pub fn radix(&self) -> Radix { | 525 | pub fn radix(&self) -> Radix { |
@@ -555,9 +554,24 @@ impl ast::IntNumber { | |||
555 | 554 | ||
556 | pub fn suffix(&self) -> Option<&str> { | 555 | pub fn suffix(&self) -> Option<&str> { |
557 | let text = self.text(); | 556 | let text = self.text(); |
558 | // FIXME: don't check a fixed set of suffixes, `1_0_1___lol` is valid | 557 | // FIXME: don't check a fixed set of suffixes, `1_0_1_l_o_l` is valid |
559 | // syntax, suffix is `lol`. | 558 | // syntax, suffix is `l_o_l`. |
560 | ast::IntNumber::SUFFIXES.iter().find_map(|suffix| { | 559 | ast::IntNumber::SUFFIXES.iter().chain(ast::FloatNumber::SUFFIXES.iter()).find_map( |
560 | |suffix| { | ||
561 | if text.ends_with(suffix) { | ||
562 | return Some(&text[text.len() - suffix.len()..]); | ||
563 | } | ||
564 | None | ||
565 | }, | ||
566 | ) | ||
567 | } | ||
568 | } | ||
569 | |||
570 | impl ast::FloatNumber { | ||
571 | const SUFFIXES: &'static [&'static str] = &["f32", "f64"]; | ||
572 | pub fn suffix(&self) -> Option<&str> { | ||
573 | let text = self.text(); | ||
574 | ast::FloatNumber::SUFFIXES.iter().find_map(|suffix| { | ||
561 | if text.ends_with(suffix) { | 575 | if text.ends_with(suffix) { |
562 | return Some(&text[text.len() - suffix.len()..]); | 576 | return Some(&text[text.len() - suffix.len()..]); |
563 | } | 577 | } |
@@ -566,10 +580,6 @@ impl ast::IntNumber { | |||
566 | } | 580 | } |
567 | } | 581 | } |
568 | 582 | ||
569 | impl ast::FloatNumber { | ||
570 | pub(crate) const SUFFIXES: &'static [&'static str] = &["f32", "f64"]; | ||
571 | } | ||
572 | |||
573 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] | 583 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] |
574 | pub enum Radix { | 584 | pub enum Radix { |
575 | Binary = 2, | 585 | Binary = 2, |