@finnair/path-parser
Version:
Simple object path as array of strings and numbers
14 lines (13 loc) • 404 B
JavaScript
import { Path } from '@finnair/path';
import nearley from 'nearley';
import pathGrammar from './pathGrammar.js';
export function parsePath(str) {
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(pathGrammar));
parser.feed(str);
if (parser.results[0]) {
return Path.of(...parser.results[0]);
}
else {
throw new Error(`Unrecognized Path: ${str}`);
}
}