Parsing positive integers.
This commit is contained in:
parent
7dd824ab4f
commit
79099a8654
@ -2,11 +2,11 @@ use nom::branch::alt;
|
||||
use nom::bytes::complete::escaped_transform;
|
||||
use nom::bytes::complete::is_a;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::bytes::complete::{tag, take_until, take_until_parser_matches};
|
||||
use nom::bytes::complete::{tag, take_until, take_until_parser_matches, take_while};
|
||||
use nom::character::complete::line_ending;
|
||||
use nom::character::complete::multispace0;
|
||||
use nom::character::complete::one_of;
|
||||
use nom::character::complete::{space0, space1};
|
||||
use nom::character::complete::{digit1, space0, space1};
|
||||
use nom::combinator::all_consuming;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::opt;
|
||||
@ -122,6 +122,7 @@ pub struct Partial<'a> {
|
||||
pub enum RValue<'a> {
|
||||
RVPath(Path<'a>),
|
||||
RVString(String),
|
||||
RVPositiveInteger(u64),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@ -210,6 +211,16 @@ fn path(i: &str) -> IResult<&str, Path> {
|
||||
))(i)
|
||||
}
|
||||
|
||||
fn postitive_integer_literal(i: &str) -> IResult<&str, RValue> {
|
||||
map(
|
||||
verify(
|
||||
map(digit1, |number_string: &str| number_string.parse::<u64>()),
|
||||
|parse_result| parse_result.is_ok(),
|
||||
),
|
||||
|parsed_number| RValue::RVPositiveInteger(parsed_number.unwrap()),
|
||||
)(i)
|
||||
}
|
||||
|
||||
/// Either a literal or a path to a value
|
||||
fn rvalue(i: &str) -> IResult<&str, RValue> {
|
||||
alt((
|
||||
@ -906,6 +917,8 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: Add test for integer literals
|
||||
|
||||
#[test]
|
||||
fn test_quoted_partial() {
|
||||
assert_eq!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user