UNPKG

@finnair/path-parser

Version:
14 lines (13 loc) 404 B
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}`); } }