@@ -36,8 +36,9 @@ pub struct NumericLiteral<'a> {
3636 pub integer : & ' a str ,
3737 /// The fraction part of the number.
3838 pub fraction : Option < & ' a str > ,
39- /// The character used as exponent separator (b'e' or b'E') and the exponent part.
40- pub exponent : Option < ( char , & ' a str ) > ,
39+ /// The exponent separator (b'e' or b'E') including preceding underscore if present
40+ /// and the exponent part.
41+ pub exponent : Option < ( & ' a str , & ' a str ) > ,
4142
4243 /// The type suffix, including preceding underscore if present.
4344 pub suffix : Option < & ' a str > ,
@@ -100,7 +101,7 @@ impl<'a> NumericLiteral<'a> {
100101 self . radix == Radix :: Decimal
101102 }
102103
103- pub fn split_digit_parts ( digits : & str , float : bool ) -> ( & str , Option < & str > , Option < ( char , & str ) > ) {
104+ pub fn split_digit_parts ( digits : & str , float : bool ) -> ( & str , Option < & str > , Option < ( & str , & str ) > ) {
104105 let mut integer = digits;
105106 let mut fraction = None ;
106107 let mut exponent = None ;
@@ -113,12 +114,14 @@ impl<'a> NumericLiteral<'a> {
113114 fraction = Some ( & digits[ i + 1 ..] ) ;
114115 } ,
115116 'e' | 'E' => {
116- if integer. len ( ) > i {
117- integer = & digits[ ..i] ;
117+ let exp_start = if digits[ ..i] . ends_with ( '_' ) { i - 1 } else { i } ;
118+
119+ if integer. len ( ) > exp_start {
120+ integer = & digits[ ..exp_start] ;
118121 } else {
119- fraction = Some ( & digits[ integer. len ( ) + 1 ..i ] ) ;
122+ fraction = Some ( & digits[ integer. len ( ) + 1 ..exp_start ] ) ;
120123 } ;
121- exponent = Some ( ( c , & digits[ i + 1 ..] ) ) ;
124+ exponent = Some ( ( & digits [ exp_start..=i ] , & digits[ i + 1 ..] ) ) ;
122125 break ;
123126 } ,
124127 _ => { } ,
@@ -153,7 +156,7 @@ impl<'a> NumericLiteral<'a> {
153156 }
154157
155158 if let Some ( ( separator, exponent) ) = self . exponent {
156- output. push ( separator) ;
159+ output. push_str ( separator) ;
157160 Self :: group_digits ( & mut output, exponent, group_size, true , false ) ;
158161 }
159162
0 commit comments