revset: move whitespace rule out of expression

There's a subtle difference between
 - 'expression = { whitespace* ... whitespace* }', and
 - '_{ whitespace* ~ expression ~ whitespace* }'.

The former includes surrounding whitespace in an "expression", the latter
doesn't. This affects the span of error indication.
This commit is contained in:
Yuya Nishihara 2023-02-08 18:25:11 +09:00
parent 78227dc7bc
commit b2825c22d7
2 changed files with 11 additions and 14 deletions

View file

@ -48,21 +48,17 @@ infix_op = _{ union_op | intersection_op | difference_op | compat_add_op | compa
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ } function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
function_arguments = { function_arguments = {
whitespace* ~ expression ~ whitespace* expression ~ (whitespace* ~ "," ~ whitespace* ~ expression)* ~ (whitespace* ~ ",")?
~ ("," ~ whitespace* ~ expression ~ whitespace*)* | ""
~ ("," ~ whitespace*)?
| whitespace*
} }
formal_parameters = { formal_parameters = {
whitespace* ~ identifier ~ whitespace* identifier ~ (whitespace* ~ "," ~ whitespace* ~ identifier)* ~ (whitespace* ~ ",")?
~ ("," ~ whitespace* ~ identifier ~ whitespace*)* | ""
~ ("," ~ whitespace*)?
| whitespace*
} }
primary = { primary = {
function_name ~ "(" ~ function_arguments ~ ")" function_name ~ "(" ~ whitespace* ~ function_arguments ~ whitespace* ~ ")"
| "(" ~ expression ~ ")" | "(" ~ whitespace* ~ expression ~ whitespace* ~ ")"
| symbol | symbol
} }
@ -76,14 +72,14 @@ range_expression = _{
} }
expression = { expression = {
whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression ~ whitespace* (negate_op ~ whitespace*)* ~ range_expression
~ (infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression ~ whitespace*)* ~ (whitespace* ~ infix_op ~ whitespace* ~ (negate_op ~ whitespace*)* ~ range_expression)*
} }
program = _{ SOI ~ expression ~ EOI } program = _{ SOI ~ whitespace* ~ expression ~ whitespace* ~ EOI }
alias_declaration_part = _{ alias_declaration_part = _{
function_name ~ "(" ~ formal_parameters ~ ")" function_name ~ "(" ~ whitespace* ~ formal_parameters ~ whitespace* ~ ")"
| identifier | identifier
} }
alias_declaration = _{ alias_declaration = _{

View file

@ -2367,6 +2367,7 @@ mod tests {
assert_eq!(parse("(@)-"), Ok(wc_symbol.parents())); assert_eq!(parse("(@)-"), Ok(wc_symbol.parents()));
// Space is allowed around expressions // Space is allowed around expressions
assert_eq!(parse(" :@ "), Ok(wc_symbol.ancestors())); assert_eq!(parse(" :@ "), Ok(wc_symbol.ancestors()));
assert_eq!(parse("( :@ )"), Ok(wc_symbol.ancestors()));
// Space is not allowed around prefix operators // Space is not allowed around prefix operators
assert_eq!(parse(" : @ "), Err(RevsetParseErrorKind::SyntaxError)); assert_eq!(parse(" : @ "), Err(RevsetParseErrorKind::SyntaxError));
// Incomplete parse // Incomplete parse