@@ -740,6 +740,7 @@ struct TtTreeSink<'a> {
740
740
text_pos : TextSize ,
741
741
inner : SyntaxTreeBuilder ,
742
742
token_map : TokenMap ,
743
+ remaining_float_lit_text : String ,
743
744
}
744
745
745
746
impl < ' a > TtTreeSink < ' a > {
@@ -751,6 +752,7 @@ impl<'a> TtTreeSink<'a> {
751
752
text_pos : 0 . into ( ) ,
752
753
inner : SyntaxTreeBuilder :: default ( ) ,
753
754
token_map : TokenMap :: default ( ) ,
755
+ remaining_float_lit_text : String :: new ( ) ,
754
756
}
755
757
}
756
758
@@ -777,6 +779,54 @@ impl<'a> TtTreeSink<'a> {
777
779
n_tokens = 2 ;
778
780
}
779
781
782
+ // We need to split a float `tt::Literal` into up to 3 tokens consumed by the parser.
783
+ match self . cursor . token_tree ( ) {
784
+ Some ( tt:: buffer:: TokenTreeRef :: Subtree ( sub, _) ) if sub. delimiter . is_none ( ) => {
785
+ self . cursor = self . cursor . subtree ( ) . unwrap ( )
786
+ }
787
+ _ => { }
788
+ }
789
+ let literal = match self . cursor . token_tree ( ) {
790
+ Some ( tt:: buffer:: TokenTreeRef :: Leaf ( tt:: Leaf :: Literal ( lit) , _) ) => Some ( lit) ,
791
+ _ => None ,
792
+ } ;
793
+ if matches ! (
794
+ kind,
795
+ FLOAT_NUMBER_PART | FLOAT_NUMBER_START_0 | FLOAT_NUMBER_START_1 | FLOAT_NUMBER_START_2
796
+ ) {
797
+ if self . remaining_float_lit_text . is_empty ( ) {
798
+ always ! (
799
+ literal. is_some( ) ,
800
+ "kind={:?}, cursor tt={:?}" ,
801
+ kind,
802
+ self . cursor. token_tree( )
803
+ ) ;
804
+ let text = literal. map_or ( String :: new ( ) , |lit| lit. to_string ( ) ) ;
805
+ self . cursor = self . cursor . bump ( ) ;
806
+ match text. split_once ( '.' ) {
807
+ Some ( ( start, end) ) => {
808
+ self . inner . token ( kind, start) ;
809
+ self . remaining_float_lit_text = format ! ( ".{end}" ) ;
810
+ return ;
811
+ }
812
+ None => {
813
+ self . inner . token ( kind, & text) ;
814
+ return ;
815
+ }
816
+ }
817
+ } else {
818
+ self . inner . token ( kind, & self . remaining_float_lit_text ) ;
819
+ self . remaining_float_lit_text . clear ( ) ;
820
+ return ;
821
+ }
822
+ }
823
+ if kind == DOT && !self . remaining_float_lit_text . is_empty ( ) {
824
+ always ! ( self . remaining_float_lit_text. chars( ) . next( ) == Some ( '.' ) ) ;
825
+ self . inner . token ( kind, "." ) ;
826
+ self . remaining_float_lit_text = self . remaining_float_lit_text [ 1 ..] . to_string ( ) ;
827
+ return ;
828
+ }
829
+
780
830
let mut last = self . cursor ;
781
831
for _ in 0 ..n_tokens {
782
832
let tmp: u8 ;
0 commit comments