or takes an array of parsers and runs them sequentially. It returns the results of the first parser that succeeds. You can use capture in an or:
or
capture
const parser = or(capture(digit, "num"), capture(word, "name")); Copy
const parser = or(capture(digit, "num"), capture(word, "name"));
or supports backtracking by returning a nextParser:
nextParser
const parser = or(str("hello"), str("hello!"));// this will match the first parserconst result = parser("hello");// but or returns the untried parsers as a new parserresult.nextParser("hello!"); // works// result.nextParser is the same as or(str("hello!")) Copy
const parser = or(str("hello"), str("hello!"));// this will match the first parserconst result = parser("hello");// but or returns the untried parsers as a new parserresult.nextParser("hello!"); // works// result.nextParser is the same as or(str("hello!"))
Rest
parsers to try
Generated using TypeDoc
or
takes an array of parsers and runs them sequentially. It returns the results of the first parser that succeeds. You can usecapture
in anor
:or
supports backtracking by returning anextParser
: