replace decimal with builtin

This commit is contained in:
notafile 2022-01-04 18:09:37 +01:00
parent 6a4dd3ce54
commit e33dfdc340
2 changed files with 4 additions and 9 deletions

View File

@ -1,3 +1,5 @@
use std::ops::RangeFrom;
use nom::{ use nom::{
bytes::complete::tag, bytes::complete::tag,
character::complete::{char, one_of}, character::complete::{char, one_of},
@ -8,13 +10,6 @@ use nom::{
use crate::parser::IResult; use crate::parser::IResult;
pub fn decimal(input: &str) -> IResult<&str, u64> {
map_res(
recognize(many1(terminated(one_of("0123456789"), many0(char('_'))))),
|out: &str| out.parse::<u64>(),
)(input)
}
pub fn hexadecimal(input: &str) -> IResult<&str, u64> { pub fn hexadecimal(input: &str) -> IResult<&str, u64> {
map_res( map_res(
preceded( preceded(

View File

@ -1,7 +1,7 @@
use nom::{ use nom::{
branch::alt, branch::alt,
bytes::complete::tag, bytes::complete::tag,
character::complete::{alpha1, alphanumeric1, char, multispace0, multispace1}, character::complete::{alpha1, alphanumeric1, char, multispace0, multispace1, u64 as decimal},
combinator::{map, opt, recognize}, combinator::{map, opt, recognize},
error::{context, ParseError, VerboseError}, error::{context, ParseError, VerboseError},
multi::{many0, many1, separated_list0}, multi::{many0, many1, separated_list0},
@ -16,7 +16,7 @@ type Span<'a> = LocatedSpan<&'a str>;
// custom IResult type for VerboseError // custom IResult type for VerboseError
pub type IResult<I, O, E = VerboseError<I>> = nom::IResult<I, O, E>; pub type IResult<I, O, E = VerboseError<I>> = nom::IResult<I, O, E>;
use crate::literals::{decimal, hexadecimal}; use crate::literals::{hexadecimal};
fn ws0<'a, F: 'a, O, E: ParseError<&'a str>>( fn ws0<'a, F: 'a, O, E: ParseError<&'a str>>(
inner: F, inner: F,