separate out the parser for key because partials don't use a full path, only a key
This commit is contained in:
parent
7f2c7151a9
commit
de4f420627
@ -91,6 +91,9 @@ enum TemplateElement<'a> {
|
|||||||
TETag(DustTag<'a>),
|
TETag(DustTag<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Any element significant to dust that isn't plain text
|
||||||
|
///
|
||||||
|
/// These elements are always wrapped in curly braces
|
||||||
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),
|
||||||
@ -102,6 +105,7 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
|||||||
))(i)
|
))(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Special characters
|
||||||
fn special(i: &str) -> IResult<&str, Special> {
|
fn special(i: &str) -> IResult<&str, Special> {
|
||||||
delimited(
|
delimited(
|
||||||
tag("{~"),
|
tag("{~"),
|
||||||
@ -116,27 +120,29 @@ fn special(i: &str) -> IResult<&str, Special> {
|
|||||||
)(i)
|
)(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Part of a dust template that does not get rendered
|
||||||
fn comment(i: &str) -> IResult<&str, Comment> {
|
fn comment(i: &str) -> IResult<&str, Comment> {
|
||||||
map(delimited(tag("{!"), take_until("!}"), tag("!}")), |body| {
|
map(delimited(tag("{!"), take_until("!}"), tag("!}")), |body| {
|
||||||
Comment { value: body }
|
Comment { value: body }
|
||||||
})(i)
|
})(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path(i: &str) -> IResult<&str, Path> {
|
/// A single element of a path
|
||||||
map(
|
fn key(i: &str) -> IResult<&str, &str> {
|
||||||
separated_list(
|
recognize(tuple((
|
||||||
tag("."),
|
one_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"),
|
||||||
recognize(tuple((
|
opt(is_a(
|
||||||
one_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"),
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$0123456789-",
|
||||||
opt(is_a(
|
)),
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$0123456789-",
|
)))(i)
|
||||||
)),
|
|
||||||
))),
|
|
||||||
),
|
|
||||||
|body| Path { keys: body },
|
|
||||||
)(i)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A series of keys separated by '.' to reference a variable in the context
|
||||||
|
fn path(i: &str) -> IResult<&str, Path> {
|
||||||
|
map(separated_list(tag("."), key), |body| Path { keys: body })(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Display a value from the context
|
||||||
fn reference(i: &str) -> IResult<&str, Reference> {
|
fn reference(i: &str) -> IResult<&str, Reference> {
|
||||||
let (remaining, (p, filters)) = delimited(tag("{"), tuple((path, many0(filter))), tag("}"))(i)?;
|
let (remaining, (p, filters)) = delimited(tag("{"), tuple((path, many0(filter))), tag("}"))(i)?;
|
||||||
Ok((
|
Ok((
|
||||||
|
Loading…
x
Reference in New Issue
Block a user