MCPcopy Create free account
hub / github.com/blacksmithgu/datacore / createFunction

Function createFunction

src/expression/parser.ts:670–677  ·  view source on GitHub ↗
(func: string | P.Parser<string>, args: P.Parser<T>)

Source from the content-addressed store, hash-verified

668 * Create a parser which parses \<function\>(\<args\>).
669 * */
670export 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. */
680export function chainOpt<T>(base: P.Parser<T>, ...funcs: ((r: T) => P.Parser<T>)[]): P.Parser<T> {

Callers 1

parser.tsFile · 0.85

Calls 1

wrapMethod · 0.80

Tested by

no test coverage detected