Rust 使用Nom将整数解析为浮点

Rust 使用Nom将整数解析为浮点,rust,nom,Rust,Nom,Nom有一个: 您需要包装标记!(“)带完成太多,如下所示: named!(unsigned_float_v2 <f32>, map_res!( map_res!( recognize!( alt!( delimited!(digit, complete!(tag!(".")), opt!(complete!(digit))) |

Nom有一个:


您需要包装
标记!(“)
完成太多,如下所示:

named!(unsigned_float_v2 <f32>,
    map_res!(
        map_res!(
            recognize!(
                alt!(
                    delimited!(digit, complete!(tag!(".")), opt!(complete!(digit))) |
                    delimited!(opt!(digit), complete!(tag!("."), digit) |
                    digit
                )
            ),
            str::from_utf8
        ),
        FromStr::from_str
    )
);
命名!(无符号浮点数),
地图(
地图(
认识(
alt(
分隔!(数字,完成!(标记!(“)),选择!(完成!(数字)))|
分隔!(选择!(数字),完成!(标记!(“),数字)|
数字
)
),
str::from_utf8
),
FromStr::FromStr
)
);
如果输入是
123
,则
标记将返回
未完成
,因为它无法确定下一个输入是否是

named!(unsigned_float_v1 <f32>,
    map_res!(
        map_res!(
            alt!(
                recognize!(
                    alt!(
                        delimited!(digit, tag!("."), opt!(complete!(digit))) |
                        delimited!(opt!(digit), tag!("."), digit)
                    )
                ) |
                ws!(digit)
            ),
            str::from_utf8
        ),
        FromStr::from_str
    )
);

named!(unsigned_float_v2 <f32>,
    map_res!(
        map_res!(
            recognize!(
                alt!(
                    delimited!(digit, tag!("."), opt!(complete!(digit))) |
                    delimited!(opt!(digit), tag!("."), digit) |
                    digit
                )
            ),
            str::from_utf8
        ),
        FromStr::from_str
    )
);
named!(unsigned_float_v2 <f32>,
    map_res!(
        map_res!(
            recognize!(
                alt!(
                    delimited!(digit, complete!(tag!(".")), opt!(complete!(digit))) |
                    delimited!(opt!(digit), complete!(tag!("."), digit) |
                    digit
                )
            ),
            str::from_utf8
        ),
        FromStr::from_str
    )
);