Parsing positive integers.

This commit is contained in:
Tom Alexander 2020-05-10 23:01:14 -04:00
parent 7dd824ab4f
commit 79099a8654
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 15 additions and 2 deletions

View File

@ -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!(