11use crate :: error:: ParseError ;
22use crate :: pc:: { ParseResult , ParseResultTrait , Parser } ;
33
4- pub trait Chain < I > : Parser < I >
4+ /// Similar to `and_without_undo`, but the right parser is created dynamically
5+ /// based on the result of the first parser.
6+ pub trait ThenWith < I > : Parser < I >
57where
68 Self : Sized ,
79{
8- fn chain < RF , R , F , O > ( self , right_factory : RF , combiner : F ) -> impl Parser < I , Output = O >
10+ /// Similar to `and_without_undo`, but the right parser is created dynamically
11+ /// based on the result of the first parser.
12+ fn then_with < RF , R , F , O > ( self , right_factory : RF , combiner : F ) -> impl Parser < I , Output = O >
913 where
1014 RF : Fn ( & Self :: Output ) -> R ,
1115 R : Parser < I > ,
1216 F : Fn ( Self :: Output , R :: Output ) -> O ,
1317 {
14- ChainParser :: new ( self , right_factory, combiner)
18+ ThenWithParser :: new ( self , right_factory, combiner)
1519 }
1620}
1721
18- impl < I , P > Chain < I > for P where P : Parser < I > { }
22+ impl < I , P > ThenWith < I > for P where P : Parser < I > { }
1923
20- struct ChainParser < L , R , F > {
24+ struct ThenWithParser < L , R , F > {
2125 left : L ,
2226 right : R ,
2327 combiner : F ,
2428}
25- impl < L , R , F > ChainParser < L , R , F > {
29+ impl < L , R , F > ThenWithParser < L , R , F > {
2630 pub fn new ( left : L , right : R , combiner : F ) -> Self {
2731 Self {
2832 left,
@@ -32,7 +36,7 @@ impl<L, R, F> ChainParser<L, R, F> {
3236 }
3337}
3438
35- impl < I , L , RF , R , F , O > Parser < I > for ChainParser < L , RF , F >
39+ impl < I , L , RF , R , F , O > Parser < I > for ThenWithParser < L , RF , F >
3640where
3741 L : Parser < I > ,
3842 RF : Fn ( & L :: Output ) -> R ,
0 commit comments