From 16a744fe18806d5f9fd76cae60eded1476710503 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 5 Feb 2023 12:30:17 +0900 Subject: [PATCH] templater: make internal parse_template_str() return expression An "Expression" object is more useful while writing tests. --- src/template_parser.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/template_parser.rs b/src/template_parser.rs index 6679f5883..7d6844b46 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -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) -> TemplateParseResult>, -) -> TemplateParseResult + 'a>> { +) -> TemplateParseResult> { let mut pairs: Pairs = 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 + '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()) }