@@ -9,6 +9,7 @@ use nom::{AsBytes, AsChar, Compare, Err, Finish, IResult, Input, Parser};
99use nom_parse_trait:: ParseFrom ;
1010use smallvec:: SmallVec ;
1111use std:: hash:: Hash ;
12+ use std:: ops:: RangeInclusive ;
1213
1314pub fn handle_parser_error < T > ( input : & [ u8 ] ) -> T
1415where
@@ -49,16 +50,16 @@ pub fn find_many_skipping_unknown<I: Input, E: ParseError<I>, T: ParseFrom<I, E>
4950 }
5051}
5152
52- pub fn many_1_n < const MAX : usize , Input , Output , Error , ParserFunction > (
53+ pub fn many_1_n < const MAX : usize , I , Output , E , ParserFunction > (
5354 mut parser : ParserFunction ,
54- ) -> impl FnMut ( Input ) -> IResult < Input , SmallVec < [ Output ; MAX ] > , Error >
55+ ) -> impl Parser < I , Output = SmallVec < [ Output ; MAX ] > , Error = E >
5556where
56- Input : nom :: Input ,
57- ParserFunction : Parser < Input , Output = Output , Error = Error > ,
58- Error : ParseError < Input > ,
57+ I : Input ,
58+ ParserFunction : Parser < I , Output = Output , Error = E > ,
59+ E : ParseError < I > ,
5960 [ Output ; MAX ] : smallvec:: Array < Item = Output > ,
6061{
61- move |mut input : Input | {
62+ move |mut input : I | {
6263 let mut result = SmallVec :: new ( ) ;
6364 while result. len ( ) < MAX {
6465 let input_len_before = input. input_len ( ) ;
@@ -68,10 +69,10 @@ where
6869 Ok ( ( next_input, output) ) => {
6970 // infinite loop check: the parser must always consume
7071 if next_input. input_len ( ) == input_len_before {
71- return Err ( Err :: Error ( Error :: from_error_kind ( input, ErrorKind :: Many1 ) ) ) ;
72+ return Err ( Err :: Error ( E :: from_error_kind ( input, ErrorKind :: Many1 ) ) ) ;
7273 }
7374 if result. len ( ) == MAX {
74- return Err ( Err :: Error ( Error :: from_error_kind ( input, ErrorKind :: ManyMN ) ) ) ;
75+ return Err ( Err :: Error ( E :: from_error_kind ( input, ErrorKind :: ManyMN ) ) ) ;
7576 }
7677
7778 input = next_input;
@@ -355,3 +356,19 @@ fn hex_decode(c: char) -> Option<u8> {
355356 _ => None ,
356357 }
357358}
359+
360+ pub fn range_inclusive < I , E : ParseError < I > , T , F , G > (
361+ value : F ,
362+ separator : G ,
363+ ) -> impl Parser < I , Output = RangeInclusive < T > , Error = E >
364+ where
365+ F : Parser < I , Output = T , Error = E > + Clone ,
366+ G : Parser < I , Error = E > ,
367+ I : Input ,
368+ <I as Input >:: Item : AsChar ,
369+ for < ' a > I : Compare < & ' a [ u8 ] > ,
370+ {
371+ map ( separated_pair ( value. clone ( ) , separator, value) , |( l, r) | {
372+ l..=r
373+ } )
374+ }
0 commit comments