@@ -241,7 +241,7 @@ where
241241 } else {
242242 let span = inp. span_since ( before) ;
243243 Err ( Located :: at (
244- inp. save ( ) ,
244+ inp. offset ( ) . into ( ) ,
245245 E :: Error :: expected_found ( None , None , span) ,
246246 ) )
247247 }
@@ -397,7 +397,7 @@ where
397397 let span = inp. span_since ( before) ;
398398 match ( self . mapper ) ( out, span) {
399399 Ok ( out) => Ok ( M :: bind ( || out) ) ,
400- Err ( e) => Err ( Located :: at ( inp. save ( ) , e) ) ,
400+ Err ( e) => Err ( Located :: at ( inp. offset ( ) . into ( ) , e) ) ,
401401 }
402402 } )
403403 }
@@ -438,7 +438,7 @@ where
438438 let state = inp. state ( ) ;
439439 match ( self . mapper ) ( out, span, state) {
440440 Ok ( out) => Ok ( M :: bind ( || out) ) ,
441- Err ( e) => Err ( Located :: at ( inp. save ( ) , e) ) ,
441+ Err ( e) => Err ( Located :: at ( inp. offset ( ) . into ( ) , e) ) ,
442442 }
443443 } )
444444 }
@@ -875,7 +875,8 @@ impl RepeatedCfg {
875875pub struct Repeated < A , OA , I : ?Sized , E > {
876876 pub ( crate ) parser : A ,
877877 pub ( crate ) at_least : usize ,
878- pub ( crate ) at_most : Option < usize > ,
878+ // Slightly evil: Should be `Option<usize>`, but we encode `!0` as 'no cap' because it's so large
879+ pub ( crate ) at_most : u64 ,
879880 pub ( crate ) phantom : PhantomData < ( OA , E , I ) > ,
880881}
881882
@@ -905,7 +906,7 @@ where
905906 /// Require that the pattern appear at most a maximum number of times.
906907 pub fn at_most ( self , at_most : usize ) -> Self {
907908 Self {
908- at_most : Some ( at_most) ,
909+ at_most : at_most as u64 ,
909910 ..self
910911 }
911912 }
@@ -954,7 +955,7 @@ where
954955 pub fn exactly ( self , exactly : usize ) -> Self {
955956 Self {
956957 at_least : exactly,
957- at_most : Some ( exactly) ,
958+ at_most : exactly as u64 ,
958959 ..self
959960 }
960961 }
@@ -1000,10 +1001,8 @@ where
10001001 inp : & mut InputRef < ' a , ' _ , I , E > ,
10011002 count : & mut Self :: IterState < M > ,
10021003 ) -> Option < PResult < M , O , E :: Error > > {
1003- if let Some ( at_most) = self . at_most {
1004- if * count >= at_most {
1005- return None ;
1006- }
1004+ if * count as u64 >= self . at_most {
1005+ return None ;
10071006 }
10081007
10091008 let before = inp. save ( ) ;
@@ -1038,13 +1037,11 @@ where
10381037 count : & mut Self :: IterState < M > ,
10391038 cfg : & Self :: Config ,
10401039 ) -> Option < PResult < M , O , E :: Error > > {
1041- let at_most = cfg. at_most . or ( self . at_most ) ;
1040+ let at_most = cfg. at_most . map ( |x| x as u64 ) . unwrap_or ( self . at_most ) ;
10421041 let at_least = cfg. at_least . unwrap_or ( self . at_least ) ;
10431042
1044- if let Some ( at_most) = at_most {
1045- if * count >= at_most {
1046- return None ;
1047- }
1043+ if * count as u64 >= at_most {
1044+ return None ;
10481045 }
10491046
10501047 let before = inp. save ( ) ;
@@ -1070,7 +1067,8 @@ pub struct SeparatedBy<A, B, OA, OB, I: ?Sized, E> {
10701067 pub ( crate ) parser : A ,
10711068 pub ( crate ) separator : B ,
10721069 pub ( crate ) at_least : usize ,
1073- pub ( crate ) at_most : Option < usize > ,
1070+ // Slightly evil: Should be `Option<usize>`, but we encode `!0` as 'no cap' because it's so large
1071+ pub ( crate ) at_most : u64 ,
10741072 pub ( crate ) allow_leading : bool ,
10751073 pub ( crate ) allow_trailing : bool ,
10761074 pub ( crate ) phantom : PhantomData < ( OA , OB , E , I ) > ,
@@ -1142,7 +1140,7 @@ where
11421140 /// ````
11431141 pub fn at_most ( self , at_most : usize ) -> Self {
11441142 Self {
1145- at_most : Some ( at_most) ,
1143+ at_most : at_most as u64 ,
11461144 ..self
11471145 }
11481146 }
@@ -1169,7 +1167,7 @@ where
11691167 pub fn exactly ( self , exactly : usize ) -> Self {
11701168 Self {
11711169 at_least : exactly,
1172- at_most : Some ( exactly) ,
1170+ at_most : exactly as u64 ,
11731171 ..self
11741172 }
11751173 }
@@ -1253,7 +1251,7 @@ where
12531251 inp : & mut InputRef < ' a , ' _ , I , E > ,
12541252 state : & mut Self :: IterState < M > ,
12551253 ) -> Option < PResult < M , OA , E :: Error > > {
1256- if self . at_most . map_or ( false , |max| * state >= max ) {
1254+ if * state as u64 >= self . at_most {
12571255 return None ;
12581256 }
12591257
@@ -1433,7 +1431,7 @@ where
14331431 Ok ( _) => {
14341432 let ( at, tok) = inp. next ( ) ;
14351433 Err ( Located :: at (
1436- at,
1434+ at. into ( ) ,
14371435 E :: Error :: expected_found ( None , tok, inp. span_since ( before. offset ) ) ,
14381436 ) )
14391437 }
0 commit comments