| 668 | * Create a parser which parses \<function\>(\<args\>). |
| 669 | * */ |
| 670 | export function createFunction<T>(func: string | P.Parser<string>, args: P.Parser<T>): P.Parser<[string, T]> { |
| 671 | const realFunc = typeof func === "string" ? P.string(func) : func; |
| 672 | return P.seqMap( |
| 673 | realFunc.skip(P.optWhitespace), |
| 674 | args.trim(P.optWhitespace).wrap(P.string("("), P.string(")")), |
| 675 | (f, a) => [f, a] |
| 676 | ); |
| 677 | } |
| 678 | |
| 679 | /** Chains a list of parsers; the first one must succeed, but following ones may fail without failing the overall parse. */ |
| 680 | export function chainOpt<T>(base: P.Parser<T>, ...funcs: ((r: T) => P.Parser<T>)[]): P.Parser<T> { |