diff --git a/lib/src/revset.pest b/lib/src/revset.pest index 074a85ee2..810e1945c 100644 --- a/lib/src/revset.pest +++ b/lib/src/revset.pest @@ -48,21 +48,17 @@ 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*)? - | whitespace* + expression ~ (whitespace* ~ "," ~ whitespace* ~ expression)* ~ (whitespace* ~ ",")? + | "" } formal_parameters = { - whitespace* ~ identifier ~ whitespace* - ~ ("," ~ whitespace* ~ identifier ~ whitespace*)* - ~ ("," ~ whitespace*)? - | whitespace* + identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")? + | "" } primary = { - function_name ~ "(" ~ function_arguments ~ ")" - | "(" ~ expression ~ ")" + function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")" + | "(" ~ whitespace* ~ expression ~ whitespace* ~ ")" | symbol } @@ -76,14 +72,14 @@ range_expression = _{ } expression = { - whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression ~ whitespace* - ~ (infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression ~ whitespace*)* + (negate_op ~ whitespace*)* ~ range_expression + ~ (whitespace* ~ infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression)* } -program = _{ SOI ~ expression ~ EOI } +program = _{ SOI ~ whitespace* ~ expression ~ whitespace* ~ EOI } alias_declaration_part = _{ - function_name ~ "(" ~ formal_parameters ~ ")" + function_name ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")" | identifier } alias_declaration = _{ diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 6d6e56c9a..dc02ce52c 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -2367,6 +2367,7 @@ mod tests { assert_eq!(parse("(@)-"), Ok(wc_symbol.parents())); // Space is allowed around expressions assert_eq!(parse(" :@ "), Ok(wc_symbol.ancestors())); + assert_eq!(parse("( :@ )"), Ok(wc_symbol.ancestors())); // Space is not allowed around prefix operators assert_eq!(parse(" : @ "), Err(RevsetParseErrorKind::SyntaxError)); // Incomplete parse