@finnair/path-parser
Version:
Simple object path as array of strings and numbers
20 lines (19 loc) • 782 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.parsePathMatcher = parsePathMatcher;
const nearley_1 = __importDefault(require("nearley"));
const matcherGrammar_js_1 = __importDefault(require("./matcherGrammar.js"));
const path_1 = require("@finnair/path");
function parsePathMatcher(str) {
const parser = new nearley_1.default.Parser(nearley_1.default.Grammar.fromCompiled(matcherGrammar_js_1.default));
parser.feed(str);
if (parser.results[0]) {
return path_1.PathMatcher.of(...parser.results[0]);
}
else {
throw new Error(`Unrecognized PathMatcher: ${str}`);
}
}