oni_comb_parser_rs/internal/parser_impl/
repeat_parser_impl.rs1use crate::core::Parser;
2use crate::extension::parser::RepeatParser;
3use crate::extension::parsers::RepeatParsers;
4use crate::internal::ParsersImpl;
5use crate::utils::RangeArgument;
6use std::fmt::Debug;
7
8impl<'a, I, A> RepeatParser<'a> for Parser<'a, I, A> {
9 fn repeat<R>(self, range: R) -> Self::P<'a, Self::Input, Vec<Self::Output>>
10 where
11 R: RangeArgument<usize> + Debug + 'a,
12 Self::Input: Clone + 'a,
13 Self::Output: Clone + Debug + 'a,
14 Self: Sized, {
15 ParsersImpl::repeat(self, range)
16 }
17
18 fn of_many0(self) -> Self::P<'a, Self::Input, Vec<Self::Output>>
19 where
20 Self::Input: Clone + 'a,
21 Self::Output: Clone + Debug + 'a, {
22 ParsersImpl::many0(self)
23 }
24
25 fn of_many1(self) -> Self::P<'a, Self::Input, Vec<Self::Output>>
26 where
27 Self::Input: Clone + 'a,
28 Self::Output: Clone + Debug + 'a, {
29 ParsersImpl::many1(self)
30 }
31
32 fn of_many_n_m(self, n: usize, m: usize) -> Self::P<'a, Self::Input, Vec<Self::Output>>
33 where
34 Self::Input: Clone + 'a,
35 Self::Output: Clone + Debug + 'a, {
36 self.repeat(n..=m)
37 }
38
39 fn of_count(self, n: usize) -> Self::P<'a, Self::Input, Vec<Self::Output>>
40 where
41 Self::Input: Clone + 'a,
42 Self::Output: Clone + Debug + 'a, {
43 ParsersImpl::count(self, n)
44 }
45
46 fn of_rep_sep<B, R>(
47 self,
48 range: R,
49 separator: Option<Self::P<'a, Self::Input, B>>,
50 ) -> Self::P<'a, Self::Input, Vec<Self::Output>>
51 where
52 R: RangeArgument<usize> + Debug + 'a,
53 Self::Input: Clone + 'a,
54 Self::Output: Clone + Debug + 'a,
55 B: Clone + Debug + 'a, {
56 ParsersImpl::repeat_sep(self, range, separator)
57 }
58
59 fn of_many0_sep<B>(self, separator: Self::P<'a, Self::Input, B>) -> Self::P<'a, Self::Input, Vec<Self::Output>>
60 where
61 Self::Input: Clone + 'a,
62 Self::Output: Clone + Debug + 'a,
63 B: Clone + Debug + 'a, {
64 ParsersImpl::many0_sep(self, separator)
65 }
66
67 fn of_many1_sep<B>(self, separator: Self::P<'a, Self::Input, B>) -> Self::P<'a, Self::Input, Vec<Self::Output>>
68 where
69 Self::Input: Clone + 'a,
70 Self::Output: Clone + Debug + 'a,
71 B: Clone + Debug + 'a, {
72 ParsersImpl::many1_sep(self, separator)
73 }
74
75 fn of_many_n_m_sep<B>(
76 self,
77 n: usize,
78 m: usize,
79 separator: Self::P<'a, Self::Input, B>,
80 ) -> Self::P<'a, Self::Input, Vec<Self::Output>>
81 where
82 Self::Input: Clone + 'a,
83 Self::Output: Clone + Debug + 'a,
84 B: Clone + Debug + 'a, {
85 ParsersImpl::repeat_sep(self, n..=m, Some(separator))
86 }
87
88 fn of_count_sep<B>(
89 self,
90 n: usize,
91 separator: Self::P<'a, Self::Input, B>,
92 ) -> Self::P<'a, Self::Input, Vec<Self::Output>>
93 where
94 Self::Input: Clone + 'a,
95 Self::Output: Clone + Debug + 'a,
96 B: Clone + Debug + 'a, {
97 ParsersImpl::repeat_sep(self, n..=n, Some(separator))
98 }
99}