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