revset: allow trailing comma

It's unlikely we would write multi-line function call in revset, but let's
allow trailing comma for consistency.
This commit is contained in:
Yuya Nishihara 2023-02-07 20:19:31 +09:00
parent 686c1fb522
commit fa045d632c
2 changed files with 32 additions and 2 deletions

View file

@ -48,11 +48,15 @@ infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compa
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
function_arguments = {
(whitespace* ~ expression ~ whitespace* ~ ",")* ~ whitespace* ~ expression ~ whitespace*
whitespace* ~ expression ~ whitespace*
~ ("," ~ whitespace* ~ expression ~ whitespace*)*
~ ("," ~ whitespace*)?
| whitespace*
}
formal_parameters = {
(whitespace* ~ identifier ~ whitespace* ~ ",")* ~ whitespace* ~ identifier ~ whitespace*
whitespace* ~ identifier ~ whitespace*
~ ("," ~ whitespace* ~ identifier ~ whitespace*)*
~ ("," ~ whitespace*)?
| whitespace*
}

View file

@ -2404,6 +2404,32 @@ mod tests {
.minus(&RevsetExpression::visible_heads())
)
);
// Trailing comma isn't allowed for empty argument
assert!(parse("branches(,)").is_err());
// Trailing comma is allowed for the last argument
assert!(parse("branches(a,)").is_ok());
assert!(parse("branches(a , )").is_ok());
assert!(parse("branches(,a)").is_err());
assert!(parse("branches(a,,)").is_err());
assert!(parse("branches(a , , )").is_err());
assert!(parse("file(a,b,)").is_ok());
assert!(parse("file(a,,b)").is_err());
}
#[test]
fn test_parse_revset_alias_formal_parameter() {
let mut aliases_map = RevsetAliasesMap::new();
// Trailing comma isn't allowed for empty parameter
assert!(aliases_map.insert("f(,)", "none()").is_err());
// Trailing comma is allowed for the last parameter
assert!(aliases_map.insert("g(a,)", "none()").is_ok());
assert!(aliases_map.insert("h(a , )", "none()").is_ok());
assert!(aliases_map.insert("i(,a)", "none()").is_err());
assert!(aliases_map.insert("j(a,,)", "none()").is_err());
assert!(aliases_map.insert("k(a , , )", "none()").is_err());
assert!(aliases_map.insert("l(a,b,)", "none()").is_ok());
assert!(aliases_map.insert("m(a,,b)", "none()").is_err());
}
#[test]