aboutsummaryrefslogtreecommitdiff
path: root/mingling_picker/src/picker/patterns.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-14 03:10:57 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-14 03:10:57 +0800
commit132b065e53e53b588a496d8649bd60872ab88a5c (patch)
tree11f2785649d73d85441501c0dd67476bd4d80c09 /mingling_picker/src/picker/patterns.rs
parent3f90ae7c987b16d485a2fb4e9f9bcb3774d37530 (diff)
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.
Diffstat (limited to 'mingling_picker/src/picker/patterns.rs')
-rw-r--r--mingling_picker/src/picker/patterns.rs37
1 files changed, 33 insertions, 4 deletions
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<T$>,
- )+
+ +)
}
});
+internal_repeat!(1..32 => {
+ impl<'a, (T$,+)> PickerPattern$<'a, (T$,+)>
+ where (T$: Pickable + Default,+)
+ {
+ #[allow(clippy::type_complexity)]
+ pub fn pick<N>(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<N>(self, flag: &'a PickerFlag<'a, N>) -> PickerPattern1<'a, N>
where