@thinql/parse
Version:
Parse ThinQL queries to ASTs
330 lines (307 loc) • 10.3 kB
JavaScript
"use strict";
var _Assertion = _interopRequireDefault(require("./types/Assertion.js"));
var _Call = _interopRequireDefault(require("./types/Call.js"));
var _Comparison = _interopRequireDefault(require("./types/Comparison.js"));
var _FullTextSearch = _interopRequireDefault(require("./types/FullTextSearch.js"));
var _lexer = _interopRequireDefault(require("./lexer.js"));
var _LogicalAndExpression = _interopRequireDefault(require("./types/LogicalAndExpression.js"));
var _LogicalOrExpression = _interopRequireDefault(require("./types/LogicalOrExpression.js"));
var _Property = _interopRequireDefault(require("./types/Property.js"));
var _Statement = _interopRequireDefault(require("./types/Statement.js"));
var _Value = _interopRequireDefault(require("./types/Value.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Generated automatically by nearley, version 2.16.0
// http://github.com/Hardmath123/nearley
(function () {
function id(x) {
return x[0];
}
var grammar = {
Lexer: _lexer.default,
ParserRules: [{
"name": "main",
"symbols": ["Statement"],
"postprocess": ([statement]) => statement
}, {
"name": "_$subexpression$1",
"symbols": []
}, {
"name": "_$subexpression$1",
"symbols": [_lexer.default.has("whitespace") ? {
type: "whitespace"
} : whitespace]
}, {
"name": "_",
"symbols": ["_$subexpression$1"],
"postprocess": () => null
}, {
"name": "__",
"symbols": [_lexer.default.has("whitespace") ? {
type: "whitespace"
} : whitespace],
"postprocess": () => true
}, {
"name": "callee",
"symbols": [_lexer.default.has("unquotedString") ? {
type: "unquotedString"
} : unquotedString],
"postprocess": ([callee]) => callee
}, {
"name": "comparisonOperator",
"symbols": [_lexer.default.has("comparisonOperator") ? {
type: "comparisonOperator"
} : comparisonOperator],
"postprocess": ([comparisonOperator]) => comparisonOperator
}, {
"name": "negator",
"symbols": [_lexer.default.has("negator") ? {
type: "negator"
} : negator],
"postprocess": ([negator]) => negator
}, {
"name": "string$subexpression$1",
"symbols": [_lexer.default.has("quotedString") ? {
type: "quotedString"
} : quotedString]
}, {
"name": "string$subexpression$1",
"symbols": [_lexer.default.has("unquotedString") ? {
type: "unquotedString"
} : unquotedString]
}, {
"name": "string",
"symbols": ["string$subexpression$1"],
"postprocess": ([[string]]) => string
}, {
"name": "_Argument$subexpression$1",
"symbols": ["Call"]
}, {
"name": "_Argument$subexpression$1",
"symbols": ["Value"]
}, {
"name": "_Argument",
"symbols": ["_Argument$subexpression$1"],
"postprocess": ([[argument]]) => argument
}, {
"name": "_LogicalExpression$subexpression$1",
"symbols": ["LogicalAndExpression"]
}, {
"name": "_LogicalExpression$subexpression$1",
"symbols": ["LogicalOrExpression"]
}, {
"name": "_LogicalExpression",
"symbols": ["_LogicalExpression$subexpression$1"],
"postprocess": ([[expression]]) => expression
}, {
"name": "Assertion$ebnf$1",
"symbols": ["negator"],
"postprocess": id
}, {
"name": "Assertion$ebnf$1",
"symbols": [],
"postprocess": function (d) {
return null;
}
}, {
"name": "Assertion$subexpression$1",
"symbols": ["Comparison"]
}, {
"name": "Assertion$subexpression$1$subexpression$1",
"symbols": [_lexer.default.has("openBracket") ? {
type: "openBracket"
} : openBracket, "_", "_LogicalExpression", "_", _lexer.default.has("closeBracket") ? {
type: "closeBracket"
} : closeBracket]
}, {
"name": "Assertion$subexpression$1",
"symbols": ["Assertion$subexpression$1$subexpression$1"]
}, {
"name": "Assertion$subexpression$1",
"symbols": ["Call"]
}, {
"name": "Assertion$subexpression$1",
"symbols": ["FullTextSearch"]
}, {
"name": "Assertion",
"symbols": ["Assertion$ebnf$1", "_", "Assertion$subexpression$1"],
"postprocess": ([negator,, [assertionGroup]]) => {
let assertion = assertionGroup;
let openBracket;
if (Array.isArray(assertion)) {
[openBracket,, assertion] = assertionGroup;
}
return new _Assertion.default({
assertion,
negated: negator !== null
}, negator || openBracket || assertion);
}
}, {
"name": "Call$ebnf$1$subexpression$1$ebnf$1",
"symbols": []
}, {
"name": "Call$ebnf$1$subexpression$1$ebnf$1$subexpression$1",
"symbols": ["__", "_Argument"]
}, {
"name": "Call$ebnf$1$subexpression$1$ebnf$1",
"symbols": ["Call$ebnf$1$subexpression$1$ebnf$1", "Call$ebnf$1$subexpression$1$ebnf$1$subexpression$1"],
"postprocess": function arrpush(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "Call$ebnf$1$subexpression$1",
"symbols": ["_Argument", "Call$ebnf$1$subexpression$1$ebnf$1"]
}, {
"name": "Call$ebnf$1",
"symbols": ["Call$ebnf$1$subexpression$1"],
"postprocess": id
}, {
"name": "Call$ebnf$1",
"symbols": [],
"postprocess": function (d) {
return null;
}
}, {
"name": "Call",
"symbols": ["callee", _lexer.default.has("openBracket") ? {
type: "openBracket"
} : openBracket, "_", "Call$ebnf$1", "_", _lexer.default.has("closeBracket") ? {
type: "closeBracket"
} : closeBracket],
"postprocess": ([callee,,, argList]) => {
const args = [];
if (argList) {
const [firstArgument, moreArguments] = argList;
args.push(firstArgument);
if (moreArguments) {
for (const [, argument] of moreArguments) {
args.push(argument);
}
}
}
return new _Call.default({
arguments: args,
callee: callee.value
}, callee);
}
}, {
"name": "Comparison$subexpression$1",
"symbols": ["Call"]
}, {
"name": "Comparison$subexpression$1",
"symbols": ["Property"]
}, {
"name": "Comparison",
"symbols": ["Comparison$subexpression$1", "_", "comparisonOperator", "_", "_Argument"],
"postprocess": ([[left],, {
value: comparisonOperator
},, right]) => new _Comparison.default({
comparisonOperator,
left,
right
}, left)
}, {
"name": "FullTextSearch",
"symbols": ["Value"],
"postprocess": ([value]) => new _FullTextSearch.default({
value
}, value)
}, {
"name": "LogicalAndExpression$ebnf$1$subexpression$1",
"symbols": ["__", "Assertion"]
}, {
"name": "LogicalAndExpression$ebnf$1",
"symbols": ["LogicalAndExpression$ebnf$1$subexpression$1"]
}, {
"name": "LogicalAndExpression$ebnf$1$subexpression$2",
"symbols": ["__", "Assertion"]
}, {
"name": "LogicalAndExpression$ebnf$1",
"symbols": ["LogicalAndExpression$ebnf$1", "LogicalAndExpression$ebnf$1$subexpression$2"],
"postprocess": function arrpush(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "LogicalAndExpression",
"symbols": ["Assertion", "LogicalAndExpression$ebnf$1"],
"postprocess": ([firstAssertion, moreAssertions]) => {
const assertions = [firstAssertion];
for (const [, assertion] of moreAssertions) {
assertions.push(assertion);
}
return new _LogicalAndExpression.default({
assertions
}, assertions[0]);
}
}, {
"name": "LogicalOrExpression$ebnf$1$subexpression$1",
"symbols": ["__", _lexer.default.has("logicalOrOperator") ? {
type: "logicalOrOperator"
} : logicalOrOperator, "__", "Assertion"]
}, {
"name": "LogicalOrExpression$ebnf$1",
"symbols": ["LogicalOrExpression$ebnf$1$subexpression$1"]
}, {
"name": "LogicalOrExpression$ebnf$1$subexpression$2",
"symbols": ["__", _lexer.default.has("logicalOrOperator") ? {
type: "logicalOrOperator"
} : logicalOrOperator, "__", "Assertion"]
}, {
"name": "LogicalOrExpression$ebnf$1",
"symbols": ["LogicalOrExpression$ebnf$1", "LogicalOrExpression$ebnf$1$subexpression$2"],
"postprocess": function arrpush(d) {
return d[0].concat([d[1]]);
}
}, {
"name": "LogicalOrExpression",
"symbols": ["Assertion", "LogicalOrExpression$ebnf$1"],
"postprocess": ([firstAssertion, moreAssertions]) => {
const assertions = [firstAssertion];
for (const [,,, assertion] of moreAssertions) {
assertions.push(assertion);
}
return new _LogicalOrExpression.default({
assertions
}, assertions[0]);
}
}, {
"name": "Property",
"symbols": ["string"],
"postprocess": ([content]) => new _Property.default({
content: content.value
}, content)
}, {
"name": "Statement$subexpression$1",
"symbols": ["_LogicalExpression"]
}, {
"name": "Statement$subexpression$1",
"symbols": ["Assertion"]
}, {
"name": "Statement",
"symbols": ["_", "Statement$subexpression$1", "_"],
"postprocess": ([, [expression]]) => new _Statement.default({
expression
}, expression)
}, {
"name": "Value",
"symbols": ["string"],
"postprocess": ([content]) => {
const {
type,
value
} = content;
const literal = type === 'quotedString';
return new _Value.default({
content: value,
literal
}, content);
}
}],
ParserStart: "main"
};
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = grammar;
} else {
window.grammar = grammar;
}
})();
//# sourceMappingURL=grammar.js.map