diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-17 11:08:07 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-17 11:11:28 +0800 |
| commit | 79ec6878877f0fd9246d67d3cd4f8cc2d1200150 (patch) | |
| tree | e3cd8cfc7ef5cd2a6a7ceb93d9a4b1764fa21b61 /mingling_picker/src/parselib/pos_matcher.rs | |
| parent | e6136f22cff446b16dbebf3b26a6fdea6dbc0e83 (diff) | |
refactor: rename `mingling_picker` to `arg_picker`
Diffstat (limited to 'mingling_picker/src/parselib/pos_matcher.rs')
| -rw-r--r-- | mingling_picker/src/parselib/pos_matcher.rs | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/mingling_picker/src/parselib/pos_matcher.rs b/mingling_picker/src/parselib/pos_matcher.rs deleted file mode 100644 index 279e01e..0000000 --- a/mingling_picker/src/parselib/pos_matcher.rs +++ /dev/null @@ -1,71 +0,0 @@ -use crate::{matcher_needed::*, parselib::seek_end_of_options}; - -/// `PositionalMatcher` matches positional arguments — values not associated -/// with any named flag. -/// -/// # Rules -/// -/// * Before `--`: skips any argument that starts with the style's long or short -/// prefix (those belong to named matchers). -/// * After `--`: takes **everything** — the `--` marker signals that all -/// remaining values are positional, even if they look like flags. -/// * Runs at the lowest priority (see [`PickerArgAttr::Positional`](crate::PickerArgAttr::Positional)). -pub struct PositionalMatcher; - -impl PositionalMatcher { - /// Check whether `raw` looks like a named flag (starts with a prefix). - #[inline(always)] - fn is_flag_like(raw: &str, style: &ParserStyle) -> bool { - raw.starts_with(style.long_prefix) || raw.starts_with(style.short_prefix) - } -} - -impl Matcher for PositionalMatcher { - fn on_match_one( - args: &[MaskedArg], - style: &ParserStyle, - _arg_info: &PickerArgInfo, - ) -> Option<usize> { - let end = seek_end_of_options(args, style); - - for arg in args { - if end.is_some_and(|e| arg.raw_idx == e) { - // Hit `--`: everything from here on is positional, - // including the first arg after `--`. - continue; - } - if end.is_some_and(|e| arg.raw_idx > e) { - // After `--`: accept everything. - return Some(arg.raw_idx); - } - // Before `--`: skip flag-like args. - if !Self::is_flag_like(arg.raw, style) { - return Some(arg.raw_idx); - } - } - - None - } - - fn on_match_all( - args: &[MaskedArg], - style: &ParserStyle, - _arg_info: &PickerArgInfo, - ) -> Vec<usize> { - let end = seek_end_of_options(args, style); - let mut after_end = false; - let mut result = Vec::new(); - - for arg in args { - if end.is_some_and(|e| arg.raw_idx == e) { - after_end = true; - continue; - } - if after_end || !Self::is_flag_like(arg.raw, style) { - result.push(arg.raw_idx); - } - } - - result - } -} |
