diff options
author | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-11-05 00:08:05 +0800 |
---|---|---|
committer | cyqsimon <28627918+cyqsimon@users.noreply.github.com> | 2023-12-11 10:21:04 +0800 |
commit | de6d418d42e078ca8dd4541d9733d99a3541edd6 (patch) | |
tree | fcb38170de43065195865b05b6e5862d8086889a /build | |
parent | c016b462c0ef2cc155db4d8215c9b6b8488fb7e3 (diff) |
Remove `BuiltinMatcher` enum
Explanation added as comments in code
Using plain `Lazy<Option<GlobMatcher>>` is just better
Diffstat (limited to 'build')
-rw-r--r-- | build/syntax_mapping.rs | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/build/syntax_mapping.rs b/build/syntax_mapping.rs index ccbadbd8..cecf8ef5 100644 --- a/build/syntax_mapping.rs +++ b/build/syntax_mapping.rs @@ -41,7 +41,7 @@ impl MappingTarget { #[derive(Clone, Debug, DeserializeFromStr)] /// A single matcher. /// -/// Corresponds to `syntax_mapping::BuiltinMatcher`. +/// Codegen converts this into a `Lazy<GlobMatcher>`. struct Matcher(Vec<MatcherSegment>); /// Parse a matcher. /// @@ -110,13 +110,12 @@ impl Matcher { let MatcherSegment::Text(ref s) = self.0[0] else { unreachable!() }; - format!(r###"BuiltinMatcher::Fixed(r#"{s}"#)"###) + format!(r###"Lazy::new(|| Some(build_matcher_fixed(r#"{s}"#)))"###) } // parser logic ensures that this case can only happen when there are dynamic segments _ => { - let segments_codegen = self.0.iter().map(MatcherSegment::codegen).join(", "); - let closure = format!("|| build_glob_string(&[{segments_codegen}])"); - format!("BuiltinMatcher::Dynamic(Lazy::new({closure}))") + let segs = self.0.iter().map(MatcherSegment::codegen).join(", "); + format!(r###"Lazy::new(|| build_matcher_dynamic(&[{segs}]))"###) } } } @@ -174,7 +173,7 @@ impl MappingList { let len = array_items.len(); format!( - "static BUILTIN_MAPPINGS: [(BuiltinMatcher, MappingTarget); {len}] = [\n{items}\n];", + "static BUILTIN_MAPPINGS: [(Lazy<Option<GlobMatcher>>, MappingTarget); {len}] = [\n{items}\n];", items = array_items.join(",\n") ) } |