From 132b065e53e53b588a496d8649bd60872ab88a5c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 14 Jul 2026 03:10:57 +0800 Subject: feat(mingling_picker_macros): add $+ $- $^ special tokens to internal_repeat Extend the `internal_repeat` macro with new special tokens: - `$+`/`ident$+` for current + 1 - `$-`/`ident$-` for current - 1 (clamped at 0) - `$^`/`ident$^` for min (aka start) value Move the repetition marker from outside the paren to the last token inside, supporting `(group,+)` syntax where `+` is the final token. A trailing `+` or `-` after `)` shifts the repetition count. Add `PickerPattern::pick` method using new syntax to allow incremental composition of typed picks. --- mingling_picker/src/picker/patterns.rs | 37 ++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'mingling_picker/src') diff --git a/mingling_picker/src/picker/patterns.rs b/mingling_picker/src/picker/patterns.rs index bd0eb12..2242a70 100644 --- a/mingling_picker/src/picker/patterns.rs +++ b/mingling_picker/src/picker/patterns.rs @@ -1,17 +1,46 @@ +use mingling_picker_macros::internal_repeat; + use crate::{Pickable, Picker, PickerArgs, PickerFlag, PickerResult}; -mingling_picker_macros::internal_repeat!(1..=32 => { - pub struct PickerPattern$<'a, (T$,)+> - where (T$: Pickable + Default,)+ +internal_repeat!(1..=32 => { + pub struct PickerPattern$<'a, (T$,+)> + where (T$: Pickable + Default,+) { pub args: PickerArgs<'a>, ( pub flag_$: &'a PickerFlag<'a, T$>, pub result_$: PickerResult, - )+ + +) } }); +internal_repeat!(1..32 => { + impl<'a, (T$,+)> PickerPattern$<'a, (T$,+)> + where (T$: Pickable + Default,+) + { + #[allow(clippy::type_complexity)] + pub fn pick(self, flag: &'a PickerFlag<'a, N>) -> PickerPattern$+<'a, (T$,+), N> + where + N: Pickable + Default, + { + PickerPattern$+ { + // Args + args: self.args, + + // Current + flag_$+: flag, + result_$+: PickerResult::Unparsed, + + // Prev + ( + flag_$: self.flag_$, + result_$: self.result_$, + +) + } + } + } +}); + impl<'a> Picker<'a> { pub fn pick(self, flag: &'a PickerFlag<'a, N>) -> PickerPattern1<'a, N> where -- cgit