@@ -108,24 +108,32 @@ macro_rules! signed_parsable {
108
108
signed_parsable ! ( i8 i16 i32 i64 i128 ) ;
109
109
110
110
macro_rules! floating_parsable {
111
- ( $( $ty: ty => $fn : tt) , +) => {
111
+ ( $( $ty: tt) +) => {
112
112
$(
113
113
impl <I , E : error:: ParseError <I >> ParseFrom <I , E > for $ty
114
114
where
115
- I : Input + Offset + AsBytes + ParseTo <$ty> + Compare <& ' static str >,
115
+ I : Input + Offset + AsBytes + Compare <& ' static str >,
116
116
<I as Input >:: Item : AsChar ,
117
117
<I as Input >:: Iter : Clone ,
118
118
I : for <' a> Compare <& ' a [ u8 ] >,
119
119
{
120
120
fn parse( input: I ) -> nom:: IResult <I , Self , E > {
121
- nom:: number:: complete:: $fn( input)
121
+ use std:: str :: FromStr ;
122
+ use nom:: number:: complete:: recognize_float_or_exceptions;
123
+ use std:: str :: from_utf8;
124
+
125
+ let ( i, s) = recognize_float_or_exceptions( input) ?;
126
+ match from_utf8( s. as_bytes( ) ) . ok( ) . and_then( |s| $ty:: from_str( s) . ok( ) ) {
127
+ Some ( f) => Ok ( ( i, f) ) ,
128
+ None => Err ( nom:: Err :: Error ( E :: from_error_kind( i, nom:: error:: ErrorKind :: Float ) ) ) ,
129
+ }
122
130
}
123
131
}
124
132
) *
125
133
}
126
134
}
127
135
128
- floating_parsable ! ( f32 => float , f64 => double ) ;
136
+ floating_parsable ! ( f32 f64 ) ;
129
137
130
138
/// Support reading the words "true" or "false" from the input and interpreting them as boolean values.
131
139
impl < I , E : error:: ParseError < I > > ParseFrom < I , E > for bool
0 commit comments