within is a funny combinator. It finds zero or
more instances of parser within the input. It
always succeeds and returns an array of results, each one
being a matched or unmatched string. You could think of
"within" as a glorified search. For example, you can
use it to look for quoted text or multiline comments within an
input.
Example:
constmultilineComments = seq( [str("/*"), manyWithJoin(noneOf(`*/`)), str("*/")], (results: string[]) =>results.join("") ); constparser = within(multilineComments); constinput = `code before /* this is a comment */ code after /* another comment */ end`;
withinis a funny combinator. It finds zero or more instances ofparserwithin the input. It always succeeds and returns an array of results, each one being a matched or unmatched string. You could think of "within" as a glorified search. For example, you can use it to look for quoted text or multiline comments within an input.Example:
Result:
This parser is somewhat expensive, as it will go down the input string one character at a time, applying the given parser each time.