forked from mirrors/jj
templater: allow trailing comma
While rewriting the default log template, I find it's annoying that I have to remove "," from the last line.
This commit is contained in:
parent
ba1c4f5fe5
commit
686c1fb522
3 changed files with 20 additions and 2 deletions
|
@ -1449,7 +1449,7 @@ fn log_template(settings: &UserSettings) -> String {
|
||||||
working_copies,
|
working_copies,
|
||||||
git_head,
|
git_head,
|
||||||
commit_id.{prefix_format},
|
commit_id.{prefix_format},
|
||||||
if(conflict, label("conflict", "conflict"))
|
if(conflict, label("conflict", "conflict")),
|
||||||
)
|
)
|
||||||
"\n"
|
"\n"
|
||||||
if(empty, label("empty", "(empty)") " ")
|
if(empty, label("empty", "(empty)") " ")
|
||||||
|
|
|
@ -33,7 +33,7 @@ identifier = @{ (ASCII_ALPHA | "_") ~ (ASCII_ALPHANUMERIC | "_")* }
|
||||||
|
|
||||||
function = { identifier ~ "(" ~ function_arguments ~ ")" }
|
function = { identifier ~ "(" ~ function_arguments ~ ")" }
|
||||||
function_arguments = {
|
function_arguments = {
|
||||||
template ~ ("," ~ template)*
|
template ~ ("," ~ template)* ~ ("," ~ whitespace*)?
|
||||||
| whitespace*
|
| whitespace*
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -789,6 +789,24 @@ mod tests {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_function_call_syntax() {
|
||||||
|
// Trailing comma isn't allowed for empty argument
|
||||||
|
assert!(parse(r#" "".first_line() "#).is_ok());
|
||||||
|
assert!(parse(r#" "".first_line(,) "#).is_err());
|
||||||
|
|
||||||
|
// Trailing comma is allowed for the last argument
|
||||||
|
assert!(parse(r#" "".contains("") "#).is_ok());
|
||||||
|
assert!(parse(r#" "".contains("",) "#).is_ok());
|
||||||
|
assert!(parse(r#" "".contains("" , ) "#).is_ok());
|
||||||
|
assert!(parse(r#" "".contains(,"") "#).is_err());
|
||||||
|
assert!(parse(r#" "".contains("",,) "#).is_err());
|
||||||
|
assert!(parse(r#" "".contains("" , , ) "#).is_err());
|
||||||
|
assert!(parse(r#" label("","") "#).is_ok());
|
||||||
|
assert!(parse(r#" label("","",) "#).is_ok());
|
||||||
|
assert!(parse(r#" label("",,"") "#).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_integer_literal() {
|
fn test_integer_literal() {
|
||||||
let extract = |x: Expression<()>| x.try_into_integer().unwrap().extract(&());
|
let extract = |x: Expression<()>| x.try_into_integer().unwrap().extract(&());
|
||||||
|
|
Loading…
Reference in a new issue