UNPKG

@finnair/path-parser

Version:
90 lines (89 loc) 4.81 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // Generated automatically by nearley, version 2.20.1 // http://github.com/Hardmath123/nearley // Bypasses TS6133. Allow declared but unused functions. /* v8 ignore next */ // @ts-ignore function id(d) { return d[0]; } const matchers = __importStar(require("@finnair/path")); const moo_1 = __importDefault(require("moo")); const lexer = moo_1.default.compile({ qString: /'(?:\\["bfnrt\/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*?'/, qqString: /"(?:\\["bfnrt\/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*?"/, integer: /[0-9]+/, property: /[a-zA-Z_][a-zA-Z0-9_]*/, comma: /, ?/, lbracket: /\[ ?/, rbracket: / ?]/, '*': '*', '$': '$', '.': '.', }); function handleQString(qString) { return JSON.parse('"' + qString.substring(1, qString.length - 1) + '"'); } ; ; ; ; const grammar = { Lexer: lexer, ParserRules: [ { "name": "Path$ebnf$1", "symbols": [] }, { "name": "Path$ebnf$1", "symbols": ["Path$ebnf$1", "PathExpression"], "postprocess": (d) => d[0].concat([d[1]]) }, { "name": "Path", "symbols": [{ "literal": "$" }, "Path$ebnf$1"], "postprocess": d => d[1].reduce((result, matcher) => result.concat(matcher), []) }, { "name": "PathExpression", "symbols": [{ "literal": "." }, "PropertyExpression"], "postprocess": d => d[1] }, { "name": "PathExpression", "symbols": [{ type: "lbracket" }, "IndexExpression", { type: "rbracket" }], "postprocess": d => d[1] }, { "name": "PathExpression", "symbols": [{ type: "lbracket" }, "UnionExpression", { type: "rbracket" }], "postprocess": d => new matchers.UnionMatcher(d[1]) }, { "name": "PropertyExpression", "symbols": [{ "literal": "*" }], "postprocess": d => matchers.AnyProperty }, { "name": "PropertyExpression", "symbols": [{ type: "property" }], "postprocess": d => new matchers.PropertyMatcher(d[0].value) }, { "name": "IndexExpression", "symbols": [{ type: "integer" }], "postprocess": d => new matchers.IndexMatcher(parseInt(d[0].value)) }, { "name": "IndexExpression", "symbols": [{ type: "qqString" }], "postprocess": d => new matchers.PropertyMatcher(JSON.parse(d[0].value)) }, { "name": "IndexExpression", "symbols": [{ type: "qString" }], "postprocess": d => new matchers.PropertyMatcher(handleQString(d[0].value)) }, { "name": "IndexExpression", "symbols": [{ "literal": "*" }], "postprocess": d => matchers.AnyIndex }, { "name": "UnionExpression", "symbols": ["ComponentExpression", { type: "comma" }, "ComponentExpression"], "postprocess": d => [d[0], d[2]] }, { "name": "UnionExpression", "symbols": ["ComponentExpression", { type: "comma" }, "UnionExpression"], "postprocess": d => [d[0], ...d[2]] }, { "name": "ComponentExpression", "symbols": [{ type: "integer" }], "postprocess": d => parseInt(d[0].value) }, { "name": "ComponentExpression", "symbols": [{ type: "property" }], "postprocess": d => d[0].value }, { "name": "ComponentExpression", "symbols": [{ type: "qqString" }], "postprocess": d => JSON.parse(d[0].value) }, { "name": "ComponentExpression", "symbols": [{ type: "qString" }], "postprocess": d => handleQString(d[0].value) } ], ParserStart: "Path", }; exports.default = grammar;