@finnair/path-parser
Version:
Simple object path as array of strings and numbers
14 lines (13 loc) • 441 B
JavaScript
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}`);
}
}