UNPKG

@astronautlabs/jsonpath

Version:

Query JavaScript objects with JSONPath expressions. Robust / safe JSONPath engine for Node.js.

136 lines 6.29 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GRAMMAR = void 0; var tokens_1 = require("./tokens"); var fs = __importStar(require("fs")); var path = __importStar(require("path")); /** * @internal * @hidden */ var grammar = { lex: { macros: { esc: "\\\\", int: tokens_1.TOKENS.integer }, rules: [ ["\\$", "return 'DOLLAR'"], ["\\.\\.", "return 'DOT_DOT'"], ["\\.", "return 'DOT'"], ["\\*", "return 'STAR'"], [tokens_1.TOKENS.identifier, "return 'IDENTIFIER'"], ["\\[", "return '['"], ["\\]", "return ']'"], [",", "return ','"], ["({int})?\\:({int})?(\\:({int})?)?", "return 'ARRAY_SLICE'"], ["{int}", "return 'INTEGER'"], [tokens_1.TOKENS.qq_string, "yytext = yytext.substr(1,yyleng-2); return 'QQ_STRING';"], [tokens_1.TOKENS.q_string, "yytext = yytext.substr(1,yyleng-2); return 'Q_STRING';"], ["\\(.+?\\)(?=\\])", "return 'SCRIPT_EXPRESSION'"], ["\\?\\(.+?\\)(?=\\])", "return 'FILTER_EXPRESSION'"] ] }, start: "JSON_PATH", bnf: { JSON_PATH: [ ['DOLLAR', 'yy.ast.set({ expression: { type: "root", value: $1 } }); yy.ast.unshift(); return yy.ast.yield()'], ['DOLLAR PATH_COMPONENTS', 'yy.ast.set({ expression: { type: "root", value: $1 } }); yy.ast.unshift(); return yy.ast.yield()'], ['LEADING_CHILD_MEMBER_EXPRESSION', 'yy.ast.unshift(); return yy.ast.yield()'], ['LEADING_CHILD_MEMBER_EXPRESSION PATH_COMPONENTS', 'yy.ast.set({ operation: "member", scope: "child", expression: { type: "identifier", value: $1 }}); yy.ast.unshift(); return yy.ast.yield()'] ], PATH_COMPONENTS: [ ['PATH_COMPONENT', ''], ['PATH_COMPONENTS PATH_COMPONENT', ''] ], PATH_COMPONENT: [ ['MEMBER_COMPONENT', 'yy.ast.set({ operation: "member" }); yy.ast.push()'], ['SUBSCRIPT_COMPONENT', 'yy.ast.set({ operation: "subscript" }); yy.ast.push() '] ], MEMBER_COMPONENT: [ ['CHILD_MEMBER_COMPONENT', 'yy.ast.set({ scope: "child" })'], ['DESCENDANT_MEMBER_COMPONENT', 'yy.ast.set({ scope: "descendant" })'] ], CHILD_MEMBER_COMPONENT: [ ['DOT MEMBER_EXPRESSION', ''] ], LEADING_CHILD_MEMBER_EXPRESSION: [ ['MEMBER_EXPRESSION', 'yy.ast.set({ scope: "child", operation: "member" })'] ], DESCENDANT_MEMBER_COMPONENT: [ ['DOT_DOT MEMBER_EXPRESSION', ''] ], MEMBER_EXPRESSION: [ ['STAR', 'yy.ast.set({ expression: { type: "wildcard", value: $1 } })'], ['IDENTIFIER', 'yy.ast.set({ expression: { type: "identifier", value: $1 } })'], ['SCRIPT_EXPRESSION', 'yy.ast.set({ expression: { type: "script_expression", value: $1 } })'], ['INTEGER', 'yy.ast.set({ expression: { type: "numeric_literal", value: parseInt($1) } })'], ['END', ''] ], SUBSCRIPT_COMPONENT: [ ['CHILD_SUBSCRIPT_COMPONENT', 'yy.ast.set({ scope: "child" })'], ['DESCENDANT_SUBSCRIPT_COMPONENT', 'yy.ast.set({ scope: "descendant" })'] ], CHILD_SUBSCRIPT_COMPONENT: [ ['[ SUBSCRIPT ]', ''] ], DESCENDANT_SUBSCRIPT_COMPONENT: [ ['DOT_DOT [ SUBSCRIPT ]', ''] ], SUBSCRIPT: [ ['SUBSCRIPT_EXPRESSION', ''], ['SUBSCRIPT_EXPRESSION_LIST', '$1.length > 1? yy.ast.set({ expression: { type: "union", value: $1 } }) : $$ = $1'] ], SUBSCRIPT_EXPRESSION_LIST: [ ['SUBSCRIPT_EXPRESSION_LISTABLE', '$$ = [$1]'], ['SUBSCRIPT_EXPRESSION_LIST , SUBSCRIPT_EXPRESSION_LISTABLE', '$$ = $1.concat($3)'] ], SUBSCRIPT_EXPRESSION_LISTABLE: [ ['INTEGER', '$$ = { expression: { type: "numeric_literal", value: parseInt($1) } }; yy.ast.set($$)'], ['STRING_LITERAL', '$$ = { expression: { type: "string_literal", value: $1 } }; yy.ast.set($$)'], ['ARRAY_SLICE', '$$ = { expression: { type: "slice", value: $1 } }; yy.ast.set($$)'] ], SUBSCRIPT_EXPRESSION: [ ['STAR', '$$ = { expression: { type: "wildcard", value: $1 } }; yy.ast.set($$)'], ['SCRIPT_EXPRESSION', '$$ = { expression: { type: "script_expression", value: $1 } }; yy.ast.set($$)'], ['FILTER_EXPRESSION', '$$ = { expression: { type: "filter_expression", value: $1 } }; yy.ast.set($$)'] ], STRING_LITERAL: [ ['QQ_STRING', "$$ = $1"], ['Q_STRING', "$$ = $1"] ] }, moduleInclude: null, actionInclude: null }; grammar.moduleInclude = fs.readFileSync(path.join(__dirname, '..', 'include', 'module.js')).toString(); grammar.actionInclude = fs.readFileSync(path.join(__dirname, '..', 'include', 'action.js')).toString(); /** * @internal * @hidden */ exports.GRAMMAR = grammar; //# sourceMappingURL=grammar.js.map