mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-28 15:34:22 +00:00
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:
parent
78227dc7bc
commit
b2825c22d7
2 changed files with 11 additions and 14 deletions
|
@ -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 = _{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue