templater: make internal parse_template_str() return expression

An "Expression" object is more useful while writing tests.
This commit is contained in:
Yuya Nishihara 2023-02-05 12:30:17 +09:00
parent 5342d2cfb7
commit 16a744fe18

View file

@ -679,13 +679,13 @@ fn parse_template_rule<'a, C: 'a>(
fn parse_template_str<'a, C: 'a>(
template_text: &str,
parse_keyword: impl Fn(Pair<Rule>) -> TemplateParseResult<PropertyAndLabels<'a, C>>,
) -> TemplateParseResult<Box<dyn Template<C> + 'a>> {
) -> TemplateParseResult<Expression<'a, C>> {
let mut pairs: Pairs<Rule> = TemplateParser::parse(Rule::program, template_text)?;
let first_pair = pairs.next().unwrap();
if first_pair.as_rule() == Rule::EOI {
Ok(Box::new(Literal(String::new())))
Ok(Expression::Template(Box::new(Literal(String::new()))))
} else {
parse_template_rule(first_pair, &parse_keyword).map(|x| x.into_template())
parse_template_rule(first_pair, &parse_keyword)
}
}
@ -694,7 +694,8 @@ pub fn parse_commit_template<'a>(
workspace_id: &WorkspaceId,
template_text: &str,
) -> TemplateParseResult<Box<dyn Template<Commit> + 'a>> {
parse_template_str(template_text, |pair| {
let expression = parse_template_str(template_text, |pair| {
parse_commit_keyword(repo, workspace_id, pair)
})
})?;
Ok(expression.into_template())
}