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.
This commit is contained in:
Yuya Nishihara 2022-11-16 20:46:53 +09:00
parent f8aa6b1deb
commit 5491b5581f
2 changed files with 11 additions and 5 deletions

View file

@ -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
}

View file

@ -518,7 +518,7 @@ fn parse_range_expression_rule(
) -> Result<Rc<RevsetExpression>, 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)?;