mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-07 13:00:08 +00:00
templater: inline build_method_call()
I don't think this function will grow to unmaintainable size, and I'm going to add global function dispatcher there.
This commit is contained in:
parent
f9f740b263
commit
5ec56fb3e9
1 changed files with 9 additions and 15 deletions
|
@ -18,8 +18,8 @@ use itertools::Itertools as _;
|
|||
use jj_lib::backend::{Signature, Timestamp};
|
||||
|
||||
use crate::template_parser::{
|
||||
self, BinaryOp, ExpressionKind, ExpressionNode, FunctionCallNode, MethodCallNode,
|
||||
TemplateAliasesMap, TemplateParseError, TemplateParseErrorKind, TemplateParseResult, UnaryOp,
|
||||
self, BinaryOp, ExpressionKind, ExpressionNode, FunctionCallNode, TemplateAliasesMap,
|
||||
TemplateParseError, TemplateParseErrorKind, TemplateParseResult, UnaryOp,
|
||||
};
|
||||
use crate::templater::{
|
||||
ConcatTemplate, ConditionalTemplate, IntoTemplate, LabelTemplate, ListPropertyTemplate,
|
||||
|
@ -515,18 +515,6 @@ fn build_binary_operation<'a, L: TemplateLanguage<'a> + ?Sized>(
|
|||
Ok(Expression::unlabeled(property))
|
||||
}
|
||||
|
||||
fn build_method_call<'a, L: TemplateLanguage<'a> + ?Sized>(
|
||||
language: &L,
|
||||
build_ctx: &BuildContext<L::Property>,
|
||||
method: &MethodCallNode,
|
||||
) -> TemplateParseResult<Expression<L::Property>> {
|
||||
let mut expression = build_expression(language, build_ctx, &method.object)?;
|
||||
expression.property =
|
||||
language.build_method(build_ctx, expression.property, &method.function)?;
|
||||
expression.labels.push(method.function.name.to_owned());
|
||||
Ok(expression)
|
||||
}
|
||||
|
||||
fn builtin_string_methods<'a, L: TemplateLanguage<'a> + ?Sized>(
|
||||
) -> TemplateBuildMethodFnMap<'a, L, String> {
|
||||
// Not using maplit::hashmap!{} or custom declarative macro here because
|
||||
|
@ -1047,7 +1035,13 @@ pub fn build_expression<'a, L: TemplateLanguage<'a> + ?Sized>(
|
|||
ExpressionKind::FunctionCall(function) => {
|
||||
build_global_function(language, build_ctx, function)
|
||||
}
|
||||
ExpressionKind::MethodCall(method) => build_method_call(language, build_ctx, method),
|
||||
ExpressionKind::MethodCall(method) => {
|
||||
let mut expression = build_expression(language, build_ctx, &method.object)?;
|
||||
expression.property =
|
||||
language.build_method(build_ctx, expression.property, &method.function)?;
|
||||
expression.labels.push(method.function.name.to_owned());
|
||||
Ok(expression)
|
||||
}
|
||||
ExpressionKind::Lambda(_) => Err(TemplateParseError::unexpected_expression(
|
||||
"Lambda cannot be defined here",
|
||||
node.span,
|
||||
|
|
Loading…
Reference in a new issue