live-parser
v0.1.1
Published
Type-safe streaming parser combinator library for JavaScript
Maintainers
Readme
live-parser
live-parser is a JavaScript parser combinator library designed for streaming data inputs. It is based on packrat parsing which ensure parsing with linear time complexity.
- Incremental parsing without waiting for full input.
- Build complex parsers from simple composable primitives.
- Fully type safe
Install
npm install live-parserQuick Start
import * as lp from 'live-parser';
const join = (sep: string) => (values: string[]) => values.join(sep);
const zero = lp.literal("0");
const nonZeroDigit = lp.charFrom("1-9");
const digit = lp.oneOf(zero, nonZeroDigit);
const positiveInteger = lp.sequenceOf(
nonZeroDigit,
lp.zeroOrMany(digit).map(join(""))
).map(join(""))
const negativeInteger = lp.sequenceOf(
lp.literal("-"),
positiveInteger
).map(join(""));
const integer = lp.oneOf(
zero,
positiveInteger,
negativeInteger
).map(Number)
// Parse a string
const result = integer.parseString("-123");
console.log(result);
// {
// status: "success",
// offset: 4,
// value: -123
// error: null
// }License
MIT
