aboutsummaryrefslogtreecommitdiff
path: root/mingling_pathf/src/pattern_analyzer.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-28 09:06:08 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-28 09:06:08 +0800
commit748c14588cf1c31c8b8d60a9c94349c0173ef607 (patch)
tree4c09bfafd93b629a68f0f78902a33e8dd9ef18d1 /mingling_pathf/src/pattern_analyzer.rs
parent50f2d767e2d07685e49fb7deae68d506ea11a79d (diff)
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!()`.
Diffstat (limited to 'mingling_pathf/src/pattern_analyzer.rs')
-rw-r--r--mingling_pathf/src/pattern_analyzer.rs28
1 files changed, 26 insertions, 2 deletions
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<String>)` —— 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<Path>) -> Result<HashSet<String>, MinglingPathfinderError> {
+ self.collect_items(path).map(|items| {
+ AnalyzeResult { items }.into_formatted()
+ })
+ }
+
+ /// Analyzes a single file and returns the raw `Vec<AnalyzeItem>`.
+ ///
+ /// 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<Path>) -> Result<Vec<AnalyzeItem>, MinglingPathfinderError> {
+ self.collect_items(path)
+ }
+
+ /// Internal: collects raw `AnalyzeItem`s from a file.
+ fn collect_items(&self, path: impl AsRef<Path>) -> Result<Vec<AnalyzeItem>, 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)
}
}