Beginning of creating a generic Container parser
This commit is contained in:
parent
7d51e500d8
commit
5f297eca78
@ -88,12 +88,21 @@ enum TemplateElement<'a> {
|
|||||||
TETag(DustTag<'a>),
|
TETag(DustTag<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Section<'a> {
|
||||||
|
fn new(path: Path<'a>, contents: std::option::Option<Block<'a>>) -> DustTag<'a> {
|
||||||
|
DustTag::DTSection(Section {
|
||||||
|
path: path,
|
||||||
|
contents: contents,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
||||||
alt((
|
alt((
|
||||||
map(special, DustTag::DTSpecial),
|
map(special, DustTag::DTSpecial),
|
||||||
map(comment, DustTag::DTComment),
|
map(comment, DustTag::DTComment),
|
||||||
map(reference, DustTag::DTReference),
|
map(reference, DustTag::DTReference),
|
||||||
map(section, DustTag::DTSection),
|
container("{#", Section::new),
|
||||||
))(i)
|
))(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +152,27 @@ fn reference(i: &str) -> IResult<&str, Reference> {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn container<'a, F>(
|
||||||
|
open_matcher: &'static str,
|
||||||
|
foo: F,
|
||||||
|
) -> impl Fn(&'a str) -> IResult<&'a str, DustTag<'a>>
|
||||||
|
where
|
||||||
|
F: Fn(Path<'a>, Option<Block<'a>>) -> DustTag<'a>,
|
||||||
|
{
|
||||||
|
move |i: &'a str| {
|
||||||
|
let (i, (opening_name, inner, _closing_name)) = verify(
|
||||||
|
tuple((
|
||||||
|
delimited(tag(open_matcher), path, tag("}")),
|
||||||
|
opt(block),
|
||||||
|
delimited(tag("{/"), path, tag("}")),
|
||||||
|
)),
|
||||||
|
|(open, _inn, close)| open == close,
|
||||||
|
)(i)?;
|
||||||
|
|
||||||
|
Ok((i, foo(opening_name, inner)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn section(i: &str) -> IResult<&str, Section> {
|
fn section(i: &str) -> IResult<&str, Section> {
|
||||||
let (i, (opening_name, inner, _closing_name)) = verify(
|
let (i, (opening_name, inner, _closing_name)) = verify(
|
||||||
tuple((
|
tuple((
|
||||||
|
Loading…
x
Reference in New Issue
Block a user