File tree 1 file changed +12
-15
lines changed
1 file changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -297,21 +297,18 @@ export function checkedAsWhole<T>(parser: Parser<T>): CheckedParser<T> {
297
297
export function choiceWithCheck < T > (
298
298
...choices : ReadonlyArray < CheckedParser < T > >
299
299
) : Parser < T > {
300
- return choices . reduceRight (
301
- ( right : Parser < T > , { check, parser } ) =>
302
- new Parser ( ( position ) => {
303
- const arrayResult = check . rawParser ( position ) ;
304
- if ( arrayResult . isError ( ) ) {
305
- return ArrayResult . concat (
306
- arrayResult as ArrayResult < never > ,
307
- right . rawParser ( position ) ,
308
- ) ;
309
- } else {
310
- return parser . rawParser ( position ) ;
311
- }
312
- } ) ,
313
- empty ,
314
- ) ;
300
+ return new Parser ( ( position ) => {
301
+ const errors : Array < ArrayResultError > = [ ] ;
302
+ for ( const { check, parser } of choices ) {
303
+ const result = check . rawParser ( position ) ;
304
+ if ( result . isError ( ) ) {
305
+ errors . push ( ...result . errors ) ;
306
+ } else {
307
+ return parser . rawParser ( position ) ;
308
+ }
309
+ }
310
+ return ArrayResult . errors ( errors ) ;
311
+ } ) ;
315
312
}
316
313
export function optionalWithCheck < T > (
317
314
parser : CheckedParser < T > ,
You can’t perform that action at this time.
0 commit comments