Relax syntax mapping rule restrictions to allow brace expansion

This commit is contained in:
cyqsimon 2024-02-20 14:24:51 +08:00
parent 1b9fc1d5af
commit 75cdabaf13
No known key found for this signature in database
GPG Key ID: 1D8CE2F297390D65

View File

@ -53,14 +53,16 @@ struct Matcher(Vec<MatcherSegment>);
/// ///
/// Note that this implementation is rather strict: it will greedily interpret /// Note that this implementation is rather strict: it will greedily interpret
/// every valid environment variable replacement as such, then immediately /// every valid environment variable replacement as such, then immediately
/// hard-error if it finds a '$', '{', or '}' anywhere in the remaining text /// hard-error if it finds a '$' anywhere in the remaining text segments.
/// segments.
/// ///
/// The reason for this strictness is I currently cannot think of a valid reason /// The reason for this strictness is I currently cannot think of a valid reason
/// why you would ever need '$', '{', or '}' as plaintext in a glob pattern. /// why you would ever need '$' as plaintext in a glob pattern. Therefore any
/// Therefore any such occurrences are likely human errors. /// such occurrences are likely human errors.
/// ///
/// If we later discover some edge cases, it's okay to make it more permissive. /// If we later discover some edge cases, it's okay to make it more permissive.
///
/// Revision history:
/// - 2024-02-20: allow `{` and `}` (glob brace expansion)
impl FromStr for Matcher { impl FromStr for Matcher {
type Err = anyhow::Error; type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
@ -106,7 +108,7 @@ impl FromStr for Matcher {
if non_empty_segments if non_empty_segments
.iter() .iter()
.filter_map(Seg::text) .filter_map(Seg::text)
.any(|t| t.contains(['$', '{', '}'])) .any(|t| t.contains('$'))
{ {
bail!(r#"Invalid matcher: "{s}""#); bail!(r#"Invalid matcher: "{s}""#);
} }