forked from mirrors/jj
revsets: use consistent "_op" suffix for operator rules in the grammar
This is especially important now that we leak the rule names into the `SyntaxError` message. For example, the error message when doing `jj diff -r :` will now mention "expected parents_op, ancestors_op, or primary". It seems much clearer with the "_op" suffixes there. Longer term, we should think more about how we can best surface syntax errors from the library crate.
This commit is contained in:
parent
a4ef42962c
commit
618abf4379
2 changed files with 14 additions and 14 deletions
|
@ -16,14 +16,14 @@ symbol = @{ (ASCII_ALPHANUMERIC | "@" | "/" | ".")+ }
|
|||
literal_string = { "\"" ~ (!"\"" ~ ANY)+ ~ "\"" }
|
||||
whitespace = _{ " " }
|
||||
|
||||
parents = { ":" }
|
||||
ancestors = { "*:" }
|
||||
prefix_operator = _{ parents | ancestors }
|
||||
parents_op = { ":" }
|
||||
ancestors_op = { "*:" }
|
||||
prefix_op = _{ parents_op | ancestors_op }
|
||||
|
||||
union = { "|" }
|
||||
intersection = { "&" }
|
||||
difference = { "-" }
|
||||
infix_operator = _{ union| intersection | difference }
|
||||
union_op = { "|" }
|
||||
intersection_op = { "&" }
|
||||
difference_op = { "-" }
|
||||
infix_op = _{ union_op | intersection_op | difference_op }
|
||||
|
||||
function_name = @{ (ASCII_ALPHANUMERIC | "_")+ }
|
||||
// The grammar accepts a string literal or an expression for function
|
||||
|
@ -48,10 +48,10 @@ primary = {
|
|||
| symbol
|
||||
}
|
||||
|
||||
prefix_expression = { prefix_operator* ~ primary }
|
||||
prefix_expression = { prefix_op* ~ primary }
|
||||
|
||||
infix_expression = {
|
||||
whitespace* ~ prefix_expression ~ whitespace* ~ (infix_operator ~ whitespace* ~ prefix_expression ~ whitespace*)*
|
||||
whitespace* ~ prefix_expression ~ whitespace* ~ (infix_op ~ whitespace* ~ prefix_expression ~ whitespace*)*
|
||||
}
|
||||
|
||||
expression = {
|
||||
|
|
|
@ -136,14 +136,14 @@ fn parse_infix_expression_rule(
|
|||
while let Some(operator) = pairs.next() {
|
||||
let expression2 = parse_prefix_expression_rule(pairs.next().unwrap().into_inner())?;
|
||||
match operator.as_rule() {
|
||||
Rule::union => {
|
||||
Rule::union_op => {
|
||||
expression1 = RevsetExpression::Union(Box::new(expression1), Box::new(expression2))
|
||||
}
|
||||
Rule::intersection => {
|
||||
Rule::intersection_op => {
|
||||
expression1 =
|
||||
RevsetExpression::Intersection(Box::new(expression1), Box::new(expression2))
|
||||
}
|
||||
Rule::difference => {
|
||||
Rule::difference_op => {
|
||||
expression1 =
|
||||
RevsetExpression::Difference(Box::new(expression1), Box::new(expression2))
|
||||
}
|
||||
|
@ -164,10 +164,10 @@ fn parse_prefix_expression_rule(
|
|||
let first = pairs.next().unwrap();
|
||||
match first.as_rule() {
|
||||
Rule::primary => parse_primary_rule(first.into_inner()),
|
||||
Rule::parents => Ok(RevsetExpression::Parents(Box::new(
|
||||
Rule::parents_op => Ok(RevsetExpression::Parents(Box::new(
|
||||
parse_prefix_expression_rule(pairs)?,
|
||||
))),
|
||||
Rule::ancestors => Ok(RevsetExpression::Ancestors(Box::new(
|
||||
Rule::ancestors_op => Ok(RevsetExpression::Ancestors(Box::new(
|
||||
parse_prefix_expression_rule(pairs)?,
|
||||
))),
|
||||
_ => {
|
||||
|
|
Loading…
Reference in a new issue