UNPKG

@finnair/path-parser

Version:
41 lines (40 loc) 1.85 kB
// Generated automatically by nearley, version 2.20.1 // http://github.com/Hardmath123/nearley // Bypasses TS6133. Allow declared but unused functions. // NOTE: Manually edited to remove dead code /* v8 ignore next */ // @ts-ignore function id(d) { return d[0]; } import moo from 'moo'; const lexer = moo.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_]*/, '$': '$', '[': '[', ']': ']', '.': '.', }); 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, component) => result.concat(component), []) }, { "name": "PathExpression", "symbols": [{ "literal": "." }, "PropertyExpression"], "postprocess": d => d[1] }, { "name": "PathExpression", "symbols": [{ "literal": "[" }, "IndexExpression", { "literal": "]" }], "postprocess": d => d[1] }, { "name": "PropertyExpression", "symbols": [{ type: "property" }], "postprocess": d => d[0].value }, { "name": "IndexExpression", "symbols": [{ type: "integer" }], "postprocess": d => parseInt(d[0].value) }, { "name": "IndexExpression", "symbols": [{ type: "qqString" }], "postprocess": d => JSON.parse(d[0].value) }, { "name": "IndexExpression", "symbols": [{ type: "qString" }], "postprocess": d => handleQString(d[0].value) } ], ParserStart: "Path", }; export default grammar;