1+ import { assert } from "@std/assert/assert" ;
12import { memoize } from "@std/cache/memoize" ;
23import { ArrayResult , ArrayResultError } from "../array_result.ts" ;
34import { Clearable , ClearableCacheSet , Lazy } from "../cache.ts" ;
@@ -120,13 +121,18 @@ export function lazy<T>(parser: () => Parser<T>): Parser<T> {
120121 }
121122}
122123export function choice < T > ( ...choices : ReadonlyArray < Parser < T > > ) : Parser < T > {
124+ assert ( choices . length > 1 , "`choice` called with less than 2 arguments" ) ;
123125 return new Parser ( ( src ) =>
124126 new ArrayResult ( choices ) . flatMap ( ( parser ) => parser . rawParser ( src ) )
125127 ) ;
126128}
127129export function choiceOnlyOne < T > (
128130 ...choices : ReadonlyArray < Parser < T > >
129131) : Parser < T > {
132+ assert (
133+ choices . length > 1 ,
134+ "`choiceOnlyOne` called with less than 2 arguments" ,
135+ ) ;
130136 return choices . reduceRight (
131137 ( right , left ) =>
132138 new Parser ( ( src ) => {
@@ -151,6 +157,7 @@ export function sequence<T extends ReadonlyArray<unknown>>(
151157 & Readonly < { [ I in keyof T ] : Parser < T [ I ] > } >
152158 & Readonly < { length : T [ "length" ] } >
153159) : Parser < T > {
160+ assert ( sequence . length > 1 , "`sequence` called with less than 2 arguments" ) ;
154161 // We resorted to using `any` types here, make sure it works properly
155162 return sequence . reduceRight (
156163 ( right : Parser < any > , left ) =>
0 commit comments