Updated to the latest nom

This commit is contained in:
Tom Alexander 2020-04-12 17:39:24 -04:00
parent 28b5cf1d34
commit d30749f709
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 11 additions and 11 deletions

View File

@ -2,3 +2,6 @@ extern crate nom;
mod parser; mod parser;
mod renderer; mod renderer;
pub use renderer::compile_template;
pub use renderer::DustRenderer;

View File

@ -17,8 +17,7 @@ use nom::combinator::value;
use nom::combinator::verify; use nom::combinator::verify;
use nom::multi::many0; use nom::multi::many0;
use nom::multi::many1; use nom::multi::many1;
use nom::multi::separated_list; use nom::multi::separated_list1;
use nom::multi::separated_nonempty_list;
use nom::sequence::delimited; use nom::sequence::delimited;
use nom::sequence::preceded; use nom::sequence::preceded;
use nom::sequence::separated_pair; 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 /// A series of keys separated by '.' to reference a variable in the context
fn path(i: &str) -> IResult<&str, Path> { fn path(i: &str) -> IResult<&str, Path> {
map(separated_nonempty_list(tag("."), key), |body| Path { map(separated_list1(tag("."), key), |body| Path { keys: body })(i)
keys: body,
})(i)
} }
/// Either a literal or a path to a value /// Either a literal or a path to a value
@ -234,7 +231,7 @@ fn reference(i: &str) -> IResult<&str, Reference> {
fn conditional<'a, F>( fn conditional<'a, F>(
open_matcher: &'static str, open_matcher: &'static str,
constructor: F, constructor: F,
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>> ) -> impl FnMut(&'a str) -> IResult<&'a str, DustTag<'a>>
where where
F: Copy + Fn(Container<'a>) -> DustTag<'a>, F: Copy + Fn(Container<'a>) -> DustTag<'a>,
{ {
@ -297,7 +294,7 @@ where
fn named_block<'a, F>( fn named_block<'a, F>(
open_matcher: &'static str, open_matcher: &'static str,
constructor: F, constructor: F,
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>> ) -> impl FnMut(&'a str) -> IResult<&'a str, DustTag<'a>>
where where
F: Copy + Fn(NamedBlock<'a>) -> DustTag<'a>, F: Copy + Fn(NamedBlock<'a>) -> DustTag<'a>,
{ {
@ -358,7 +355,7 @@ fn parameterized_block<'a, F>(
open_matcher: &'static str, open_matcher: &'static str,
tag_name: &'static str, tag_name: &'static str,
constructor: F, constructor: F,
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>> ) -> impl FnMut(&'a str) -> IResult<&'a str, DustTag<'a>>
where where
F: Copy + Fn(ParameterizedBlock<'a>) -> DustTag<'a>, F: Copy + Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
{ {
@ -380,7 +377,7 @@ where
let (i, (name, params, inner, maybe_else, _closing_name)) = tuple(( let (i, (name, params, inner, maybe_else, _closing_name)) = tuple((
preceded(tag(open_matcher), tag(tag_name)), preceded(tag(open_matcher), tag(tag_name)),
terminated( terminated(
opt(preceded(space1, separated_list(space1, key_value_pair))), opt(preceded(space1, separated_list1(space1, key_value_pair))),
tag("}"), tag("}"),
), ),
opt(body), opt(body),
@ -413,7 +410,7 @@ where
tag(open_matcher), tag(open_matcher),
tuple(( tuple((
tag(tag_name), tag(tag_name),
opt(preceded(space1, separated_list(space1, key_value_pair))), opt(preceded(space1, separated_list1(space1, key_value_pair))),
)), )),
tag("/}"), tag("/}"),
)(i)?; )(i)?;
@ -442,7 +439,7 @@ where
tag(open_matcher), tag(open_matcher),
tuple(( tuple((
alt((map(key, String::from), quoted_string)), 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("/}"), tag("/}"),
)(i)?; )(i)?;