From 52df6f2e8175045daf34a50673a11a5e39484f04 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 17 Feb 2023 21:26:07 +0900 Subject: [PATCH] templater: proxy build_core_method() through language trait The "core" template parser wouldn't know how to dispatch property of types added by a derived language. For example, CommitOrChangeId/ShortestIdPrefix will be moved to the "commit" templater. --- src/template_parser.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/template_parser.rs b/src/template_parser.rs index 2481bd0d4..943a1d0de 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -591,6 +591,11 @@ trait TemplateLanguage<'a> { name: &str, span: pest::Span, ) -> TemplateParseResult>; + fn build_method( + &self, + property: Property<'a, Self::Context>, + function: &FunctionCallNode, + ) -> TemplateParseResult>; } enum Property<'a, I> { @@ -760,7 +765,7 @@ fn build_method_call<'a, L: TemplateLanguage<'a>>( ) -> TemplateParseResult> { match build_expression(language, &method.object)? { Expression::Property(property, mut labels) => { - let property = build_core_method(language, property, &method.function)?; + let property = language.build_method(property, &method.function)?; labels.push(method.function.name.to_owned()); Ok(Expression::Property(property, labels)) } @@ -1127,6 +1132,14 @@ impl<'a> TemplateLanguage<'a> for CommitTemplateLanguage<'a, '_> { ) -> TemplateParseResult> { build_commit_keyword(self, name, span) } + + fn build_method( + &self, + property: Property<'a, Self::Context>, + function: &FunctionCallNode, + ) -> TemplateParseResult> { + build_core_method(self, property, function) + } } pub fn parse_commit_template<'a>( @@ -1158,6 +1171,14 @@ mod tests { ) -> TemplateParseResult> { Err(TemplateParseError::no_such_keyword(name, span)) } + + fn build_method( + &self, + property: Property<'static, Self::Context>, + function: &FunctionCallNode, + ) -> TemplateParseResult> { + build_core_method(self, property, function) + } } #[derive(Debug)]