From 618abf4379ba840f223809747bfd10e612e9a16b Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Wed, 21 Apr 2021 13:42:37 -0700 Subject: [PATCH] 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. --- lib/src/revset.pest | 18 +++++++++--------- lib/src/revset.rs | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/src/revset.pest b/lib/src/revset.pest index e6395a134..f79675c5c 100644 --- a/lib/src/revset.pest +++ b/lib/src/revset.pest @@ -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 = { diff --git a/lib/src/revset.rs b/lib/src/revset.rs index eff9241de..4193183bd 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -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)?, ))), _ => {