mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 00:44:33 +00:00
templater: dispatch global functions through TemplateLanguage trait
Prepares for migrating to table-based lookup. It's unlikely that the implementor handles global function calls differently, but the core doesn't have an access to the customized symbol table.
This commit is contained in:
parent
1e8bf8426c
commit
fa9cb72445
4 changed files with 33 additions and 2 deletions
|
@ -107,6 +107,14 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> {
|
|||
self.wrap_commit(TemplatePropertyFn(|commit: &Commit| Ok(commit.clone())))
|
||||
}
|
||||
|
||||
fn build_function(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
function: &FunctionCallNode,
|
||||
) -> TemplateParseResult<Self::Property> {
|
||||
template_builder::build_global_function(self, build_ctx, function)
|
||||
}
|
||||
|
||||
fn build_method(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
|
|
|
@ -83,6 +83,14 @@ impl<'a, C: 'a> TemplateLanguage<'a> for GenericTemplateLanguage<'a, C> {
|
|||
GenericTemplatePropertyKind::Self_
|
||||
}
|
||||
|
||||
fn build_function(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
function: &FunctionCallNode,
|
||||
) -> TemplateParseResult<Self::Property> {
|
||||
template_builder::build_global_function(self, build_ctx, function)
|
||||
}
|
||||
|
||||
fn build_method(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
|
|
|
@ -59,6 +59,14 @@ impl TemplateLanguage<'static> for OperationTemplateLanguage {
|
|||
self.wrap_operation(TemplatePropertyFn(|op: &Operation| Ok(op.clone())))
|
||||
}
|
||||
|
||||
fn build_function(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
function: &FunctionCallNode,
|
||||
) -> TemplateParseResult<Self::Property> {
|
||||
template_builder::build_global_function(self, build_ctx, function)
|
||||
}
|
||||
|
||||
fn build_method(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
|
|
|
@ -73,6 +73,13 @@ pub trait TemplateLanguage<'a> {
|
|||
/// clones the `Context` object.
|
||||
fn build_self(&self) -> Self::Property;
|
||||
|
||||
/// Translates the given global `function` call to a property.
|
||||
fn build_function(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
function: &FunctionCallNode,
|
||||
) -> TemplateParseResult<Self::Property>;
|
||||
|
||||
fn build_method(
|
||||
&self,
|
||||
build_ctx: &BuildContext<Self::Property>,
|
||||
|
@ -891,7 +898,7 @@ where
|
|||
Ok(language.wrap_list_template(Box::new(list_template)))
|
||||
}
|
||||
|
||||
fn build_global_function<'a, L: TemplateLanguage<'a> + ?Sized>(
|
||||
pub fn build_global_function<'a, L: TemplateLanguage<'a> + ?Sized>(
|
||||
language: &L,
|
||||
build_ctx: &BuildContext<L::Property>,
|
||||
function: &FunctionCallNode,
|
||||
|
@ -1033,7 +1040,7 @@ pub fn build_expression<'a, L: TemplateLanguage<'a> + ?Sized>(
|
|||
Ok(Expression::unlabeled(property))
|
||||
}
|
||||
ExpressionKind::FunctionCall(function) => {
|
||||
let property = build_global_function(language, build_ctx, function)?;
|
||||
let property = language.build_function(build_ctx, function)?;
|
||||
Ok(Expression::unlabeled(property))
|
||||
}
|
||||
ExpressionKind::MethodCall(method) => {
|
||||
|
|
Loading…
Reference in a new issue