diff --git a/src/template.pest b/src/template.pest index 70b8d1ac8..abd231e9f 100644 --- a/src/template.pest +++ b/src/template.pest @@ -29,6 +29,7 @@ identifier = @{ (ASCII_ALPHANUMERIC | "_")+ } function = { identifier ~ "(" ~ function_arguments ~ ")" } function_arguments = { template ~ ("," ~ template)* + | whitespace* } maybe_method = { ("." ~ function)* } @@ -46,7 +47,7 @@ list = _{ } template = { - whitespace* ~ (list | term | "") ~ whitespace* + whitespace* ~ (list | term) ~ whitespace* } -program = _{ SOI ~ template ~ EOI } +program = _{ SOI ~ (template | whitespace*) ~ EOI } diff --git a/src/template_parser.rs b/src/template_parser.rs index a396c66f7..a2c8a89ab 100644 --- a/src/template_parser.rs +++ b/src/template_parser.rs @@ -369,10 +369,10 @@ fn parse_commit_template_rule<'a>( let mut templates = inner .map(|term| parse_commit_term(repo, workspace_id, term)) .collect_vec(); - match templates.len() { - 0 => Box::new(Literal(String::new())), - 1 => templates.pop().unwrap(), - _ => Box::new(ListTemplate(templates)), + if templates.len() == 1 { + templates.pop().unwrap() + } else { + Box::new(ListTemplate(templates)) } } @@ -383,5 +383,9 @@ pub fn parse_commit_template<'a>( ) -> Box + 'a> { let mut pairs: Pairs = TemplateParser::parse(Rule::program, template_text).unwrap(); let first_pair = pairs.next().unwrap(); - parse_commit_template_rule(repo, workspace_id, first_pair) + if first_pair.as_rule() == Rule::EOI { + Box::new(Literal(String::new())) + } else { + parse_commit_template_rule(repo, workspace_id, first_pair) + } }