mirror of
https://github.com/sharkdp/bat
synced 2026-07-23 17:03:18 +00:00
Refactor: string-or-struct matcher syntax, Case enum, remove case_sensitive_mappings table
Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
This commit is contained in:
committed by
Keith Hall
parent
22c38b6fcb
commit
2a29802dd5
@@ -3,7 +3,7 @@ use std::env;
|
||||
use globset::GlobMatcher;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::syntax_mapping::{make_glob_matcher, MappingTarget};
|
||||
use crate::syntax_mapping::{make_glob_matcher, Case, MappingTarget};
|
||||
|
||||
// Static syntax mappings generated from /src/syntax_mapping/builtins/ by the
|
||||
// build script (/build/syntax_mapping.rs).
|
||||
@@ -53,8 +53,8 @@ include!(concat!(
|
||||
/// A failure to compile is a fatal error.
|
||||
///
|
||||
/// Used internally by `Lazy<Option<GlobMatcher>>`'s lazy evaluation closure.
|
||||
fn build_matcher_fixed(from: &str, case_insensitive: bool) -> GlobMatcher {
|
||||
make_glob_matcher(from, case_insensitive)
|
||||
fn build_matcher_fixed(from: &str, case: Case) -> GlobMatcher {
|
||||
make_glob_matcher(from, case)
|
||||
.expect("A builtin fixed glob matcher failed to compile")
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ fn build_matcher_fixed(from: &str, case_insensitive: bool) -> GlobMatcher {
|
||||
/// to compile.
|
||||
///
|
||||
/// Used internally by `Lazy<Option<GlobMatcher>>`'s lazy evaluation closure.
|
||||
fn build_matcher_dynamic(segs: &[MatcherSegment], case_insensitive: bool) -> Option<GlobMatcher> {
|
||||
fn build_matcher_dynamic(segs: &[MatcherSegment], case: Case) -> Option<GlobMatcher> {
|
||||
// join segments
|
||||
let mut buf = String::new();
|
||||
for seg in segs {
|
||||
@@ -78,7 +78,7 @@ fn build_matcher_dynamic(segs: &[MatcherSegment], case_insensitive: bool) -> Opt
|
||||
}
|
||||
}
|
||||
// compile glob matcher
|
||||
let matcher = make_glob_matcher(&buf, case_insensitive).ok()?;
|
||||
let matcher = make_glob_matcher(&buf, case).ok()?;
|
||||
Some(matcher)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
[case_sensitive_mappings]
|
||||
"Python" = ["BUILD"]
|
||||
[mappings]
|
||||
"Python" = [{ glob = "BUILD", case_sensitive = true }]
|
||||
|
||||
Reference in New Issue
Block a user