UNPKG

@finnair/path-parser

Version:
14 lines (13 loc) 441 B
import nearley from 'nearley'; import matcherGrammar from './matcherGrammar.js'; import { PathMatcher } from '@finnair/path'; export function parsePathMatcher(str) { const parser = new nearley.Parser(nearley.Grammar.fromCompiled(matcherGrammar)); parser.feed(str); if (parser.results[0]) { return PathMatcher.of(...parser.results[0]); } else { throw new Error(`Unrecognized PathMatcher: ${str}`); } }