mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-28 15:26:25 +00:00
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:
parent
3361130df4
commit
52df6f2e81
1 changed files with 22 additions and 1 deletions
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue