diff --git a/cli/src/commit_templater.rs b/cli/src/commit_templater.rs index 5d6b4b367..b9f5b5ecc 100644 --- a/cli/src/commit_templater.rs +++ b/cli/src/commit_templater.rs @@ -68,7 +68,7 @@ impl<'repo> TemplateLanguage<'repo> for CommitTemplateLanguage<'repo> { match property { CommitTemplatePropertyKind::Core(property) => { let table = &self.build_fn_table.core; - template_builder::build_core_method(self, table, build_ctx, property, function) + table.build_method(self, build_ctx, property, function) } CommitTemplatePropertyKind::Commit(property) => { let table = &self.build_fn_table.commit_methods; diff --git a/cli/src/operation_templater.rs b/cli/src/operation_templater.rs index e666543b7..7bd1d626d 100644 --- a/cli/src/operation_templater.rs +++ b/cli/src/operation_templater.rs @@ -56,7 +56,7 @@ impl TemplateLanguage<'static> for OperationTemplateLanguage { match property { OperationTemplatePropertyKind::Core(property) => { let table = &self.build_fn_table.core; - template_builder::build_core_method(self, table, build_ctx, property, function) + table.build_method(self, build_ctx, property, function) } OperationTemplatePropertyKind::Operation(property) => { let table = &self.build_fn_table.operation_methods; diff --git a/cli/src/template_builder.rs b/cli/src/template_builder.rs index 0a387366f..809ba8a0c 100644 --- a/cli/src/template_builder.rs +++ b/cli/src/template_builder.rs @@ -254,6 +254,63 @@ impl<'a, L: TemplateLanguage<'a>> CoreTemplateBuildFnTable<'a, L> { timestamp_range_methods: builtin_timestamp_range_methods(), } } + + /// Applies the method call node `function` to the given `property` by using + /// this symbol table. + pub fn build_method( + &self, + language: &L, + build_ctx: &BuildContext, + property: CoreTemplatePropertyKind<'a, L::Context>, + function: &FunctionCallNode, + ) -> TemplateParseResult { + match property { + CoreTemplatePropertyKind::String(property) => { + let table = &self.string_methods; + let build = template_parser::lookup_method("String", table, function)?; + build(language, build_ctx, property, function) + } + CoreTemplatePropertyKind::StringList(property) => { + // TODO: migrate to table? + build_formattable_list_method(language, build_ctx, property, function, |item| { + language.wrap_string(item) + }) + } + CoreTemplatePropertyKind::Boolean(property) => { + let table = &self.boolean_methods; + let build = template_parser::lookup_method("Boolean", table, function)?; + build(language, build_ctx, property, function) + } + CoreTemplatePropertyKind::Integer(property) => { + let table = &self.integer_methods; + let build = template_parser::lookup_method("Integer", table, function)?; + build(language, build_ctx, property, function) + } + CoreTemplatePropertyKind::Signature(property) => { + let table = &self.signature_methods; + let build = template_parser::lookup_method("Signature", table, function)?; + build(language, build_ctx, property, function) + } + CoreTemplatePropertyKind::Timestamp(property) => { + let table = &self.timestamp_methods; + let build = template_parser::lookup_method("Timestamp", table, function)?; + build(language, build_ctx, property, function) + } + CoreTemplatePropertyKind::TimestampRange(property) => { + let table = &self.timestamp_range_methods; + let build = template_parser::lookup_method("TimestampRange", table, function)?; + build(language, build_ctx, property, function) + } + CoreTemplatePropertyKind::Template(_) => { + // TODO: migrate to table? + Err(TemplateParseError::no_such_method("Template", function)) + } + CoreTemplatePropertyKind::ListTemplate(template) => { + // TODO: migrate to table? + build_list_template_method(language, build_ctx, template, function) + } + } + } } /// Opaque struct that represents a template value. @@ -396,61 +453,6 @@ fn build_method_call<'a, L: TemplateLanguage<'a>>( Ok(expression) } -pub fn build_core_method<'a, L: TemplateLanguage<'a>>( - language: &L, - build_fn_table: &CoreTemplateBuildFnTable<'a, L>, - build_ctx: &BuildContext, - property: CoreTemplatePropertyKind<'a, L::Context>, - function: &FunctionCallNode, -) -> TemplateParseResult { - match property { - CoreTemplatePropertyKind::String(property) => { - let table = &build_fn_table.string_methods; - let build = template_parser::lookup_method("String", table, function)?; - build(language, build_ctx, property, function) - } - CoreTemplatePropertyKind::StringList(property) => { - // TODO: migrate to table? - build_formattable_list_method(language, build_ctx, property, function, |item| { - language.wrap_string(item) - }) - } - CoreTemplatePropertyKind::Boolean(property) => { - let table = &build_fn_table.boolean_methods; - let build = template_parser::lookup_method("Boolean", table, function)?; - build(language, build_ctx, property, function) - } - CoreTemplatePropertyKind::Integer(property) => { - let table = &build_fn_table.integer_methods; - let build = template_parser::lookup_method("Integer", table, function)?; - build(language, build_ctx, property, function) - } - CoreTemplatePropertyKind::Signature(property) => { - let table = &build_fn_table.signature_methods; - let build = template_parser::lookup_method("Signature", table, function)?; - build(language, build_ctx, property, function) - } - CoreTemplatePropertyKind::Timestamp(property) => { - let table = &build_fn_table.timestamp_methods; - let build = template_parser::lookup_method("Timestamp", table, function)?; - build(language, build_ctx, property, function) - } - CoreTemplatePropertyKind::TimestampRange(property) => { - let table = &build_fn_table.timestamp_range_methods; - let build = template_parser::lookup_method("TimestampRange", table, function)?; - build(language, build_ctx, property, function) - } - CoreTemplatePropertyKind::Template(_) => { - // TODO: migrate to table? - Err(TemplateParseError::no_such_method("Template", function)) - } - CoreTemplatePropertyKind::ListTemplate(template) => { - // TODO: migrate to table? - build_list_template_method(language, build_ctx, template, function) - } - } -} - fn builtin_string_methods<'a, L: TemplateLanguage<'a>>() -> TemplateBuildMethodFnMap<'a, L, String> { // Not using maplit::hashmap!{} or custom declarative macro here because @@ -1051,7 +1053,7 @@ mod tests { match property { TestTemplatePropertyKind::Core(property) => { let table = &self.build_fn_table; - build_core_method(self, table, build_ctx, property, function) + table.build_method(self, build_ctx, property, function) } TestTemplatePropertyKind::Unit => { let build = self