diff --git a/lib/src/revset.pest b/lib/src/revset.pest index a3a74c9b0..074a85ee2 100644 --- a/lib/src/revset.pest +++ b/lib/src/revset.pest @@ -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* } diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 6eeb92126..ed223c7cd 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -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]