From 45c4734b52ce49dea21d26f0e3a3eeb471c4dce8 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 6 Oct 2022 16:20:16 +0900 Subject: [PATCH] revset: fix parsing of concatenated-identifier in expression Previously an expression 'foo-bar-' failed to parse because 1. try first rule: 'foo-bar-' matches (identifier_part+ ~ '-')+, but the trailing '' doesn't match identifier_part+ 2. fall back to second rule: 'foo' matches identifier_part+ => (identifier 'foo') Instead, we need to consume as much (identifier_part ~ '-' ~ ...) as possible before falling back to the identifier_part rule. I think the trailing + of identifier_part+ is redundant, so removed it as well. --- lib/src/revset.pest | 6 +++--- lib/src/revset.rs | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/revset.pest b/lib/src/revset.pest index 17c208fe6..f96f05c7a 100644 --- a/lib/src/revset.pest +++ b/lib/src/revset.pest @@ -14,9 +14,9 @@ identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ } identifier = @{ - (identifier_part+ ~ ("." | "-" | "+" ))+ ~ identifier_part+ - | identifier_part+ -} + identifier_part ~ ("." | "-" | "+" ) ~ identifier + | identifier_part +} symbol = { identifier | literal_string diff --git a/lib/src/revset.rs b/lib/src/revset.rs index e59e38ee7..f2cb9e37f 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -1516,6 +1516,10 @@ mod tests { parse("foo.bar-v1+7"), Ok(RevsetExpression::symbol("foo.bar-v1+7".to_string())) ); + assert_eq!( + parse("foo.bar-v1+7-"), + Ok(RevsetExpression::symbol("foo.bar-v1+7".to_string()).parents()) + ); // '.' is not allowed at the beginning or end assert_matches!(parse(".foo"), Err(RevsetParseError::SyntaxError(_))); assert_matches!(parse("foo."), Err(RevsetParseError::SyntaxError(_)));