Skip to main content
Module

x/pazza/mod.ts>sepEndBy

Parser combinators library designed for Deno, but also works on browsers and Node.js.
Go to Latest
function sepEndBy
import { sepEndBy } from "https://deno.land/x/pazza@v0.3.0/mod.ts";

Execute the embedded parser in specified times, with another parser as separator, then produce a list of values. Separator can be trailing.

sepEndBy(char(","), digit())("1,2").output; // ==> ["1", "2"]
sepEndBy(char(","), digit())("1,2,").output; // ==> ["1", "2"]
sepEndBy(char(","), digit())("1,2,").input === "";
sepEndBy(char(","), digit(), 1)("").ok === false;
sepEndBy(char(","), digit(), 0, 1)("1,2").output; // ==> ["1"]
sepEndBy(char(","), digit(), 0, 1)("1,2").input === "2";

Type Parameters

T
E
I extends Input
CtxIn
CtxOut
Min extends number

Parameters

separator: IParser<unknown, unknown, I, CtxIn, CtxOut>

parser to parse as separator

parser: IParser<T, E, I, CtxIn, CtxOut>

embedded parser

optional
min: Min | 0 = [UNSUPPORTED]

minimum times (inclusive), default is 0

optional
max = [UNSUPPORTED]

maximum times (inclusive), default is Infinity

Returns

NeverFailOnZeroCountParser<Min, T, ErrorKind.SepEndBy, I, CtxIn, CtxOut>