Introducing an RValue enum to handle paths vs literals
This commit is contained in:
parent
8641e5a98b
commit
dd8b4ac28c
@ -113,6 +113,12 @@ enum TemplateElement<'a> {
|
|||||||
TETag(DustTag<'a>),
|
TETag(DustTag<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
enum RValue<'a> {
|
||||||
|
RVPath(Path<'a>),
|
||||||
|
RVLiteral(&'a str),
|
||||||
|
}
|
||||||
|
|
||||||
/// Any element significant to dust that isn't plain text
|
/// Any element significant to dust that isn't plain text
|
||||||
///
|
///
|
||||||
/// These elements are always wrapped in curly braces
|
/// These elements are always wrapped in curly braces
|
||||||
@ -168,12 +174,13 @@ fn path(i: &str) -> IResult<&str, Path> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Either a literal or a path to a value
|
/// Either a literal or a path to a value
|
||||||
fn rvalue(i: &str) -> IResult<&str, &str> {
|
fn rvalue(i: &str) -> IResult<&str, RValue> {
|
||||||
key(i)
|
map(path, RValue::RVPath)(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_value_pair(i: &str) -> IResult<&str, (&str, Path)> {
|
/// Parameters for a partial
|
||||||
separated_pair(key, tag("="), path)(i)
|
fn key_value_pair(i: &str) -> IResult<&str, (&str, RValue)> {
|
||||||
|
separated_pair(key, tag("="), rvalue)(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Display a value from the context
|
/// Display a value from the context
|
||||||
@ -681,7 +688,13 @@ mod tests {
|
|||||||
)),
|
)),
|
||||||
tag("/}"),
|
tag("/}"),
|
||||||
)("{>foo bar=baz/}"),
|
)("{>foo bar=baz/}"),
|
||||||
Ok(("", ("foo", Some(vec![("bar", Path { keys: vec!["baz"] })]))))
|
Ok((
|
||||||
|
"",
|
||||||
|
(
|
||||||
|
"foo",
|
||||||
|
Some(vec![("bar", RValue::RVPath(Path { keys: vec!["baz"] }))])
|
||||||
|
)
|
||||||
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user