forked from mirrors/jj
templater: add helper function that does parse() + build()
This could be a provided method of the TemplateLanguage trait, but it's unlikely that this method would have to be customized by implementors. And I'm going to add thin wrapper method to CommandHelper, so no users would write language.parse(..) anyway.
This commit is contained in:
parent
26cce214cb
commit
e1669f08fa
3 changed files with 14 additions and 9 deletions
|
@ -859,7 +859,5 @@ pub fn parse<'repo>(
|
|||
build_fn_table,
|
||||
keyword_cache: CommitKeywordCache::default(),
|
||||
};
|
||||
let node = template_parser::parse(template_text, aliases_map)?;
|
||||
template_builder::build(&language, &node)
|
||||
.map_err(|err| err.extend_alias_candidates(aliases_map))
|
||||
template_builder::parse(&language, template_text, aliases_map)
|
||||
}
|
||||
|
|
|
@ -261,7 +261,5 @@ pub fn parse(
|
|||
current_op_id: current_op_id.cloned(),
|
||||
build_fn_table: OperationTemplateBuildFnTable::builtin(),
|
||||
};
|
||||
let node = template_parser::parse(template_text, aliases_map)?;
|
||||
template_builder::build(&language, &node)
|
||||
.map_err(|err| err.extend_alias_candidates(aliases_map))
|
||||
template_builder::parse(&language, template_text, aliases_map)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ use jj_lib::backend::{Signature, Timestamp};
|
|||
|
||||
use crate::template_parser::{
|
||||
self, BinaryOp, ExpressionKind, ExpressionNode, FunctionCallNode, MethodCallNode,
|
||||
TemplateParseError, TemplateParseErrorKind, TemplateParseResult, UnaryOp,
|
||||
TemplateAliasesMap, TemplateParseError, TemplateParseErrorKind, TemplateParseResult, UnaryOp,
|
||||
};
|
||||
use crate::templater::{
|
||||
ConcatTemplate, ConditionalTemplate, IntoTemplate, LabelTemplate, ListPropertyTemplate,
|
||||
|
@ -1064,6 +1064,16 @@ pub fn build<'a, L: TemplateLanguage<'a> + ?Sized>(
|
|||
expect_template_expression(language, &build_ctx, node)
|
||||
}
|
||||
|
||||
/// Parses text, expands aliases, then builds template evaluation tree.
|
||||
pub fn parse<'a, L: TemplateLanguage<'a> + ?Sized>(
|
||||
language: &L,
|
||||
template_text: &str,
|
||||
aliases_map: &TemplateAliasesMap,
|
||||
) -> TemplateParseResult<Box<dyn Template<L::Context> + 'a>> {
|
||||
let node = template_parser::parse(template_text, aliases_map)?;
|
||||
build(language, &node).map_err(|err| err.extend_alias_candidates(aliases_map))
|
||||
}
|
||||
|
||||
pub fn expect_boolean_expression<'a, L: TemplateLanguage<'a> + ?Sized>(
|
||||
language: &L,
|
||||
build_ctx: &BuildContext<L::Property>,
|
||||
|
@ -1253,8 +1263,7 @@ mod tests {
|
|||
}
|
||||
|
||||
fn parse(&self, template: &str) -> TemplateParseResult<Box<dyn Template<()>>> {
|
||||
let node = template_parser::parse(template, &self.aliases_map)?;
|
||||
build(&self.language, &node)
|
||||
parse(&self.language, template, &self.aliases_map)
|
||||
}
|
||||
|
||||
fn parse_err(&self, template: &str) -> String {
|
||||
|
|
Loading…
Reference in a new issue