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.
This commit is contained in:
Yuya Nishihara 2023-02-17 21:26:07 +09:00
parent 3361130df4
commit 52df6f2e81

View file

@ -591,6 +591,11 @@ trait TemplateLanguage<'a> {
name: &str,
span: pest::Span,
) -> TemplateParseResult<Property<'a, Self::Context>>;
fn build_method(
&self,
property: Property<'a, Self::Context>,
function: &FunctionCallNode,
) -> TemplateParseResult<Property<'a, Self::Context>>;
}
enum Property<'a, I> {
@ -760,7 +765,7 @@ fn build_method_call<'a, L: TemplateLanguage<'a>>(
) -> TemplateParseResult<Expression<'a, L::Context>> {
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<Property<'a, Self::Context>> {
build_commit_keyword(self, name, span)
}
fn build_method(
&self,
property: Property<'a, Self::Context>,
function: &FunctionCallNode,
) -> TemplateParseResult<Property<'a, Self::Context>> {
build_core_method(self, property, function)
}
}
pub fn parse_commit_template<'a>(
@ -1158,6 +1171,14 @@ mod tests {
) -> TemplateParseResult<Property<'static, Self::Context>> {
Err(TemplateParseError::no_such_keyword(name, span))
}
fn build_method(
&self,
property: Property<'static, Self::Context>,
function: &FunctionCallNode,
) -> TemplateParseResult<Property<'static, Self::Context>> {
build_core_method(self, property, function)
}
}
#[derive(Debug)]