forked from mirrors/jj
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.
This commit is contained in:
parent
18c0b97d9d
commit
45c4734b52
2 changed files with 7 additions and 3 deletions
|
@ -14,9 +14,9 @@
|
||||||
|
|
||||||
identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ }
|
identifier_part = @{ (ASCII_ALPHANUMERIC | "_" | "@" | "/")+ }
|
||||||
identifier = @{
|
identifier = @{
|
||||||
(identifier_part+ ~ ("." | "-" | "+" ))+ ~ identifier_part+
|
identifier_part ~ ("." | "-" | "+" ) ~ identifier
|
||||||
| identifier_part+
|
| identifier_part
|
||||||
}
|
}
|
||||||
symbol = {
|
symbol = {
|
||||||
identifier
|
identifier
|
||||||
| literal_string
|
| literal_string
|
||||||
|
|
|
@ -1516,6 +1516,10 @@ mod tests {
|
||||||
parse("foo.bar-v1+7"),
|
parse("foo.bar-v1+7"),
|
||||||
Ok(RevsetExpression::symbol("foo.bar-v1+7".to_string()))
|
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
|
// '.' is not allowed at the beginning or end
|
||||||
assert_matches!(parse(".foo"), Err(RevsetParseError::SyntaxError(_)));
|
assert_matches!(parse(".foo"), Err(RevsetParseError::SyntaxError(_)));
|
||||||
assert_matches!(parse("foo."), Err(RevsetParseError::SyntaxError(_)));
|
assert_matches!(parse("foo."), Err(RevsetParseError::SyntaxError(_)));
|
||||||
|
|
Loading…
Reference in a new issue