-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fileset: relax identifier rule to accept more path-like strings
Since fileset is primarily used in CLI, it's better to avoid inner quoting if possible. For example, ".." would have to be quoted in the original grammar derived from the revset. This patch also adds a stricter version of an identifier rule. If we add a symbol alias, it will follow the "strict_identifier" rule.
- Loading branch information
Showing
3 changed files
with
27 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,9 @@ impl Rule { | |
match self { | ||
Rule::EOI => None, | ||
Rule::whitespace => None, | ||
Rule::identifier_part => None, | ||
Rule::identifier => None, | ||
Rule::strict_identifier_part => None, | ||
Rule::strict_identifier => None, | ||
Rule::string_escape => None, | ||
Rule::string_content_char => None, | ||
Rule::string_content => None, | ||
|
@@ -237,7 +238,7 @@ fn parse_primary_node(pair: Pair<Rule>) -> FilesetParseResult<ExpressionNode> { | |
} | ||
Rule::string_pattern => { | ||
let (lhs, op, rhs) = first.into_inner().collect_tuple().unwrap(); | ||
assert_eq!(lhs.as_rule(), Rule::identifier); | ||
assert_eq!(lhs.as_rule(), Rule::strict_identifier); | ||
assert_eq!(op.as_rule(), Rule::pattern_kind_op); | ||
let kind = lhs.as_str(); | ||
let value = match rhs.as_rule() { | ||
|
@@ -399,6 +400,18 @@ mod tests { | |
parse_into_kind("dir/foo-bar_0.baz"), | ||
Ok(ExpressionKind::Identifier("dir/foo-bar_0.baz")) | ||
); | ||
assert_eq!( | ||
parse_into_kind("[email protected]"), | ||
Ok(ExpressionKind::Identifier("[email protected]")) | ||
); | ||
assert_eq!( | ||
parse_into_kind("柔術.jj"), | ||
Ok(ExpressionKind::Identifier("柔術.jj")) | ||
); | ||
assert_eq!( | ||
parse_into_kind(r#"Windows\Path"#), | ||
Ok(ExpressionKind::Identifier(r#"Windows\Path"#)) | ||
); | ||
} | ||
|
||
#[test] | ||
|