From a5bb48d47ed46e71814299ae6fa4e38f1f09504f Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 29 Jan 2023 12:50:12 +0900 Subject: [PATCH] templater: introduce top-level rule that wraps template terms An epsilon rule will be moved here to disambiguate f() with f(""). --- src/commands/mod.rs | 2 +- src/template.pest | 2 ++ src/template_parser.rs | 12 +----------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 88ac66d82..e64110c26 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2915,7 +2915,7 @@ fn cmd_debug( } DebugCommands::Template(template_matches) => { let parse = TemplateParser::parse( - crate::template_parser::Rule::template, + crate::template_parser::Rule::program, &template_matches.template, ); writeln!(ui, "{parse:#?}")?; diff --git a/src/template.pest b/src/template.pest index 841d91776..70b8d1ac8 100644 --- a/src/template.pest +++ b/src/template.pest @@ -48,3 +48,5 @@ list = _{ template = { whitespace* ~ (list | term | "") ~ whitespace* } + +program = _{ SOI ~ template ~ EOI } diff --git a/src/template_parser.rs b/src/template_parser.rs index e6650aab1..a396c66f7 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -381,17 +381,7 @@ pub fn parse_commit_template<'a>( workspace_id: &WorkspaceId, template_text: &str, ) -> Box + 'a> { - let mut pairs: Pairs = TemplateParser::parse(Rule::template, template_text).unwrap(); - + let mut pairs: Pairs = TemplateParser::parse(Rule::program, template_text).unwrap(); let first_pair = pairs.next().unwrap(); - assert!(pairs.next().is_none()); - - assert_eq!( - first_pair.as_span().end(), - template_text.len(), - "failed to parse template past position {}", - first_pair.as_span().end() - ); - parse_commit_template_rule(repo, workspace_id, first_pair) }