aboutsummaryrefslogtreecommitdiff
path: root/arg_picker/src/parselib.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-18 05:31:20 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-18 05:31:20 +0800
commite89608805efe7a24ab72b8030bc307b6a4f6d6fc (patch)
treefc722c41194d28f694ece2a21fd3902a0246c9cd /arg_picker/src/parselib.rs
parente525ad90af0295e7f6b4f16367ba12a6d88abfb4 (diff)
feat(arg_picker): add preprocessing and postprocessing priority levels
Add `Begin`, `Preprocess`, `Final`, and `Postprocess` variants to `PickerArgAttr` enum, and implement `Pickable` for `PickerArgs` as a built-in picker that consumes all remaining unclaimed arguments at lowest priority. Expose `is_masked` and `build_masked_args` as public functions for use by custom pickers.
Diffstat (limited to 'arg_picker/src/parselib.rs')
-rw-r--r--arg_picker/src/parselib.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/arg_picker/src/parselib.rs b/arg_picker/src/parselib.rs
index 7fbd606..0fcd583 100644
--- a/arg_picker/src/parselib.rs
+++ b/arg_picker/src/parselib.rs
@@ -117,13 +117,32 @@ impl<'a> From<crate::TagPhaseContext<'a>> for MatcherContext<'a> {
}
}
+/// Checks whether the argument at index `idx` is already claimed (masked).
+///
+/// Returns `true` if `idx` is within the mask bounds and the mask value is non-zero,
+/// indicating the argument has been claimed by a previous matcher.
+///
+/// # Arguments
+///
+/// * `mask` - A byte slice where non-zero values indicate claimed arguments.
+/// * `idx` - The index to check in the mask.
#[inline(always)]
-fn is_masked(mask: &[u8], idx: usize) -> bool {
+pub fn is_masked(mask: &[u8], idx: usize) -> bool {
idx < mask.len() && mask[idx] != 0
}
+/// Builds a vector of [`MaskedArg`] from the given `PickerArgs` and mask.
+///
+/// Only arguments whose mask entry is `0` (i.e., available/not yet claimed) are included.
+/// Each resulting [`MaskedArg`] retains its original raw string and its index in the full
+/// argument list for later reference.
+///
+/// # Arguments
+///
+/// * `args` - The full set of parsed arguments.
+/// * `mask` - A byte slice where `0` means available and non-zero means already claimed.
#[inline(always)]
-fn build_masked_args<'a>(args: &'a PickerArgs, mask: &'a [u8]) -> Vec<MaskedArg<'a>> {
+pub fn build_masked_args<'a>(args: &'a PickerArgs, mask: &'a [u8]) -> Vec<MaskedArg<'a>> {
let mut cidx = 0;
args.iter()
.filter_map(|r| {