From 748c14588cf1c31c8b8d60a9c94349c0173ef607 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 28 Jun 2026 09:06:08 +0800 Subject: feat(pathf): add build-time type path resolution system Add `mingling_pathf` sub-crate and `pathf` feature for automatic resolution of Mingling type module paths at build time. Scans source files, identifies macro invocations via pattern matchers, and generates mapping files consumed by `gen_program!()`. --- mingling_pathf/src/pattern_analyzer.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'mingling_pathf/src/pattern_analyzer.rs') diff --git a/mingling_pathf/src/pattern_analyzer.rs b/mingling_pathf/src/pattern_analyzer.rs index cb98a5f..4a1f8a4 100644 --- a/mingling_pathf/src/pattern_analyzer.rs +++ b/mingling_pathf/src/pattern_analyzer.rs @@ -16,6 +16,15 @@ pub fn init() -> PatternAnalyzer { __register![ BasicStructPattern, + PackPattern, + GroupPattern, + GrouppedDerivePattern, + ChainPattern, + RendererPattern, + HelpPattern, + CompletionPattern, + DispatcherPattern, + DispatcherClapPattern, ]; analyzer @@ -123,6 +132,22 @@ impl PatternAnalyzer { /// - `Ok(HashSet)` —— On success, returns a formatted set of strings, each in the form `"::module_path::item_name"`. /// - `Err(MinglingPathfinderError)` —— If the file cannot be read, returns the corresponding I/O error wrapper. pub fn analyze_file(&self, path: impl AsRef) -> Result, MinglingPathfinderError> { + self.collect_items(path).map(|items| { + AnalyzeResult { items }.into_formatted() + }) + } + + /// Analyzes a single file and returns the raw `Vec`. + /// + /// Unlike `analyze_file`, this method does not format the results into strings, + /// preserving the original module-path and item-name information. Useful for + /// callers that need to combine the results with other data sources. + pub fn analyze_file_items(&self, path: impl AsRef) -> Result, MinglingPathfinderError> { + self.collect_items(path) + } + + /// Internal: collects raw `AnalyzeItem`s from a file. + fn collect_items(&self, path: impl AsRef) -> Result, MinglingPathfinderError> { let path = path.as_ref(); let content = std::fs::read_to_string(path)?; @@ -134,7 +159,6 @@ impl PatternAnalyzer { } } - let result = AnalyzeResult { items: all_items }; - Ok(result.into_formatted()) + Ok(all_items) } } -- cgit