sparcl
v0.1.6
Published
A simple parser combinator library
Downloads
20
Readme
Sparcl
Simple Parser Combinator Library
Examples
// Number sequence parsing
import {
sequence,
separatedBy,
string,
takeAll,
whitespace,
digits,
eof
} from "sparcl";
const parser = sequence(
separatedBy(
sequence(string(","), takeAll(whitespace)),
digits.map(Number)
),
eof
).map(([numbers]) => numbers);
const source = "1, 5, 9, 12";
const result = parser.parse(source);
if (result.isError) {
console.error(result.error.message);
} else {
console.log(result.value); // [ 1, 5, 9, 12 ]
}