]> git.lizzy.rs Git - rust.git/commitdiff
Revert "Fix conversion of float literals in `TtTreeSink`"
authorJonas Schievink <jonas.schievink@ferrous-systems.com>
Fri, 13 May 2022 13:05:17 +0000 (15:05 +0200)
committerJonas Schievink <jonas.schievink@ferrous-systems.com>
Fri, 13 May 2022 13:05:34 +0000 (15:05 +0200)
This reverts commit 43a066c5a87972b5e42ad41bab56861661c49b18.

crates/hir-def/src/macro_expansion_tests/mbe/tt_conversion.rs
crates/mbe/src/syntax_bridge.rs

index 9e4ab043f6cebd2cd92386a887b8abc0f072f164..73799574d83eea9f234f3aec7b2390aa869b2603 100644 (file)
@@ -183,22 +183,18 @@ fn float_literal_in_tt() {
 macro_rules! constant {
     ($( $ret:expr; )*) => {};
 }
-
 macro_rules! float_const_impl {
     () => ( constant!(0.3; 3.3;); );
 }
-
 float_const_impl! {}
 "#,
         expect![[r#"
 macro_rules! constant {
     ($( $ret:expr; )*) => {};
 }
-
 macro_rules! float_const_impl {
     () => ( constant!(0.3; 3.3;); );
 }
-
 constant!(0.3;
 3.3;
 );
index fb6f8d66c6d74dd0b1625a824bbc7f8c01fcd020..83d22af92325eae3b65be0861499d8e9a4d32a1a 100644 (file)
@@ -740,7 +740,6 @@ struct TtTreeSink<'a> {
     text_pos: TextSize,
     inner: SyntaxTreeBuilder,
     token_map: TokenMap,
-    remaining_float_lit_text: String,
 }
 
 impl<'a> TtTreeSink<'a> {
@@ -752,7 +751,6 @@ fn new(cursor: Cursor<'a>) -> Self {
             text_pos: 0.into(),
             inner: SyntaxTreeBuilder::default(),
             token_map: TokenMap::default(),
-            remaining_float_lit_text: String::new(),
         }
     }
 
@@ -779,54 +777,6 @@ fn token(&mut self, kind: SyntaxKind, mut n_tokens: u8) {
             n_tokens = 2;
         }
 
-        // We need to split a float `tt::Literal` into up to 3 tokens consumed by the parser.
-        match self.cursor.token_tree() {
-            Some(tt::buffer::TokenTreeRef::Subtree(sub, _)) if sub.delimiter.is_none() => {
-                self.cursor = self.cursor.subtree().unwrap()
-            }
-            _ => {}
-        }
-        let literal = match self.cursor.token_tree() {
-            Some(tt::buffer::TokenTreeRef::Leaf(tt::Leaf::Literal(lit), _)) => Some(lit),
-            _ => None,
-        };
-        if matches!(
-            kind,
-            FLOAT_NUMBER_PART | FLOAT_NUMBER_START_0 | FLOAT_NUMBER_START_1 | FLOAT_NUMBER_START_2
-        ) {
-            if self.remaining_float_lit_text.is_empty() {
-                always!(
-                    literal.is_some(),
-                    "kind={:?}, cursor tt={:?}",
-                    kind,
-                    self.cursor.token_tree()
-                );
-                let text = literal.map_or(String::new(), |lit| lit.to_string());
-                self.cursor = self.cursor.bump();
-                match text.split_once('.') {
-                    Some((start, end)) => {
-                        self.inner.token(kind, start);
-                        self.remaining_float_lit_text = format!(".{end}");
-                        return;
-                    }
-                    None => {
-                        self.inner.token(kind, &text);
-                        return;
-                    }
-                }
-            } else {
-                self.inner.token(kind, &self.remaining_float_lit_text);
-                self.remaining_float_lit_text.clear();
-                return;
-            }
-        }
-        if kind == DOT && !self.remaining_float_lit_text.is_empty() {
-            always!(self.remaining_float_lit_text.chars().next() == Some('.'));
-            self.inner.token(kind, ".");
-            self.remaining_float_lit_text = self.remaining_float_lit_text[1..].to_string();
-            return;
-        }
-
         let mut last = self.cursor;
         for _ in 0..n_tokens {
             let tmp: u8;