Skip to main content
Module

x/pazza/mod.ts>sepBy

Parser combinators library designed for Deno, but also works on browsers and Node.js.
Go to Latest
function sepBy
import { sepBy } 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.

If separator is trailing, it will be treated as the rest of input without parsing.

sepBy(char(","), digit())("1,2").output; // ==> ["1", "2"]
sepBy(char(","), digit())("1,2,").output; // ==> ["1", "2"]
sepBy(char(","), digit())("1,2,").input === ",";
sepBy(char(","), digit(), 1)("").ok === false;
sepBy(char(","), digit(), 0, 1)("1,2").output; // ==> ["1"]
sepBy(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.SepBy, I, CtxIn, CtxOut>