From d30749f7092d6c31519e99d0926bb6e5cf40b5fe Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 12 Apr 2020 17:39:24 -0400 Subject: [PATCH] Updated to the latest nom --- src/lib.rs | 3 +++ src/parser/parser.rs | 19 ++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1f08a84..745bad9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,3 +2,6 @@ extern crate nom; mod parser; mod renderer; + +pub use renderer::compile_template; +pub use renderer::DustRenderer; diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 41d13bd..211edac 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -17,8 +17,7 @@ use nom::combinator::value; use nom::combinator::verify; use nom::multi::many0; use nom::multi::many1; -use nom::multi::separated_list; -use nom::multi::separated_nonempty_list; +use nom::multi::separated_list1; use nom::sequence::delimited; use nom::sequence::preceded; use nom::sequence::separated_pair; @@ -198,9 +197,7 @@ fn key(i: &str) -> IResult<&str, &str> { /// A series of keys separated by '.' to reference a variable in the context fn path(i: &str) -> IResult<&str, Path> { - map(separated_nonempty_list(tag("."), key), |body| Path { - keys: body, - })(i) + map(separated_list1(tag("."), key), |body| Path { keys: body })(i) } /// Either a literal or a path to a value @@ -234,7 +231,7 @@ fn reference(i: &str) -> IResult<&str, Reference> { fn conditional<'a, F>( open_matcher: &'static str, constructor: F, -) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>> +) -> impl FnMut(&'a str) -> IResult<&'a str, DustTag<'a>> where F: Copy + Fn(Container<'a>) -> DustTag<'a>, { @@ -297,7 +294,7 @@ where fn named_block<'a, F>( open_matcher: &'static str, constructor: F, -) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>> +) -> impl FnMut(&'a str) -> IResult<&'a str, DustTag<'a>> where F: Copy + Fn(NamedBlock<'a>) -> DustTag<'a>, { @@ -358,7 +355,7 @@ fn parameterized_block<'a, F>( open_matcher: &'static str, tag_name: &'static str, constructor: F, -) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>> +) -> impl FnMut(&'a str) -> IResult<&'a str, DustTag<'a>> where F: Copy + Fn(ParameterizedBlock<'a>) -> DustTag<'a>, { @@ -380,7 +377,7 @@ where let (i, (name, params, inner, maybe_else, _closing_name)) = tuple(( preceded(tag(open_matcher), tag(tag_name)), terminated( - opt(preceded(space1, separated_list(space1, key_value_pair))), + opt(preceded(space1, separated_list1(space1, key_value_pair))), tag("}"), ), opt(body), @@ -413,7 +410,7 @@ where tag(open_matcher), tuple(( tag(tag_name), - opt(preceded(space1, separated_list(space1, key_value_pair))), + opt(preceded(space1, separated_list1(space1, key_value_pair))), )), tag("/}"), )(i)?; @@ -442,7 +439,7 @@ where tag(open_matcher), tuple(( alt((map(key, String::from), quoted_string)), - opt(preceded(space1, separated_list(space1, key_value_pair))), + opt(preceded(space1, separated_list1(space1, key_value_pair))), )), tag("/}"), )(i)?;