js-parser-combinators example 1
const { exhaustive, and, literal, param, optional } = require('js-parser-combinators')
// A parser that can parse paths such as:
// /user/1234
// /user/1234/details
const parser =
exhaustive(
and(
and(
literal('/user/'),
param('userid', /^\d+/, parseInt)
),
optional(literal('/details'))
)
);
parser({ input: '/user/1234/details' }).ast
no comments