Also stealing the ParameterizedBlock struct
This commit is contained in:
parent
b7120a34de
commit
15c732b3a3
@ -32,7 +32,7 @@ enum DustTag<'a> {
|
||||
DTNotExists(Container<'a>),
|
||||
DTBlock(NamedBlock<'a>),
|
||||
DTInlinePartial(NamedBlock<'a>),
|
||||
DTPartial(ParameterizedBlock<'a>),
|
||||
DTPartial(Partial<'a>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@ -91,6 +91,14 @@ struct NamedBlock<'a> {
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct ParameterizedBlock<'a> {
|
||||
name: &'a str,
|
||||
params: Vec<KVPair<'a>>,
|
||||
contents: Option<Body<'a>>,
|
||||
else_contents: Option<Body<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
struct Partial<'a> {
|
||||
name: String,
|
||||
params: Vec<KVPair<'a>>,
|
||||
}
|
||||
@ -332,6 +340,7 @@ where
|
||||
|
||||
fn parameterized_self_closing_block<'a, F>(
|
||||
open_matcher: &'static str,
|
||||
tag_name: &'static str,
|
||||
constructor: F,
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>>
|
||||
where
|
||||
@ -341,7 +350,7 @@ where
|
||||
let (i, (name, params)) = delimited(
|
||||
tag(open_matcher),
|
||||
tuple((
|
||||
alt((map(key, String::from), quoted_string)),
|
||||
tag(tag_name),
|
||||
opt(preceded(space1, separated_list(space1, key_value_pair))),
|
||||
)),
|
||||
tag("/}"),
|
||||
@ -352,6 +361,8 @@ where
|
||||
constructor(ParameterizedBlock {
|
||||
name: name,
|
||||
params: params.unwrap_or(Vec::new()),
|
||||
contents: None,
|
||||
else_contents: None,
|
||||
}),
|
||||
))
|
||||
}
|
||||
@ -362,7 +373,7 @@ fn partial<'a, F>(
|
||||
constructor: F,
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>>
|
||||
where
|
||||
F: Fn(ParameterizedBlock<'a>) -> DustTag<'a>,
|
||||
F: Fn(Partial<'a>) -> DustTag<'a>,
|
||||
{
|
||||
move |i: &'a str| {
|
||||
let (i, (name, params)) = delimited(
|
||||
@ -376,7 +387,7 @@ where
|
||||
|
||||
Ok((
|
||||
i,
|
||||
constructor(ParameterizedBlock {
|
||||
constructor(Partial {
|
||||
name: name,
|
||||
params: params.unwrap_or(Vec::new()),
|
||||
}),
|
||||
@ -721,7 +732,7 @@ mod tests {
|
||||
dust_tag(r#"{>foo bar=baz animal="cat"/}"#),
|
||||
Ok((
|
||||
"",
|
||||
DustTag::DTPartial(ParameterizedBlock {
|
||||
DustTag::DTPartial(Partial {
|
||||
name: "foo".to_owned(),
|
||||
params: vec![
|
||||
KVPair {
|
||||
@ -744,7 +755,7 @@ mod tests {
|
||||
dust_tag(r#"{>"template name * with * special \" characters" bar=baz animal="cat"/}"#),
|
||||
Ok((
|
||||
"",
|
||||
DustTag::DTPartial(ParameterizedBlock {
|
||||
DustTag::DTPartial(Partial {
|
||||
name: r#"template name * with * special " characters"#.to_owned(),
|
||||
params: vec![
|
||||
KVPair {
|
||||
|
Loading…
x
Reference in New Issue
Block a user