From 5491b5581f9bb26c33e3f432c58b71b3cc401216 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 16 Nov 2022 20:46:53 +0900 Subject: [PATCH] revset: decouple prefix/infix/postfix range operators This unblocks the use of PrattParser, which builds an operator map keyed solely by Rule, not by (Rule, prefix/infix/postfix) pair. --- lib/src/revset.pest | 10 ++++++++-- lib/src/revset.rs | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/src/revset.pest b/lib/src/revset.pest index 369f2c69b..f0081938a 100644 --- a/lib/src/revset.pest +++ b/lib/src/revset.pest @@ -28,8 +28,14 @@ parents_op = { "-" } children_op = { "+" } dag_range_op = { ":" } +dag_range_pre_op = { ":" } +dag_range_post_op = { ":" } range_op = { ".." } +range_pre_op = { ".." } +range_post_op = { ".." } range_ops = _{ dag_range_op | range_op } +range_pre_ops = _{ dag_range_pre_op | range_pre_op } +range_post_ops = _{ dag_range_post_op | range_post_op } union_op = { "|" } intersection_op = { "&" } @@ -52,8 +58,8 @@ neighbors_expression = { primary ~ (parents_op | children_op)* } range_expression = { neighbors_expression ~ range_ops ~ neighbors_expression - | neighbors_expression ~ range_ops - | range_ops ~ neighbors_expression + | neighbors_expression ~ range_post_ops + | range_pre_ops ~ neighbors_expression | neighbors_expression } diff --git a/lib/src/revset.rs b/lib/src/revset.rs index 8e6791293..7fbe7fcb8 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -518,7 +518,7 @@ fn parse_range_expression_rule( ) -> Result, RevsetParseError> { let first = pairs.next().unwrap(); match first.as_rule() { - Rule::dag_range_op | Rule::range_op => { + Rule::dag_range_pre_op | Rule::range_pre_op => { return Ok(parse_neighbors_expression_rule( pairs.next().unwrap().into_inner(), workspace_ctx, @@ -535,7 +535,7 @@ fn parse_range_expression_rule( let mut expression = parse_neighbors_expression_rule(first.into_inner(), workspace_ctx)?; if let Some(next) = pairs.next() { match next.as_rule() { - Rule::dag_range_op => { + Rule::dag_range_op | Rule::dag_range_post_op => { if let Some(heads_pair) = pairs.next() { let heads_expression = parse_neighbors_expression_rule(heads_pair.into_inner(), workspace_ctx)?; @@ -544,7 +544,7 @@ fn parse_range_expression_rule( expression = expression.descendants(); } } - Rule::range_op => { + Rule::range_op | Rule::range_post_op => { if let Some(heads_pair) = pairs.next() { let heads_expression = parse_neighbors_expression_rule(heads_pair.into_inner(), workspace_ctx)?;