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::take_until;
|
||||
use nom::character::complete::one_of;
|
||||
use nom::character::complete::space1;
|
||||
use nom::combinator::map;
|
||||
use nom::combinator::not;
|
||||
use nom::combinator::opt;
|
||||
use nom::combinator::recognize;
|
||||
use nom::combinator::rest;
|
||||
@ -91,6 +93,7 @@ struct NamedBlock<'a> {
|
||||
struct ParameterizedBlock<'a> {
|
||||
name: String,
|
||||
contents: Option<Body<'a>>,
|
||||
params: Vec<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@ -306,13 +309,21 @@ where
|
||||
F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
||||
{
|
||||
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((
|
||||
i,
|
||||
constructor(ParameterizedBlock {
|
||||
name: name.to_owned(),
|
||||
contents: None,
|
||||
params: params.unwrap_or(Vec::new()),
|
||||
}),
|
||||
))
|
||||
}
|
||||
@ -652,14 +663,12 @@ mod tests {
|
||||
#[test]
|
||||
fn test_self_closing_unquoted_partial() {
|
||||
assert_eq!(
|
||||
super::dust_tag("{>foo/}"),
|
||||
Ok((
|
||||
"",
|
||||
DustTag::DTPartial(ParameterizedBlock {
|
||||
name: "foo".to_owned(),
|
||||
contents: None
|
||||
})
|
||||
))
|
||||
delimited(
|
||||
tag("{>"),
|
||||
tuple((key, opt(preceded(space1, separated_list(space1, key))),)),
|
||||
tag("/}"),
|
||||
)("{>foo bar/}"),
|
||||
Ok(("", ("foo", Some(vec!["bar"]))))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user