最后我把它建成了
fn simple_number<'a>(i: &'a str) -> IResult<&'a str, Token, (&'a str, ErrorKind)> {
map(
recognize(tuple( (opt(alt((char('-'), char('+')))), many1(digit1), opt(preceded(char('.'), many1(digit1)))) ) ),
|s: &str| Token::Number(s.parse::<f64>().unwrap(), "".into())
//|s: &str| Token::Var(s.into())
)(i)
}
fn exponent<'a>(i: &'a str) -> IResult<&'a str, Token, (&'a str, ErrorKind)> {
map(
recognize(tuple( ( alt((char('e'), char('E'))), simple_number )) ),
|s: &str| Token::Var(s.into())
)(i)
}
fn number<'a>(i: &'a str) -> IResult<&'a str, f64, (&'a str, ErrorKind)> {
map(
recognize(tuple((simple_number, opt(exponent))) ),
|s: &str| s.parse::<f64>().unwrap()
)(i)
}
fn units<'a>(i: &'a str) -> IResult<&'a str, &'a str, (&'a str, ErrorKind)> {
alphanumeric1(i)
}
fn number_with_unit<'a>(i: &'a str) -> IResult<&'a str, Token, (&'a str, ErrorKind)> {
map(
tuple((number, opt(units))),
|t: (f64, Option<&str>)| Token::Number(t.0, t.1.unwrap_or(&"".to_string()).into())
)(i)
}
// Number: 1, -34, 5.4, -5.4, 9.23, 74.2, 4, 5.4e-45, -5.4e-45, 67.3E7 INF -INF +INF NAN
fn zinc_number<'a>(i: &'a str) -> IResult<&'a str, Token, (&'a str, ErrorKind)> {
alt( (number_with_unit, inf, nan) ) (i)
}