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>),
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
alt((
|
||||
map(special, DustTag::DTSpecial),
|
||||
@ -102,6 +105,7 @@ fn dust_tag(i: &str) -> IResult<&str, DustTag> {
|
||||
))(i)
|
||||
}
|
||||
|
||||
/// Special characters
|
||||
fn special(i: &str) -> IResult<&str, Special> {
|
||||
delimited(
|
||||
tag("{~"),
|
||||
@ -116,27 +120,29 @@ fn special(i: &str) -> IResult<&str, Special> {
|
||||
)(i)
|
||||
}
|
||||
|
||||
/// Part of a dust template that does not get rendered
|
||||
fn comment(i: &str) -> IResult<&str, Comment> {
|
||||
map(delimited(tag("{!"), take_until("!}"), tag("!}")), |body| {
|
||||
Comment { value: body }
|
||||
})(i)
|
||||
}
|
||||
|
||||
fn path(i: &str) -> IResult<&str, Path> {
|
||||
map(
|
||||
separated_list(
|
||||
tag("."),
|
||||
recognize(tuple((
|
||||
one_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"),
|
||||
opt(is_a(
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$0123456789-",
|
||||
)),
|
||||
))),
|
||||
),
|
||||
|body| Path { keys: body },
|
||||
)(i)
|
||||
/// A single element of a path
|
||||
fn key(i: &str) -> IResult<&str, &str> {
|
||||
recognize(tuple((
|
||||
one_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$"),
|
||||
opt(is_a(
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$0123456789-",
|
||||
)),
|
||||
)))(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> {
|
||||
let (remaining, (p, filters)) = delimited(tag("{"), tuple((path, many0(filter))), tag("}"))(i)?;
|
||||
Ok((
|
||||
|
Loading…
x
Reference in New Issue
Block a user