@@ -36,8 +36,9 @@ pub struct NumericLiteral<'a> {
36
36
pub integer : & ' a str ,
37
37
/// The fraction part of the number.
38
38
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 ) > ,
41
42
42
43
/// The type suffix, including preceding underscore if present.
43
44
pub suffix : Option < & ' a str > ,
@@ -100,7 +101,7 @@ impl<'a> NumericLiteral<'a> {
100
101
self . radix == Radix :: Decimal
101
102
}
102
103
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 ) > ) {
104
105
let mut integer = digits;
105
106
let mut fraction = None ;
106
107
let mut exponent = None ;
@@ -113,12 +114,14 @@ impl<'a> NumericLiteral<'a> {
113
114
fraction = Some ( & digits[ i + 1 ..] ) ;
114
115
} ,
115
116
'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] ;
118
121
} else {
119
- fraction = Some ( & digits[ integer. len ( ) + 1 ..i ] ) ;
122
+ fraction = Some ( & digits[ integer. len ( ) + 1 ..exp_start ] ) ;
120
123
} ;
121
- exponent = Some ( ( c , & digits[ i + 1 ..] ) ) ;
124
+ exponent = Some ( ( & digits [ exp_start..=i ] , & digits[ i + 1 ..] ) ) ;
122
125
break ;
123
126
} ,
124
127
_ => { } ,
@@ -153,7 +156,7 @@ impl<'a> NumericLiteral<'a> {
153
156
}
154
157
155
158
if let Some ( ( separator, exponent) ) = self . exponent {
156
- output. push ( separator) ;
159
+ output. push_str ( separator) ;
157
160
Self :: group_digits ( & mut output, exponent, group_size, true , false ) ;
158
161
}
159
162
0 commit comments