diff --git a/src/template.pest b/src/template.pest index 497cd8536..d75d01f51 100644 --- a/src/template.pest +++ b/src/template.pest @@ -53,11 +53,11 @@ term = { primary ~ ("." ~ function)* } -list = _{ +concat = _{ term ~ (whitespace* ~ "++" ~ whitespace* ~ term)+ } -template = { list | term } +template = { concat | term } program = _{ SOI ~ whitespace* ~ template? ~ whitespace* ~ EOI } diff --git a/src/template_parser.rs b/src/template_parser.rs index d805c97ea..151653bf9 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -25,7 +25,7 @@ use pest_derive::Parser; use thiserror::Error; use crate::templater::{ - ConditionalTemplate, IndentTemplate, IntoTemplate, LabelTemplate, ListTemplate, Literal, + ConcatTemplate, ConditionalTemplate, IndentTemplate, IntoTemplate, LabelTemplate, Literal, PlainTextFormattedProperty, SeparateTemplate, Template, TemplateFunction, TemplateProperty, TimestampRange, }; @@ -226,7 +226,7 @@ enum ExpressionKind<'i> { Identifier(&'i str), Integer(i64), String(String), - List(Vec>), + Concat(Vec>), FunctionCall(FunctionCallNode<'i>), MethodCall(MethodCallNode<'i>), /// Identity node to preserve the span in the source template text. @@ -335,7 +335,7 @@ fn parse_template_node(pair: Pair) -> TemplateParseResult if nodes.len() == 1 { Ok(nodes.pop().unwrap()) } else { - Ok(ExpressionNode::new(ExpressionKind::List(nodes), span)) + Ok(ExpressionNode::new(ExpressionKind::Concat(nodes), span)) } } @@ -345,7 +345,7 @@ pub fn parse_template(template_text: &str) -> TemplateParseResult( } ExpressionKind::Integer(_) => Ok(node), ExpressionKind::String(_) => Ok(node), - ExpressionKind::List(nodes) => { - node.kind = ExpressionKind::List(expand_list(nodes, state)?); + ExpressionKind::Concat(nodes) => { + node.kind = ExpressionKind::Concat(expand_list(nodes, state)?); Ok(node) } ExpressionKind::FunctionCall(function) => { @@ -1077,7 +1077,7 @@ fn build_global_function<'a, L: TemplateLanguage<'a>>( .iter() .map(|node| build_expression(language, node).map(|x| x.into_template())) .try_collect()?; - language.wrap_template(ListTemplate(contents)) + language.wrap_template(ConcatTemplate(contents)) } "separate" => { let ([separator_node], content_nodes) = expect_some_arguments(function)?; @@ -1111,12 +1111,12 @@ pub fn build_expression<'a, L: TemplateLanguage<'a>>( let property = language.wrap_string(Literal(value.clone())); Ok(Expression::unlabeled(property)) } - ExpressionKind::List(nodes) => { + ExpressionKind::Concat(nodes) => { let templates = nodes .iter() .map(|node| build_expression(language, node).map(|x| x.into_template())) .try_collect()?; - let property = language.wrap_template(ListTemplate(templates)); + let property = language.wrap_template(ConcatTemplate(templates)); Ok(Expression::unlabeled(property)) } ExpressionKind::FunctionCall(function) => build_global_function(language, function), @@ -1211,7 +1211,7 @@ mod tests { ExpressionKind::Identifier(_) | ExpressionKind::Integer(_) | ExpressionKind::String(_) => node.kind, - ExpressionKind::List(nodes) => ExpressionKind::List(normalize_list(nodes)), + ExpressionKind::Concat(nodes) => ExpressionKind::Concat(normalize_list(nodes)), ExpressionKind::FunctionCall(function) => { ExpressionKind::FunctionCall(normalize_function_call(function)) } diff --git a/src/templater.rs b/src/templater.rs index 7c7bef063..a0b73f024 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -182,9 +182,9 @@ where } } -pub struct ListTemplate(pub Vec); +pub struct ConcatTemplate(pub Vec); -impl> Template for ListTemplate { +impl> Template for ConcatTemplate { fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()> { for template in &self.0 { template.format(context, formatter)? @@ -193,7 +193,7 @@ impl> Template for ListTemplate { } } -/// Like `ListTemplate`, but inserts a separator between non-empty templates. +/// Like `ConcatTemplate`, but inserts a separator between non-empty templates. pub struct SeparateTemplate { separator: S, contents: Vec,