diff --git a/js/test_cases/reference_parameters/input1.json b/js/test_cases/reference_parameters/input1.json index 0110e76..3c704cd 100644 --- a/js/test_cases/reference_parameters/input1.json +++ b/js/test_cases/reference_parameters/input1.json @@ -11,5 +11,13 @@ { "petname": "spot" } + ], + "array_petname": [ + { + "petname": [ + "foo", + "bar" + ] + } ] } diff --git a/js/test_cases/reference_parameters/main.dust b/js/test_cases/reference_parameters/main.dust index 7683af4..ea47d31 100644 --- a/js/test_cases/reference_parameters/main.dust +++ b/js/test_cases/reference_parameters/main.dust @@ -6,6 +6,22 @@ Hello {name}, nice {pet}{~n} Hello {name}, nice {pet}{~n} {/people} +Direct Parameters{~n} +================={~n} +{#people name="chris" pet=petname petname="whiskers"} + Hello {name}, nice {pet}{~n} +{/people} +{#people} + {#truthy name="chris" pet=petname petname="whiskers"} + Hello {name}, nice {pet}{~n} + {/truthy} +{/people} +{#people name="chris" pet=petname petname="whiskers"} + {#other_petname} + Hello {name}, nice {pet}{~n} + {/other_petname} +{/people} + Reference Parameters{~n} ===================={~n} {#people name="chris" pet="{petname}" petname="whiskers"} @@ -33,20 +49,3 @@ Reference Parameters{~n} Hello {name}, nice {pet}{~n} {/other_petname} {/people} - - -Direct Parameters{~n} -================={~n} -{#people name="chris" pet=petname petname="whiskers"} - Hello {name}, nice {pet}{~n} -{/people} -{#people} - {#truthy name="chris" pet=petname petname="whiskers"} - Hello {name}, nice {pet}{~n} - {/truthy} -{/people} -{#people name="chris" pet=petname petname="whiskers"} - {#other_petname} - Hello {name}, nice {pet}{~n} - {/other_petname} -{/people} diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 3e0696a..e134642 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -110,13 +110,14 @@ pub struct Partial<'a> { #[derive(Clone, Debug, PartialEq)] pub enum OwnedLiteral { - LString(String), LPositiveInteger(u64), + LString(String), } #[derive(Clone, Debug, PartialEq)] pub enum RValue<'a> { RVPath(Path<'a>), + // RVTemplate(Vec), RVLiteral(OwnedLiteral), } @@ -308,6 +309,20 @@ fn postitive_integer_literal(i: &str) -> IResult<&str, u64> { )(i) } +fn template_string_rvalue(i: &str) -> IResult<&str, Vec> { + let (i, template_string) = verify(quoted_string, |s: &String| { + partial_quoted_tag(s.as_str()).is_ok() + })(i)?; + + let (_remaining, parsed_template_elements) = partial_quoted_tag(template_string.as_str()) + .expect("A successful parse was verified earlier with a call to verify()"); + let converted_template_elements = parsed_template_elements + .into_iter() + .map(|e| e.into()) + .collect(); + Ok((i, converted_template_elements)) +} + /// Either a literal or a path to a value fn rvalue(i: &str) -> IResult<&str, RValue> { alt(( @@ -528,9 +543,7 @@ fn partial_with_quoted_tag<'a>( let (i, (name, maybe_explicit_context, params)) = delimited( tag(open_matcher), tuple(( - verify(quoted_string, |s: &String| { - partial_quoted_tag(s.as_str()).is_ok() - }), + template_string_rvalue, opt(preceded(tag(":"), path)), opt(delimited( space1, @@ -541,17 +554,10 @@ fn partial_with_quoted_tag<'a>( tag("/}"), )(i)?; - let (_remaining, template_name_elements) = partial_quoted_tag(name.as_str()) - .expect("A successful parse was verified earlier with a call to verify()"); - let partial_name_elements = template_name_elements - .into_iter() - .map(|e| e.into()) - .collect(); - Ok(( i, Partial { - name: partial_name_elements, + name: name, explicit_context: maybe_explicit_context, params: params.unwrap_or(Vec::new()), },