The extra steps are making it harder to debug, so move parser directly into test
This commit is contained in:
parent
647c22b3a9
commit
ffce2b0569
@ -6,7 +6,9 @@ use nom::bytes::complete::is_not;
|
|||||||
use nom::bytes::complete::tag;
|
use nom::bytes::complete::tag;
|
||||||
use nom::bytes::complete::take_until;
|
use nom::bytes::complete::take_until;
|
||||||
use nom::character::complete::one_of;
|
use nom::character::complete::one_of;
|
||||||
|
use nom::character::complete::space1;
|
||||||
use nom::combinator::map;
|
use nom::combinator::map;
|
||||||
|
use nom::combinator::not;
|
||||||
use nom::combinator::opt;
|
use nom::combinator::opt;
|
||||||
use nom::combinator::recognize;
|
use nom::combinator::recognize;
|
||||||
use nom::combinator::rest;
|
use nom::combinator::rest;
|
||||||
@ -91,6 +93,7 @@ struct NamedBlock<'a> {
|
|||||||
struct ParameterizedBlock<'a> {
|
struct ParameterizedBlock<'a> {
|
||||||
name: String,
|
name: String,
|
||||||
contents: Option<Body<'a>>,
|
contents: Option<Body<'a>>,
|
||||||
|
params: Vec<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
@ -306,13 +309,21 @@ where
|
|||||||
F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
||||||
{
|
{
|
||||||
move |i: &'a str| {
|
move |i: &'a str| {
|
||||||
let (i, name) = delimited(tag(open_matcher), key, tag("/}"))(i)?;
|
let (i, (name, params)) = delimited(
|
||||||
|
tag(open_matcher),
|
||||||
|
tuple((
|
||||||
|
key,
|
||||||
|
opt(preceded(space1, separated_list(space1, is_not(" ")))),
|
||||||
|
)),
|
||||||
|
tag("/}"),
|
||||||
|
)(i)?;
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
i,
|
i,
|
||||||
constructor(ParameterizedBlock {
|
constructor(ParameterizedBlock {
|
||||||
name: name.to_owned(),
|
name: name.to_owned(),
|
||||||
contents: None,
|
contents: None,
|
||||||
|
params: params.unwrap_or(Vec::new()),
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -652,14 +663,12 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_self_closing_unquoted_partial() {
|
fn test_self_closing_unquoted_partial() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
super::dust_tag("{>foo/}"),
|
delimited(
|
||||||
Ok((
|
tag("{>"),
|
||||||
"",
|
tuple((key, opt(preceded(space1, separated_list(space1, key))),)),
|
||||||
DustTag::DTPartial(ParameterizedBlock {
|
tag("/}"),
|
||||||
name: "foo".to_owned(),
|
)("{>foo bar/}"),
|
||||||
contents: None
|
Ok(("", ("foo", Some(vec!["bar"]))))
|
||||||
})
|
|
||||||
))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user