File tree Expand file tree Collapse file tree 1 file changed +12
-15
lines changed
Expand file tree Collapse file tree 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> {
297297export function choiceWithCheck < T > (
298298 ...choices : ReadonlyArray < CheckedParser < T > >
299299) : 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+ } ) ;
315312}
316313export function optionalWithCheck < T > (
317314 parser : CheckedParser < T > ,
You can’t perform that action at this time.
0 commit comments