diff --git a/src/parser/parser.rs b/src/parser/parser.rs index b4cee94..4241b23 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -113,6 +113,12 @@ enum TemplateElement<'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 /// /// 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 -fn rvalue(i: &str) -> IResult<&str, &str> { - key(i) +fn rvalue(i: &str) -> IResult<&str, RValue> { + map(path, RValue::RVPath)(i) } -fn key_value_pair(i: &str) -> IResult<&str, (&str, Path)> { - separated_pair(key, tag("="), path)(i) +/// Parameters for a partial +fn key_value_pair(i: &str) -> IResult<&str, (&str, RValue)> { + separated_pair(key, tag("="), rvalue)(i) } /// Display a value from the context @@ -681,7 +688,13 @@ mod tests { )), tag("/}"), )("{>foo bar=baz/}"), - Ok(("", ("foo", Some(vec![("bar", Path { keys: vec!["baz"] })])))) + Ok(( + "", + ( + "foo", + Some(vec![("bar", RValue::RVPath(Path { keys: vec!["baz"] }))]) + ) + )) ); } }