1- use crate :: error:: ParseError ;
21use crate :: pc:: { ParseResult , Parser , ToOption } ;
32
43//
@@ -12,40 +11,50 @@ where
1211{
1312 /// Parses both the left and the right side.
1413 /// If the right side fails with a non fatal error, parsing of the left side is undone.
15- fn and < R , F , O > ( self , right : R , combiner : F ) -> impl Parser < I , Output = O >
14+ fn and < R , F , O > ( self , right : R , combiner : F ) -> impl Parser < I , Output = O , Error = Self :: Error >
1615 where
17- R : Parser < I > ,
16+ R : Parser < I , Error = Self :: Error > ,
1817 F : Fn ( Self :: Output , R :: Output ) -> O ,
1918 {
2019 AndParser :: new ( self , right, combiner)
2120 }
2221
23- fn and_tuple < R > ( self , right : R ) -> impl Parser < I , Output = ( Self :: Output , R :: Output ) >
22+ fn and_tuple < R > (
23+ self ,
24+ right : R ,
25+ ) -> impl Parser < I , Output = ( Self :: Output , R :: Output ) , Error = Self :: Error >
2426 where
25- R : Parser < I > ,
27+ R : Parser < I , Error = Self :: Error > ,
2628 {
2729 self . and ( right, |l, r| ( l, r) )
2830 }
2931
30- fn and_keep_left < R > ( self , right : R ) -> impl Parser < I , Output = Self :: Output >
32+ fn and_keep_left < R > (
33+ self ,
34+ right : R ,
35+ ) -> impl Parser < I , Output = Self :: Output , Error = Self :: Error >
3136 where
32- R : Parser < I > ,
37+ R : Parser < I , Error = Self :: Error > ,
3338 {
3439 self . and ( right, |l, _| l)
3540 }
3641
37- fn and_keep_right < R > ( self , right : R ) -> impl Parser < I , Output = R :: Output >
42+ fn and_keep_right < R > ( self , right : R ) -> impl Parser < I , Output = R :: Output , Error = Self :: Error >
3843 where
39- R : Parser < I > ,
44+ R : Parser < I , Error = Self :: Error > ,
4045 {
4146 self . and ( right, |_, r| r)
4247 }
4348
4449 /// Parses the left side and optionally the right side.
4550 /// The combiner function maps the left and (optional) right output to the final result.
46- fn and_opt < R , F , O > ( self , right : R , combiner : F ) -> impl Parser < I , Output = O >
51+ fn and_opt < R , F , O > (
52+ self ,
53+ right : R ,
54+ combiner : F ,
55+ ) -> impl Parser < I , Output = O , Error = Self :: Error >
4756 where
48- R : Parser < I > ,
57+ R : Parser < I , Error = Self :: Error > ,
4958 F : Fn ( Self :: Output , Option < R :: Output > ) -> O ,
5059 {
5160 self . and ( right. to_option ( ) , combiner)
@@ -56,35 +65,45 @@ where
5665 fn and_opt_tuple < R > (
5766 self ,
5867 right : R ,
59- ) -> impl Parser < I , Output = ( Self :: Output , Option < R :: Output > ) >
68+ ) -> impl Parser < I , Output = ( Self :: Output , Option < R :: Output > ) , Error = Self :: Error >
6069 where
61- R : Parser < I > ,
70+ R : Parser < I , Error = Self :: Error > ,
6271 {
6372 self . and_opt ( right, |l, r| ( l, r) )
6473 }
6574
6675 /// Parses the left side and optionally the right side.
6776 /// The result is only the left side's output.
68- fn and_opt_keep_left < R > ( self , right : R ) -> impl Parser < I , Output = Self :: Output >
77+ fn and_opt_keep_left < R > (
78+ self ,
79+ right : R ,
80+ ) -> impl Parser < I , Output = Self :: Output , Error = Self :: Error >
6981 where
70- R : Parser < I > ,
82+ R : Parser < I , Error = Self :: Error > ,
7183 {
7284 self . and_opt ( right, |l, _| l)
7385 }
7486
7587 /// Parses the left side and optionally the right side.
7688 /// The result is only the right side's output.
77- fn and_opt_keep_right < R > ( self , right : R ) -> impl Parser < I , Output = Option < R :: Output > >
89+ fn and_opt_keep_right < R > (
90+ self ,
91+ right : R ,
92+ ) -> impl Parser < I , Output = Option < R :: Output > , Error = Self :: Error >
7893 where
79- R : Parser < I > ,
94+ R : Parser < I , Error = Self :: Error > ,
8095 {
8196 self . and_opt ( right, |_, r| r)
8297 }
8398
84- fn surround < L , R > ( self , left : L , right : R ) -> impl Parser < I , Output = Self :: Output >
99+ fn surround < L , R > (
100+ self ,
101+ left : L ,
102+ right : R ,
103+ ) -> impl Parser < I , Output = Self :: Output , Error = Self :: Error >
85104 where
86- L : Parser < I > ,
87- R : Parser < I > ,
105+ L : Parser < I , Error = Self :: Error > ,
106+ R : Parser < I , Error = Self :: Error > ,
88107 {
89108 left. and_keep_right ( self ) . and_keep_left ( right)
90109 }
@@ -120,11 +139,13 @@ impl<I, L, R, F, O> Parser<I> for AndParser<L, R, F>
120139where
121140 I : Clone ,
122141 L : Parser < I > ,
123- R : Parser < I > ,
142+ R : Parser < I , Error = L :: Error > ,
124143 F : Fn ( L :: Output , R :: Output ) -> O ,
125144{
126145 type Output = O ;
127- fn parse ( & self , tokenizer : I ) -> ParseResult < I , Self :: Output , ParseError > {
146+ type Error = L :: Error ;
147+
148+ fn parse ( & self , tokenizer : I ) -> ParseResult < I , Self :: Output , Self :: Error > {
128149 match self . left . parse ( tokenizer. clone ( ) ) {
129150 Ok ( ( input, left) ) => {
130151 match self . right . parse ( input) {
@@ -142,11 +163,11 @@ where
142163/// Parses the left side optionally and then the right side.
143164/// If the right side fails, the left side is reverted too.
144165/// The combiner function is used to create the final result.
145- pub fn opt_and < I , L , R , F , O > (
146- left : impl Parser < I , Output = L > ,
147- right : impl Parser < I , Output = R > ,
166+ pub fn opt_and < I , L , R , E , F , O > (
167+ left : impl Parser < I , Output = L , Error = E > ,
168+ right : impl Parser < I , Output = R , Error = E > ,
148169 combiner : F ,
149- ) -> impl Parser < I , Output = O >
170+ ) -> impl Parser < I , Output = O , Error = E >
150171where
151172 I : Clone ,
152173 F : Fn ( Option < L > , R ) -> O ,
@@ -157,10 +178,10 @@ where
157178/// Parses the left side optionally and then the right side.
158179/// If the right side fails, the left side is reverted too.
159180/// The result is a tuple of the (optional) left side and the right side.
160- pub fn opt_and_tuple < I , L , R > (
161- left : impl Parser < I , Output = L > ,
162- right : impl Parser < I , Output = R > ,
163- ) -> impl Parser < I , Output = ( Option < L > , R ) >
181+ pub fn opt_and_tuple < I , L , R , E > (
182+ left : impl Parser < I , Output = L , Error = E > ,
183+ right : impl Parser < I , Output = R , Error = E > ,
184+ ) -> impl Parser < I , Output = ( Option < L > , R ) , Error = E >
164185where
165186 I : Clone ,
166187{
@@ -170,10 +191,10 @@ where
170191/// Parses the left side optionally and then the right side.
171192/// If the right side fails, the left side is reverted too.
172193/// The result is the right side only, the left is discarded.
173- pub fn opt_and_keep_right < I , L , R > (
174- left : impl Parser < I , Output = L > ,
175- right : impl Parser < I , Output = R > ,
176- ) -> impl Parser < I , Output = R >
194+ pub fn opt_and_keep_right < I , L , R , E > (
195+ left : impl Parser < I , Output = L , Error = E > ,
196+ right : impl Parser < I , Output = R , Error = E > ,
197+ ) -> impl Parser < I , Output = R , Error = E >
177198where
178199 I : Clone ,
179200{
0 commit comments