├── index.js
├── .gitignore
├── .babelrc
├── .github
├── dependabot.yml.bak
└── workflows
│ └── main.yml
├── compile-parser.js
├── src
├── sql_parser.js
├── parser.js
├── lexer.js
├── nodes.js
├── grammar.js
└── compiled_parser.js
├── rollup.config.js
├── browser
├── example.html
└── sql-parser.js
├── LICENSE
├── package.json
├── README.md
└── test
├── parser.spec.js
├── lexer.spec.js
├── __snapshots__
└── grammar.spec.js.snap
└── grammar.spec.js
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./src/sql_parser');
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 | *.swp
4 | *.iml
5 | .idea
6 | yarn.lock
7 |
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | [
4 | "@babel/env",
5 | {
6 | "loose": true,
7 | "modules": false
8 | }
9 | ]
10 | ]
11 | }
--------------------------------------------------------------------------------
/.github/dependabot.yml.bak:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "04:00"
8 | open-pull-requests-limit: 10
9 |
--------------------------------------------------------------------------------
/compile-parser.js:
--------------------------------------------------------------------------------
1 | const fs = require('fs');
2 |
3 | const parser = require('./src/grammar').parser;
4 |
5 | const code = `${parser.generate()}
6 |
7 | exports.parser = parser;`;
8 |
9 | fs.writeFileSync('src/compiled_parser.js', code);
10 |
--------------------------------------------------------------------------------
/src/sql_parser.js:
--------------------------------------------------------------------------------
1 | exports.lexer = require('./lexer');
2 | exports.parser = require('./parser');
3 | exports.nodes = require('./nodes');
4 |
5 | exports.parse = function (sql) {
6 | return exports.parser.parse(exports.lexer.tokenize(sql));
7 | };
8 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | build:
7 |
8 | runs-on: ubuntu-latest
9 |
10 | steps:
11 | - uses: actions/checkout@v1
12 | - name: build
13 | run: |
14 | npm install
15 | npm run compile
16 | npm run test
17 |
--------------------------------------------------------------------------------
/src/parser.js:
--------------------------------------------------------------------------------
1 | const parser = require('./compiled_parser').parser;
2 | const nodes = require('./nodes');
3 |
4 | parser.lexer = {
5 | lex : function () {
6 | let tag;
7 | [tag, this.yytext, this.yylineno] = this.tokens[this.pos++] || [''];
8 | return tag;
9 | },
10 | setInput : function (tokens) {
11 | this.tokens = tokens;
12 | return this.pos = 0;
13 | },
14 | upcomingInput: function () {
15 | return '';
16 | }
17 | };
18 |
19 | parser.yy = nodes;
20 |
21 | exports.parser = parser;
22 |
23 | exports.parse = function (str) {
24 | return parser.parse(str);
25 | };
26 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import babel from 'rollup-plugin-babel';
2 | import commonjs from 'rollup-plugin-commonjs';
3 |
4 | const pkg = require('./package.json');
5 |
6 | export default {
7 | input : 'src/sql_parser.js',
8 | output : {
9 | file : 'browser/sql-parser.js',
10 | name : 'SQLParser',
11 | exports: 'named',
12 | format : 'umd',
13 | sourcemap: true,
14 | banner : `/*!
15 | * SQLParser (v${pkg.version})
16 | * @copyright 2012-2015 ${pkg.author.name} <${pkg.author.email}>
17 | * @copyright 2015-${new Date().getFullYear()} ${pkg.contributors[0].name} <${pkg.contributors[0].email}>
18 | * @licence ${pkg.license}
19 | */`,
20 | },
21 | plugins : [
22 | commonjs(),
23 | babel({
24 | exclude: 'node_modules/**',
25 | }),
26 | ]
27 | };
28 |
--------------------------------------------------------------------------------
/browser/example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SQLParser
5 |
6 | Input
7 |
8 |
9 |
10 | Tokens
11 |
12 |
13 | Parsed
14 |
15 |
16 | Output
17 |
18 |
19 |
20 |
21 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2012 Andrew Kent
2 | Copyright (c) 2016-2019 Damien "Mistic" Sorel
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 |
6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 |
8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sql-parser-mistic",
3 | "description": "Lexer and Parser for SQL Syntax",
4 | "version": "1.3.0",
5 | "author": {
6 | "name": "Andy Kent",
7 | "email": "andy@forward.co.uk"
8 | },
9 | "contributors": [
10 | {
11 | "name": "Damien \"Mistic\" Sorel",
12 | "email": "contact@git.strangeplanet.fr",
13 | "url": "https://www.strangeplanet.fr"
14 | }
15 | ],
16 | "files": [
17 | "index.js",
18 | "src/",
19 | "browser/"
20 | ],
21 | "keywords": [
22 | "sql",
23 | "lexer",
24 | "parser",
25 | "ast"
26 | ],
27 | "devDependencies": {
28 | "@babel/core": "^7.2.2",
29 | "@babel/preset-env": "^7.2.3",
30 | "jest": "^28.0.0",
31 | "jison": "0.4.18",
32 | "rollup": "^2.0.2",
33 | "rollup-plugin-babel": "^4.3.0",
34 | "rollup-plugin-commonjs": "^10.0.0"
35 | },
36 | "license": "MIT",
37 | "homepage": "https://github.com/mistic100/sql-parser",
38 | "repository": {
39 | "type": "git",
40 | "url": "http://github.com/mistic100/sql-parser.git"
41 | },
42 | "scripts": {
43 | "compile": "node compile-parser.js && rollup --config rollup.config.js",
44 | "test": "jest"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SQL Parser
2 | ==========
3 |
4 | [](https://www.npmjs.com/package/sql-parser-mistic)
5 | [](https://www.jsdelivr.com/package/npm/sql-parser-mistic)
6 | [](https://bundlephobia.com/result?p=sql-parser-mistic)
7 | [](https://github.com/mistic100/sql-parser/actions)
8 |
9 | SQL Parser is a lexer, grammar and parser for SQL written in JS. Currently it is only capable of parsing fairly basic SELECT queries but full SQL support will hopefully come in time. See the specs for examples of currently supported queries.
10 |
11 |
12 | Installation
13 | ----------
14 |
15 | The package is distributed on NPM and can be installed with...
16 |
17 | npm install sql-parser-mistic
18 |
19 | To build from source you'll need to run the following from the root of the project...
20 |
21 | npm install
22 | npm run compile
23 |
24 | Tests are written using Mocha and can be run with...
25 |
26 | npm test
27 |
28 |
29 | Lexer
30 | -----
31 |
32 | The lexer takes a SQL query string as input and returns a stream of tokens in the format
33 |
34 | ['NAME', 'value', lineNumber]
35 |
36 | Here is a simple example...
37 |
38 | lexer.tokenize('select * from my_table')
39 |
40 | [
41 | ['SELECT','select',1],
42 | ['STAR','*',1],
43 | ['FROM','from',1],
44 | ['LITERAL','my_table',1]
45 | ]
46 |
47 | The tokenized output is in a format compatible with JISON.
48 |
49 |
50 | Parser
51 | ------
52 |
53 | The parser only currently supports SELECT queries but is able to produce a Select object with properties for where, group, order, limit. See lib/nodes.coffee for more info of the returned object structure. Calling .toString() on a Select object should give you back a well formatted version of the original SQL input.
54 |
55 | tokens = lexer.tokenize("select * from my_table where foo = 'bar'")
56 | parser.parse(tokens).toString()
57 |
58 | SELECT *
59 | FROM `my_table`
60 | WHERE `foo` = 'bar'
61 |
62 |
63 | Contributions
64 | -------------
65 |
66 | Contributions in the form of pull requests that add syntax support are very welcome but should be supported by both Lexer and Parser level tests.
67 |
--------------------------------------------------------------------------------
/test/parser.spec.js:
--------------------------------------------------------------------------------
1 | const lexer = require('../src/lexer');
2 | const parser = require('../src/parser');
3 | const nodes = require('../src/nodes');
4 |
5 | function parse(query) {
6 | return parser.parse(lexer.tokenize(query));
7 | }
8 |
9 | describe('SQL Parser', function () {
10 | it('parses simple query', function () {
11 | const ast = parse('SELECT * FROM my_table');
12 | expect(ast).toEqual({
13 | 'distinct': false,
14 | 'fields' : [new nodes.Star],
15 | 'group' : null,
16 | 'joins' : [],
17 | 'limit' : null,
18 | 'order' : null,
19 | 'source' : new nodes.Table(new nodes.LiteralValue('my_table'), null),
20 | 'unions' : [],
21 | 'where' : null
22 | });
23 | });
24 |
25 | it('parses ORDER BY clauses', function () {
26 | const ast = parse('SELECT * FROM my_table ORDER BY x DESC');
27 | expect(ast.order).toEqual(
28 | new nodes.Order([
29 | new nodes.OrderArgument(new nodes.LiteralValue('x'), 'DESC')
30 | ])
31 | );
32 | });
33 |
34 | it('parses WHERE with function call', function () {
35 | const ast = parse('SELECT * FROM my_table WHERE foo < NOW()');
36 | expect(ast.where).toEqual(
37 | new nodes.Where(
38 | new nodes.Op('<',
39 | new nodes.LiteralValue('foo'),
40 | new nodes.FunctionValue('NOW', null, true))
41 | )
42 | );
43 | });
44 |
45 | it('parses basic WHERE', function () {
46 | const ast = parse('SELECT * FROM my_table WHERE id >= 5 AND name LIKE \'foo\' AND ( bar IS NOT NULL OR date BETWEEN 41 AND 43 )');
47 | expect(ast.where).toEqual(
48 | new nodes.Where(
49 | new nodes.Op('AND',
50 | new nodes.Op('AND',
51 | new nodes.Op('>=',
52 | new nodes.LiteralValue('id'),
53 | new nodes.NumberValue(5)
54 | ),
55 | new nodes.Op('LIKE',
56 | new nodes.LiteralValue('name'),
57 | new nodes.StringValue('foo', '\'')
58 | )
59 | ),
60 | new nodes.Op('OR',
61 | new nodes.Op('IS NOT',
62 | new nodes.LiteralValue('bar'),
63 | new nodes.BooleanValue('NULL')
64 | ),
65 | new nodes.Op('BETWEEN',
66 | new nodes.LiteralValue('date'),
67 | new nodes.BetweenOp([
68 | new nodes.NumberValue(41),
69 | new nodes.NumberValue(43)
70 | ])
71 | )
72 | )
73 | )
74 | )
75 | );
76 | });
77 |
78 | it('parses function with complex arguments', function () {
79 | const ast = parse('SELECT * FROM my_table WHERE foo < DATE_SUB(NOW(), INTERVAL 14 DAYS)');
80 | expect(ast.where.conditions.right).toEqual(
81 | new nodes.FunctionValue('DATE_SUB',
82 | new nodes.ArgumentListValue([
83 | new nodes.FunctionValue('NOW', null, true),
84 | new nodes.WhitepaceList([
85 | new nodes.LiteralValue('INTERVAL'),
86 | new nodes.NumberValue(14),
87 | new nodes.LiteralValue('DAYS')
88 | ],
89 | true
90 | )
91 | ]),
92 | true
93 | )
94 | );
95 | });
96 | });
97 |
--------------------------------------------------------------------------------
/test/lexer.spec.js:
--------------------------------------------------------------------------------
1 | const lexer = require('../src/lexer');
2 |
3 | // removes the last two params of each token (line and offset)
4 | function clean(tokens) {
5 | return tokens.map(function (token) {
6 | return token.slice(0, 2);
7 | });
8 | }
9 |
10 | describe('SQL Lexer', function () {
11 | it('eats select queries', function () {
12 | const tokens = clean(lexer.tokenize('select * from my_table'));
13 | expect(tokens).toEqual([
14 | ['SELECT', 'select'],
15 | ['STAR', '*'],
16 | ['FROM', 'from'],
17 | ['LITERAL', 'my_table'],
18 | ['EOF', '']
19 | ]);
20 | });
21 |
22 | it('eats select queries with named values', function () {
23 | const tokens = clean(lexer.tokenize('select foo , bar from my_table'));
24 | expect(tokens).toEqual([
25 | ['SELECT', 'select'],
26 | ['LITERAL', 'foo'],
27 | ['SEPARATOR', ','],
28 | ['LITERAL', 'bar'],
29 | ['FROM', 'from'],
30 | ['LITERAL', 'my_table'],
31 | ['EOF', '']
32 | ]);
33 | });
34 |
35 | it('eats select queries with named typed values', function () {
36 | const tokens = clean(lexer.tokenize('select foo:boolean, bar:number from my_table'));
37 | expect(tokens).toEqual([
38 | ['SELECT', 'select'],
39 | ['LITERAL', 'foo:boolean'],
40 | ['SEPARATOR', ','],
41 | ['LITERAL', 'bar:number'],
42 | ['FROM', 'from'],
43 | ['LITERAL', 'my_table'],
44 | ['EOF', '']
45 | ]);
46 | });
47 |
48 | it('eats select queries with with parameter', function () {
49 | const tokens = clean(lexer.tokenize('select * from my_table where a = $foo'));
50 | expect(tokens).toEqual([
51 | ['SELECT', 'select'],
52 | ['STAR', '*'],
53 | ['FROM', 'from'],
54 | ['LITERAL', 'my_table'],
55 | ['WHERE', 'where'],
56 | ['LITERAL', 'a'],
57 | ['OPERATOR', '='],
58 | ['PARAMETER', 'foo'],
59 | ['EOF', '']
60 | ]);
61 | });
62 |
63 | it('eats select queries with with parameter and type', function () {
64 | const tokens = clean(lexer.tokenize('select * from my_table where a = $foo:number'));
65 | expect(tokens).toEqual([
66 | ['SELECT', 'select'],
67 | ['STAR', '*'],
68 | ['FROM', 'from'],
69 | ['LITERAL', 'my_table'],
70 | ['WHERE', 'where'],
71 | ['LITERAL', 'a'],
72 | ['OPERATOR', '='],
73 | ['PARAMETER', 'foo:number'],
74 | ['EOF', '']
75 | ]);
76 | });
77 |
78 | it('eats select queries with stars and multiplication', function () {
79 | const tokens = clean(lexer.tokenize('select * from my_table where foo = 1 * 2'));
80 | expect(tokens).toEqual([
81 | ['SELECT', 'select'],
82 | ['STAR', '*'],
83 | ['FROM', 'from'],
84 | ['LITERAL', 'my_table'],
85 | ['WHERE', 'where'],
86 | ['LITERAL', 'foo'],
87 | ['OPERATOR', '='],
88 | ['NUMBER', '1'],
89 | ['MATH_MULTI', '*'],
90 | ['NUMBER', '2'],
91 | ['EOF', '']
92 | ]);
93 | });
94 |
95 | it('eats select queries with negative numbers', function () {
96 | const tokens = clean(lexer.tokenize('select * from my_table where foo < -5'));
97 | expect(tokens).toEqual([
98 | ['SELECT', 'select'],
99 | ['STAR', '*'],
100 | ['FROM', 'from'],
101 | ['LITERAL', 'my_table'],
102 | ['WHERE', 'where'],
103 | ['LITERAL', 'foo'],
104 | ['OPERATOR', '<'],
105 | ['NUMBER', '-5'],
106 | ['EOF', '']
107 | ]);
108 | });
109 |
110 | it('eats select queries with negative numbers and minus sign', function () {
111 | const tokens = clean(lexer.tokenize('select * from my_table where foo < -5 - 5'));
112 | expect(tokens).toEqual([
113 | ['SELECT', 'select'],
114 | ['STAR', '*'],
115 | ['FROM', 'from'],
116 | ['LITERAL', 'my_table'],
117 | ['WHERE', 'where'],
118 | ['LITERAL', 'foo'],
119 | ['OPERATOR', '<'],
120 | ['NUMBER', '-5'],
121 | ['MATH', '-'],
122 | ['NUMBER', '5'],
123 | ['EOF', '']
124 | ]);
125 | });
126 |
127 | it('eats sub selects', function () {
128 | const tokens = clean(lexer.tokenize('select * from (select * from my_table) t'));
129 | expect(tokens).toEqual([
130 | ['SELECT', 'select'],
131 | ['STAR', '*'],
132 | ['FROM', 'from'],
133 | ['LEFT_PAREN', '('],
134 | ['SELECT', 'select'],
135 | ['STAR', '*'],
136 | ['FROM', 'from'],
137 | ['LITERAL', 'my_table'],
138 | ['RIGHT_PAREN', ')'],
139 | ['LITERAL', 't'],
140 | ['EOF', '']
141 | ]);
142 | });
143 |
144 | it('eats joins', function () {
145 | const tokens = clean(lexer.tokenize('select * from a join b on a.id = b.id'));
146 | expect(tokens).toEqual([
147 | ['SELECT', 'select'],
148 | ['STAR', '*'],
149 | ['FROM', 'from'],
150 | ['LITERAL', 'a'],
151 | ['JOIN', 'join'],
152 | ['LITERAL', 'b'],
153 | ['ON', 'on'],
154 | ['LITERAL', 'a'],
155 | ['DOT', '.'],
156 | ['LITERAL', 'id'],
157 | ['OPERATOR', '='],
158 | ['LITERAL', 'b'],
159 | ['DOT', '.'],
160 | ['LITERAL', 'id'],
161 | ['EOF', '']
162 | ]);
163 | });
164 |
165 | it('eats insert queries', function () {
166 | const tokens = clean(lexer.tokenize('insert into my_table values (\'a\',1)'));
167 | expect(tokens).toEqual([
168 | ['INSERT', 'insert'],
169 | ['INTO', 'into'],
170 | ['LITERAL', 'my_table'],
171 | ['VALUES', 'values'],
172 | ['LEFT_PAREN', '('],
173 | ['STRING', 'a'],
174 | ['SEPARATOR', ','],
175 | ['NUMBER', '1'],
176 | ['RIGHT_PAREN', ')'],
177 | ['EOF', '']
178 | ]);
179 | });
180 |
181 | it('eats insert queries with default values', function () {
182 | const tokens = clean(lexer.tokenize('insert into my_table default values'));
183 | expect(tokens).toEqual([
184 | ['INSERT', 'insert'],
185 | ['INTO', 'into'],
186 | ['LITERAL', 'my_table'],
187 | ['DEFAULT', 'default'],
188 | ['VALUES', 'values'],
189 | ['EOF', '']
190 | ]);
191 | });
192 |
193 | it('eats insert queries with multiple rows', function () {
194 | const tokens = clean(lexer.tokenize('insert into my_table values (\'a\'),(\'b\')'));
195 | expect(tokens).toEqual([
196 | ['INSERT', 'insert'],
197 | ['INTO', 'into'],
198 | ['LITERAL', 'my_table'],
199 | ['VALUES', 'values'],
200 | ['LEFT_PAREN', '('],
201 | ['STRING', 'a'],
202 | ['RIGHT_PAREN', ')'],
203 | ['SEPARATOR', ','],
204 | ['LEFT_PAREN', '('],
205 | ['STRING', 'b'],
206 | ['RIGHT_PAREN', ')'],
207 | ['EOF', '']
208 | ]);
209 | });
210 |
211 | it('eats insert queries with multiple rows and column names', function () {
212 | const tokens = clean(lexer.tokenize('insert into my_table (foo) values (\'a\'),(\'b\')'));
213 | expect(tokens).toEqual([
214 | ['INSERT', 'insert'],
215 | ['INTO', 'into'],
216 | ['LITERAL', 'my_table'],
217 | ['LEFT_PAREN', '('],
218 | ['LITERAL', 'foo'],
219 | ['RIGHT_PAREN', ')'],
220 | ['VALUES', 'values'],
221 | ['LEFT_PAREN', '('],
222 | ['STRING', 'a'],
223 | ['RIGHT_PAREN', ')'],
224 | ['SEPARATOR', ','],
225 | ['LEFT_PAREN', '('],
226 | ['STRING', 'b'],
227 | ['RIGHT_PAREN', ')'],
228 | ['EOF', '']
229 | ]);
230 | });
231 |
232 | it('eats case when', function () {
233 | const tokens = clean(lexer.tokenize('select case when foo = \'a\' then a when foo = \'b\' then b else c end from table'));
234 | expect(tokens).toEqual([
235 | ['SELECT', 'select'],
236 | ['CASE', 'case'],
237 | ['WHEN', 'when'],
238 | ['LITERAL', 'foo'],
239 | ['OPERATOR', '='],
240 | ['STRING', 'a'],
241 | ['THEN', 'then'],
242 | ['LITERAL', 'a'],
243 | ['WHEN', 'when'],
244 | ['LITERAL', 'foo'],
245 | ['OPERATOR', '='],
246 | ['STRING', 'b'],
247 | ['THEN', 'then'],
248 | ['LITERAL', 'b'],
249 | ['ELSE', 'else'],
250 | ['LITERAL', 'c'],
251 | ['END', 'end'],
252 | ['FROM', 'from'],
253 | ['LITERAL', 'table'],
254 | ['EOF', '']
255 | ]);
256 | });
257 |
258 | });
259 |
260 |
--------------------------------------------------------------------------------
/src/lexer.js:
--------------------------------------------------------------------------------
1 | const SQL_FUNCTIONS = ['AVG', 'COUNT', 'MIN', 'MAX', 'SUM'];
2 | const SQL_SORT_ORDERS = ['ASC', 'DESC'];
3 | const SQL_OPERATORS = ['=', '!=', '>=', '>', '<=', '<>', '<', 'LIKE', 'NOT LIKE', 'ILIKE', 'NOT ILIKE', 'IS NOT', 'IS', 'REGEXP', 'NOT REGEXP'];
4 | const SUB_SELECT_OP = ['IN', 'NOT IN', 'ANY', 'ALL', 'SOME'];
5 | const SUB_SELECT_UNARY_OP = ['EXISTS'];
6 | const SQL_CONDITIONALS = ['AND', 'OR'];
7 | const SQL_BETWEENS = ['BETWEEN', 'NOT BETWEEN'];
8 | const BOOLEAN = ['TRUE', 'FALSE', 'NULL'];
9 | const MATH = ['+', '-', '||', '&&'];
10 | const MATH_MULTI = ['/', '*'];
11 | const STAR = /^\*/;
12 | const SEPARATOR = /^,/;
13 | const WHITESPACE = /^[ \n\r]+/;
14 | const LITERAL = /^`?([a-z_][a-z0-9_]{0,}(\:(number|float|string|date|boolean))?)`?/i;
15 | const PARAMETER = /^\$([a-z0-9_]+(\:(number|float|string|date|boolean))?)/;
16 | const NUMBER = /^[+-]?[0-9]+(\.[0-9]+)?/;
17 | const STRING = /^'((?:[^\\']+?|\\.|'')*)'(?!')/;
18 | const DBLSTRING = /^"([^\\"]*(?:\\.[^\\"]*)*)"/;
19 |
20 | class Lexer {
21 |
22 | constructor(sql, opts = {}) {
23 | this.sql = sql;
24 | this.preserveWhitespace = opts.preserveWhitespace || false;
25 | this.tokens = [];
26 | this.currentLine = 1;
27 | this.currentOffset = 0;
28 |
29 | let i = 0;
30 | while (!!(this.chunk = sql.slice(i))) {
31 | const bytesConsumed = this.keywordToken() ||
32 | this.starToken() ||
33 | this.booleanToken() ||
34 | this.functionToken() ||
35 | this.windowExtension() ||
36 | this.sortOrderToken() ||
37 | this.seperatorToken() ||
38 | this.operatorToken() ||
39 | this.numberToken() ||
40 | this.mathToken() ||
41 | this.dotToken() ||
42 | this.conditionalToken() ||
43 | this.betweenToken() ||
44 | this.subSelectOpToken() ||
45 | this.subSelectUnaryOpToken() ||
46 | this.stringToken() ||
47 | this.parameterToken() ||
48 | this.parensToken() ||
49 | this.whitespaceToken() ||
50 | this.literalToken();
51 |
52 | if (bytesConsumed < 1) {
53 | throw new Error(`NOTHING CONSUMED: Stopped at - '${this.chunk.slice(0, 30)}'`);
54 | }
55 |
56 | i += bytesConsumed;
57 | this.currentOffset += bytesConsumed;
58 | }
59 |
60 | this.token('EOF', '');
61 | this.postProcess();
62 | }
63 |
64 | postProcess() {
65 | const results = [];
66 | for (let i =0, j = 0, len = this.tokens.length; j < len; i = ++j) {
67 | const token = this.tokens[i];
68 | if (token[0] === 'STAR') {
69 | const next_token = this.tokens[i + 1];
70 | if (!(next_token[0] === 'SEPARATOR' || next_token[0] === 'FROM')) {
71 | results.push(token[0] = 'MATH_MULTI');
72 | }
73 | else {
74 | results.push(void 0);
75 | }
76 | }
77 | else {
78 | results.push(void 0);
79 | }
80 | }
81 | return results;
82 | }
83 |
84 | token(name, value) {
85 | return this.tokens.push([name, value, this.currentLine, this.currentOffset]);
86 | }
87 |
88 | tokenizeFromStringRegex(name, regex, part = 0, lengthPart = part, output = true) {
89 | const match = regex.exec(this.chunk);
90 | if (!match) {
91 | return 0;
92 | }
93 | const partMatch = match[part].replace(/''/g, '\'');
94 | if (output) {
95 | this.token(name, partMatch);
96 | }
97 | return match[lengthPart].length;
98 | }
99 |
100 | tokenizeFromRegex(name, regex, part = 0, lengthPart = part, output = true) {
101 | const match = regex.exec(this.chunk);
102 | if (!match) {
103 | return 0;
104 | }
105 | const partMatch = match[part];
106 | if (output) {
107 | this.token(name, partMatch);
108 | }
109 | return match[lengthPart].length;
110 | }
111 |
112 | tokenizeFromWord(name, word = name) {
113 | word = this.regexEscape(word);
114 | const matcher = /^\w+$/.test(word) ? new RegExp(`^(${word})\\b`, 'ig') : new RegExp(`^(${word})`, 'ig');
115 | const match = matcher.exec(this.chunk);
116 | if (!match) {
117 | return 0;
118 | }
119 | this.token(name, match[1]);
120 | return match[1].length;
121 | }
122 |
123 | tokenizeFromList(name, list) {
124 | let ret = 0;
125 | for (let j = 0, len = list.length; j < len; j++) {
126 | const entry = list[j];
127 | ret = this.tokenizeFromWord(name, entry);
128 | if (ret > 0) {
129 | break;
130 | }
131 | }
132 | return ret;
133 | }
134 |
135 | keywordToken() {
136 | return this.tokenizeFromWord('SELECT') ||
137 | this.tokenizeFromWord('INSERT') ||
138 | this.tokenizeFromWord('INTO') ||
139 | this.tokenizeFromWord('DEFAULT') ||
140 | this.tokenizeFromWord('VALUES') ||
141 | this.tokenizeFromWord('DISTINCT') ||
142 | this.tokenizeFromWord('FROM') ||
143 | this.tokenizeFromWord('WHERE') ||
144 | this.tokenizeFromWord('GROUP') ||
145 | this.tokenizeFromWord('ORDER') ||
146 | this.tokenizeFromWord('BY') ||
147 | this.tokenizeFromWord('HAVING') ||
148 | this.tokenizeFromWord('LIMIT') ||
149 | this.tokenizeFromWord('JOIN') ||
150 | this.tokenizeFromWord('LEFT') ||
151 | this.tokenizeFromWord('RIGHT') ||
152 | this.tokenizeFromWord('INNER') ||
153 | this.tokenizeFromWord('OUTER') ||
154 | this.tokenizeFromWord('ON') ||
155 | this.tokenizeFromWord('AS') ||
156 | this.tokenizeFromWord('CASE') ||
157 | this.tokenizeFromWord('WHEN') ||
158 | this.tokenizeFromWord('THEN') ||
159 | this.tokenizeFromWord('ELSE') ||
160 | this.tokenizeFromWord('END') ||
161 | this.tokenizeFromWord('UNION') ||
162 | this.tokenizeFromWord('ALL') ||
163 | this.tokenizeFromWord('LIMIT') ||
164 | this.tokenizeFromWord('OFFSET') ||
165 | this.tokenizeFromWord('FETCH') ||
166 | this.tokenizeFromWord('ROW') ||
167 | this.tokenizeFromWord('ROWS') ||
168 | this.tokenizeFromWord('ONLY') ||
169 | this.tokenizeFromWord('NEXT') ||
170 | this.tokenizeFromWord('FIRST');
171 | }
172 |
173 | dotToken() {
174 | return this.tokenizeFromWord('DOT', '.');
175 | }
176 |
177 | operatorToken() {
178 | return this.tokenizeFromList('OPERATOR', SQL_OPERATORS);
179 | }
180 |
181 | mathToken() {
182 | return this.tokenizeFromList('MATH', MATH) || this.tokenizeFromList('MATH_MULTI', MATH_MULTI);
183 | }
184 |
185 | conditionalToken() {
186 | return this.tokenizeFromList('CONDITIONAL', SQL_CONDITIONALS);
187 | }
188 |
189 | betweenToken() {
190 | return this.tokenizeFromList('BETWEEN', SQL_BETWEENS);
191 | }
192 |
193 | subSelectOpToken() {
194 | return this.tokenizeFromList('SUB_SELECT_OP', SUB_SELECT_OP);
195 | }
196 |
197 | subSelectUnaryOpToken() {
198 | return this.tokenizeFromList('SUB_SELECT_UNARY_OP', SUB_SELECT_UNARY_OP);
199 | }
200 |
201 | functionToken() {
202 | return this.tokenizeFromList('FUNCTION', SQL_FUNCTIONS);
203 | }
204 |
205 | sortOrderToken() {
206 | return this.tokenizeFromList('DIRECTION', SQL_SORT_ORDERS);
207 | }
208 |
209 | booleanToken() {
210 | return this.tokenizeFromList('BOOLEAN', BOOLEAN);
211 | }
212 |
213 | starToken() {
214 | return this.tokenizeFromRegex('STAR', STAR);
215 | }
216 |
217 | seperatorToken() {
218 | return this.tokenizeFromRegex('SEPARATOR', SEPARATOR);
219 | }
220 |
221 | literalToken() {
222 | return this.tokenizeFromRegex('LITERAL', LITERAL, 1, 0);
223 | }
224 |
225 | numberToken() {
226 | return this.tokenizeFromRegex('NUMBER', NUMBER);
227 | }
228 |
229 | parameterToken() {
230 | return this.tokenizeFromRegex('PARAMETER', PARAMETER, 1, 0);
231 | }
232 |
233 | stringToken() {
234 | return this.tokenizeFromStringRegex('STRING', STRING, 1, 0) || this.tokenizeFromRegex('DBLSTRING', DBLSTRING, 1, 0);
235 | }
236 |
237 | parensToken() {
238 | return this.tokenizeFromRegex('LEFT_PAREN', /^\(/) || this.tokenizeFromRegex('RIGHT_PAREN', /^\)/);
239 | }
240 |
241 | windowExtension() {
242 | const match = /^\.(win):(length|time)/i.exec(this.chunk);
243 | if (!match) {
244 | return 0;
245 | }
246 | this.token('WINDOW', match[1]);
247 | this.token('WINDOW_FUNCTION', match[2]);
248 | return match[0].length;
249 | }
250 |
251 | whitespaceToken() {
252 | const match = WHITESPACE.exec(this.chunk);
253 | if (!match) {
254 | return 0;
255 | }
256 | const partMatch = match[0];
257 | if (this.preserveWhitespace) {
258 | this.token('WHITESPACE', partMatch);
259 | }
260 | const newlines = partMatch.match(/\n/g, '');
261 | this.currentLine += (newlines != null ? newlines.length : void 0) || 0;
262 | return partMatch.length;
263 | }
264 |
265 | regexEscape(str) {
266 | return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
267 | }
268 |
269 | }
270 |
271 | exports.tokenize = function (sql, opts) {
272 | return (new Lexer(sql, opts)).tokens;
273 | };
274 |
--------------------------------------------------------------------------------
/test/__snapshots__/grammar.spec.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`SQL Grammar Parameters parses query parameters 1`] = `
4 | "SELECT *
5 | FROM \`foo\`
6 | WHERE (\`bar\` = $12)"
7 | `;
8 |
9 | exports[`SQL Grammar SELECT Queries parses COUNT(DISTINCT field) 1`] = `
10 | "SELECT \`a\`, COUNT(DISTINCT \`b\`)
11 | FROM \`my_table\`
12 | LIMIT 10"
13 | `;
14 |
15 | exports[`SQL Grammar SELECT Queries parses GROUP BY and HAVING clauses 1`] = `
16 | "SELECT *
17 | FROM \`my_table\`
18 | GROUP BY \`x\`, \`y\`
19 | HAVING (COUNT(\`y\`) > 1)"
20 | `;
21 |
22 | exports[`SQL Grammar SELECT Queries parses GROUP BY clauses 1`] = `
23 | "SELECT *
24 | FROM \`my_table\`
25 | GROUP BY \`x\`, \`y\`"
26 | `;
27 |
28 | exports[`SQL Grammar SELECT Queries parses LIMIT clauses 1`] = `
29 | "SELECT *
30 | FROM \`my_table\`
31 | LIMIT 10"
32 | `;
33 |
34 | exports[`SQL Grammar SELECT Queries parses LIMIT clauses after ORDER BY 1`] = `
35 | "SELECT *
36 | FROM \`my_table\`
37 | ORDER BY \`cat\` DESC
38 | LIMIT 10"
39 | `;
40 |
41 | exports[`SQL Grammar SELECT Queries parses LIMIT clauses with OFFSET keyword 1`] = `
42 | "SELECT *
43 | FROM \`my_table\`
44 | LIMIT 10
45 | OFFSET 30"
46 | `;
47 |
48 | exports[`SQL Grammar SELECT Queries parses LIMIT clauses with comma separated offset 1`] = `
49 | "SELECT *
50 | FROM \`my_table\`
51 | LIMIT 10
52 | OFFSET 30"
53 | `;
54 |
55 | exports[`SQL Grammar SELECT Queries parses ORDER BY clauses 1`] = `
56 | "SELECT *
57 | FROM \`my_table\`
58 | ORDER BY \`x\` DESC"
59 | `;
60 |
61 | exports[`SQL Grammar SELECT Queries parses ORDER BY clauses with OFFSET n ROW 1`] = `
62 | "SELECT *
63 | FROM \`my_table\`
64 | ORDER BY \`x\` DESC
65 | OFFSET 10 ROWS"
66 | `;
67 |
68 | exports[`SQL Grammar SELECT Queries parses ORDER BY clauses with OFFSET n ROW FETCH FIRST n ONLY 1`] = `
69 | "SELECT *
70 | FROM \`my_table\`
71 | ORDER BY \`x\` DESC
72 | OFFSET 10 ROWS
73 | FETCH NEXT 15 ROWS ONLY"
74 | `;
75 |
76 | exports[`SQL Grammar SELECT Queries parses ORDER BY clauses with OFFSET n ROW FETCH NEXT n ONLY 1`] = `
77 | "SELECT *
78 | FROM \`my_table\`
79 | ORDER BY \`x\` DESC
80 | OFFSET 10 ROWS
81 | FETCH NEXT 15 ROWS ONLY"
82 | `;
83 |
84 | exports[`SQL Grammar SELECT Queries parses ORDER BY clauses with OFFSET n ROWS 1`] = `
85 | "SELECT *
86 | FROM \`my_table\`
87 | ORDER BY \`x\` DESC
88 | OFFSET 10 ROWS"
89 | `;
90 |
91 | exports[`SQL Grammar SELECT Queries parses SELECTs with FUNCTIONs 1`] = `
92 | "SELECT \`a\`, COUNT(1, \`b\`)
93 | FROM \`my_table\`
94 | LIMIT 10"
95 | `;
96 |
97 | exports[`SQL Grammar SELECT Queries parses SELECTs with FUNCTIONs without arguments 1`] = `
98 | "SELECT X(Y(Z()))
99 | FROM \`X\`"
100 | `;
101 |
102 | exports[`SQL Grammar SELECT Queries parses UDFs 1`] = `
103 | "SELECT LENGTH(\`a\`)
104 | FROM \`my_table\`"
105 | `;
106 |
107 | exports[`SQL Grammar SELECT Queries parses UNION ALL 1`] = `
108 | "SELECT *
109 | FROM \`a\`
110 | UNION ALL
111 | SELECT *
112 | FROM \`b\`"
113 | `;
114 |
115 | exports[`SQL Grammar SELECT Queries parses UNIONs 1`] = `
116 | "SELECT *
117 | FROM \`a\`
118 | UNION
119 | SELECT *
120 | FROM \`b\`
121 | UNION
122 | SELECT *
123 | FROM \`c\`"
124 | `;
125 |
126 | exports[`SQL Grammar SELECT Queries parses WHERE clauses 1`] = `
127 | "SELECT *
128 | FROM \`my_table\`
129 | WHERE ((\`x\` > 1) AND (\`y\` = 'foo'))"
130 | `;
131 |
132 | exports[`SQL Grammar SELECT Queries parses WHERE clauses with BETWEEN operator 1`] = `
133 | "SELECT *
134 | FROM \`my_table\`
135 | WHERE (((\`a\` > 10) AND (\`b\` BETWEEN 4 AND 6)) AND (\`c\` = 4))"
136 | `;
137 |
138 | exports[`SQL Grammar SELECT Queries parses WHERE with GROUP BY and ORDER BY clauses 1`] = `
139 | "SELECT *
140 | FROM \`my_table\`
141 | WHERE (\`x\` > 1)
142 | GROUP BY \`x\`, \`y\`
143 | ORDER BY COUNT(\`y\`) ASC"
144 | `;
145 |
146 | exports[`SQL Grammar SELECT Queries parses WHERE with GROUP BY clauses 1`] = `
147 | "SELECT *
148 | FROM \`my_table\`
149 | WHERE (\`x\` > 1)
150 | GROUP BY \`x\`, \`y\`"
151 | `;
152 |
153 | exports[`SQL Grammar SELECT Queries parses WHERE with ILIKE and NOT ILIKE clauses 1`] = `
154 | "SELECT *
155 | FROM \`my_table\`
156 | WHERE ((\`foo\` ILIKE '%a') AND (\`bar\` NOT ILIKE 'b%'))"
157 | `;
158 |
159 | exports[`SQL Grammar SELECT Queries parses WHERE with LIKE and NOT LIKE clauses 1`] = `
160 | "SELECT *
161 | FROM \`my_table\`
162 | WHERE ((\`foo\` LIKE '%a') AND (\`bar\` NOT LIKE 'b%'))"
163 | `;
164 |
165 | exports[`SQL Grammar SELECT Queries parses WHERE with NOT REGEXP clauses 1`] = `
166 | "SELECT *
167 | FROM \`my_table\`
168 | WHERE (((\`a\` > 10) AND (\`b\` NOT REGEXP '.*')) AND (\`c\` = 4))"
169 | `;
170 |
171 | exports[`SQL Grammar SELECT Queries parses WHERE with ORDER BY clauses 1`] = `
172 | "SELECT *
173 | FROM \`my_table\`
174 | WHERE (\`x\` > 1)
175 | ORDER BY \`y\` ASC"
176 | `;
177 |
178 | exports[`SQL Grammar SELECT Queries parses WHERE with ORDER BY clauses with direction 1`] = `
179 | "SELECT *
180 | FROM \`my_table\`
181 | WHERE (\`x\` > 1)
182 | ORDER BY \`y\` ASC"
183 | `;
184 |
185 | exports[`SQL Grammar SELECT Queries parses WHERE with REGEXP clauses 1`] = `
186 | "SELECT *
187 | FROM \`my_table\`
188 | WHERE (((\`a\` > 10) AND (\`b\` REGEXP '.*')) AND (\`c\` = 4))"
189 | `;
190 |
191 | exports[`SQL Grammar SELECT Queries parses WHERE with multiple ORDER BY clauses 1`] = `
192 | "SELECT *
193 | FROM \`my_table\`
194 | WHERE (\`x\` > 1)
195 | ORDER BY \`x\` ASC, \`y\` DESC"
196 | `;
197 |
198 | exports[`SQL Grammar SELECT Queries parses WHERE with negative numbers and operaions 1`] = `
199 | "SELECT *
200 | FROM \`my_table\`
201 | WHERE (\`foo\` < (-5 - 4))"
202 | `;
203 |
204 | exports[`SQL Grammar SELECT Queries parses complex WHERE clauses 1`] = `
205 | "SELECT *
206 | FROM \`my_table\`
207 | WHERE ((\`a\` > 10) AND ((\`a\` < 30) OR (\`b\` = 'c')))"
208 | `;
209 |
210 | exports[`SQL Grammar SELECT Queries parses expressions in place of fields 1`] = `
211 | "SELECT (\`f\` + (LENGTH(\`f\`) / 3)) AS \`f1\`
212 | FROM \`my_table\`"
213 | `;
214 |
215 | exports[`SQL Grammar SELECT Queries parses multiple joins 1`] = `
216 | "SELECT *
217 | FROM \`a\`
218 | JOIN \`b\`
219 | ON (\`a\`.\`id\` = \`b\`.\`id\`)
220 | JOIN \`c\`
221 | ON (\`a\`.\`id\` = \`c\`.\`id\`)"
222 | `;
223 |
224 | exports[`SQL Grammar SELECT Queries parses named sub selects 1`] = `
225 | "SELECT *
226 | FROM (
227 | SELECT *
228 | FROM \`my_table\`
229 | ) \`t\`"
230 | `;
231 |
232 | exports[`SQL Grammar SELECT Queries parses right outer joins 1`] = `
233 | "SELECT *
234 | FROM \`a\`
235 | RIGHT OUTER JOIN \`b\`
236 | ON (\`a\`.\`id\` = \`b\`.\`id\`)"
237 | `;
238 |
239 | exports[`SQL Grammar SELECT Queries parses single joins 1`] = `
240 | "SELECT *
241 | FROM \`a\`
242 | JOIN \`b\`
243 | ON (\`a\`.\`id\` = \`b\`.\`id\`)"
244 | `;
245 |
246 | exports[`SQL Grammar SELECT Queries parses sub selects 1`] = `
247 | "SELECT *
248 | FROM (
249 | SELECT *
250 | FROM \`my_table\`
251 | )"
252 | `;
253 |
254 | exports[`SQL Grammar SELECT Queries supports IS and IS NOT 1`] = `
255 | "SELECT *
256 | FROM \`my_table\`
257 | WHERE ((\`a\` IS NULL) AND (\`b\` IS NOT NULL))"
258 | `;
259 |
260 | exports[`SQL Grammar SELECT Queries supports booleans 1`] = `
261 | "SELECT NULL
262 | FROM \`my_table\`
263 | WHERE (\`a\` = TRUE)"
264 | `;
265 |
266 | exports[`SQL Grammar SELECT Queries supports nested expressions 1`] = `
267 | "SELECT *
268 | FROM \`my_table\`
269 | WHERE MOD((LENGTH(\`a\`) + LENGTH(\`b\`)), \`c\`)"
270 | `;
271 |
272 | exports[`SQL Grammar SELECT Queries supports nested fields using dot syntax 1`] = `
273 | "SELECT \`a\`.\`b\`.\`c\`
274 | FROM \`my_table\`
275 | WHERE (\`a\`.\`b\` > 2)"
276 | `;
277 |
278 | exports[`SQL Grammar SELECT Queries supports time window extensions 1`] = `
279 | "SELECT *
280 | FROM \`my_table\`.win:length(123)"
281 | `;
282 |
283 | exports[`SQL Grammar STARS parses stars as multiplication 1`] = `
284 | "SELECT *
285 | FROM \`foo\`
286 | WHERE (\`a\` = (1 * 2))"
287 | `;
288 |
289 | exports[`SQL Grammar aliases parses aliased table names 1`] = `
290 | "SELECT *
291 | FROM \`a\` AS \`b\`"
292 | `;
293 |
294 | exports[`SQL Grammar aliases parses aliased table names with as 1`] = `
295 | "SELECT *
296 | FROM \`a\` AS \`b\`"
297 | `;
298 |
299 | exports[`SQL Grammar functions parses function with complex arguments 1`] = `
300 | "SELECT *
301 | FROM \`foo\`
302 | WHERE (\`bar\` < DATE_SUB(NOW(), INTERVAL 14 DAYS))"
303 | `;
304 |
305 | exports[`SQL Grammar misc parses case when statements 1`] = `
306 | "SELECT CASE WHEN (\`foo\` = 'a') THEN \`a\` WHEN (\`foo\` = 'b') THEN \`b\` ELSE \`c\` END
307 | FROM \`table\`"
308 | `;
309 |
310 | exports[`SQL Grammar misc parses nested AND 1`] = `
311 | "SELECT *
312 | FROM \`a\`
313 | WHERE (((\`id\` = 1) AND ((\`id\` = 2) AND (\`type\` = 'foo'))) AND ((\`id\` = 3) AND (\`type\` = 'bar')))"
314 | `;
315 |
316 | exports[`SQL Grammar string quoting allows nesting different quote styles 1`] = `
317 | "SELECT *
318 | FROM \`a\`
319 | WHERE (\`foo\` = \\"I'm\\")"
320 | `;
321 |
322 | exports[`SQL Grammar string quoting allows using double quotes 1`] = `
323 | "SELECT *
324 | FROM \`a\`
325 | WHERE (\`foo\` = \\"a\\")"
326 | `;
327 |
328 | exports[`SQL Grammar string quoting allows using two single quotes 1`] = `
329 | "SELECT *
330 | FROM \`a\`
331 | WHERE (\`foo\` = 'I''m')"
332 | `;
333 |
334 | exports[`SQL Grammar string quoting doesn't choke on escaped quotes 1`] = `
335 | "SELECT *
336 | FROM \`a\`
337 | WHERE (\`foo\` = 'I\\\\'m')"
338 | `;
339 |
340 | exports[`SQL Grammar string quoting parses single quote 1`] = `
341 | "SELECT *
342 | FROM \`a\`
343 | WHERE (\`foo\` = '''')"
344 | `;
345 |
346 | exports[`SQL Grammar subselect clauses parses a NOT IN clause containing a query 1`] = `
347 | "SELECT *
348 | FROM \`a\`
349 | WHERE (\`x\` NOT IN (
350 | SELECT \`foo\`
351 | FROM \`bar\`
352 | ))"
353 | `;
354 |
355 | exports[`SQL Grammar subselect clauses parses a subselect field 1`] = `
356 | "SELECT (
357 | SELECT \`x\`
358 | FROM \`y\`
359 | )
360 | FROM \`a\`"
361 | `;
362 |
363 | exports[`SQL Grammar subselect clauses parses an EXISTS clause containing a query 1`] = `
364 | "SELECT *
365 | FROM \`a\`
366 | WHERE (EXISTS (
367 | SELECT \`foo\`
368 | FROM \`bar\`
369 | ))"
370 | `;
371 |
372 | exports[`SQL Grammar subselect clauses parses an IN clause containing a list 1`] = `
373 | "SELECT *
374 | FROM \`a\`
375 | WHERE (\`x\` IN (1, 2, 3))"
376 | `;
377 |
378 | exports[`SQL Grammar subselect clauses parses an IN clause containing a query 1`] = `
379 | "SELECT *
380 | FROM \`a\`
381 | WHERE (\`x\` IN (
382 | SELECT \`foo\`
383 | FROM \`bar\`
384 | ))"
385 | `;
386 |
--------------------------------------------------------------------------------
/test/grammar.spec.js:
--------------------------------------------------------------------------------
1 | const lexer = require('../src/lexer');
2 | const parser = require('../src/parser');
3 |
4 | function parse(query) {
5 | return parser.parse(lexer.tokenize(query)).toString();
6 | }
7 |
8 | describe('SQL Grammar', function () {
9 | describe('SELECT Queries', function () {
10 | it('parses ORDER BY clauses', function () {
11 | expect(parse('SELECT * FROM my_table ORDER BY x DESC')).toMatchSnapshot();
12 | });
13 |
14 | it('parses ORDER BY clauses with OFFSET n ROWS', function () {
15 | expect(parse('SELECT * FROM my_table ORDER BY x DESC OFFSET 10 ROWS')).toMatchSnapshot();
16 | });
17 |
18 | it('parses ORDER BY clauses with OFFSET n ROW', function () {
19 | expect(parse('SELECT * FROM my_table ORDER BY x DESC OFFSET 10 ROW')).toMatchSnapshot();
20 | });
21 |
22 | it('parses ORDER BY clauses with OFFSET n ROW FETCH FIRST n ONLY', function () {
23 | expect(parse('SELECT * FROM my_table ORDER BY x DESC OFFSET 10 ROW FETCH FIRST 15 ROW ONLY')).toMatchSnapshot();
24 | });
25 |
26 | it('parses ORDER BY clauses with OFFSET n ROW FETCH NEXT n ONLY', function () {
27 | expect(parse('SELECT * FROM my_table ORDER BY x DESC OFFSET 10 ROW FETCH NEXT 15 ROWS ONLY')).toMatchSnapshot();
28 | });
29 |
30 | it('parses GROUP BY clauses', function () {
31 | expect(parse('SELECT * FROM my_table GROUP BY x, y')).toMatchSnapshot();
32 | });
33 |
34 | it('parses LIMIT clauses', function () {
35 | expect(parse('SELECT * FROM my_table LIMIT 10')).toMatchSnapshot();
36 | });
37 |
38 | it('parses LIMIT clauses after ORDER BY', function () {
39 | expect(parse('SELECT * FROM my_table ORDER BY cat DESC LIMIT 10')).toMatchSnapshot();
40 | });
41 |
42 | it('parses LIMIT clauses with comma separated offset', function () {
43 | expect(parse('SELECT * FROM my_table LIMIT 30, 10')).toMatchSnapshot();
44 | });
45 |
46 | it('parses LIMIT clauses with OFFSET keyword', function () {
47 | expect(parse('SELECT * FROM my_table LIMIT 10 OFFSET 30')).toMatchSnapshot();
48 | });
49 |
50 | it('parses SELECTs with FUNCTIONs without arguments', function () {
51 | expect(parse('SELECT X(Y(Z())) FROM X')).toMatchSnapshot();
52 | });
53 |
54 | it('parses SELECTs with FUNCTIONs', function () {
55 | expect(parse('SELECT a, COUNT(1, b) FROM my_table LIMIT 10')).toMatchSnapshot();
56 | });
57 |
58 | it('parses COUNT(DISTINCT field)', function () {
59 | expect(parse('select a, count(distinct b) FROM my_table limit 10')).toMatchSnapshot();
60 | });
61 |
62 | it('parses WHERE clauses', function () {
63 | expect(parse('SELECT * FROM my_table WHERE x > 1 AND y = \'foo\'')).toMatchSnapshot();
64 | });
65 |
66 | it('parses complex WHERE clauses', function () {
67 | expect(parse('SELECT * FROM my_table WHERE a > 10 AND (a < 30 OR b = \'c\')')).toMatchSnapshot();
68 | });
69 |
70 | it('parses WHERE with REGEXP clauses', function () {
71 | expect(parse('SELECT * FROM my_table WHERE a > 10 AND b REGEXP \'.*\' AND c = 4')).toMatchSnapshot();
72 | });
73 |
74 | it('parses WHERE with NOT REGEXP clauses', function () {
75 | expect(parse('SELECT * FROM my_table WHERE a > 10 AND b NOT REGEXP \'.*\' AND c = 4')).toMatchSnapshot();
76 | });
77 |
78 | it('parses WHERE clauses with BETWEEN operator', function () {
79 | expect(parse('SELECT * FROM my_table WHERE a > 10 AND b BETWEEN 4 AND 6 AND c = 4')).toMatchSnapshot();
80 | });
81 |
82 | it('parses WHERE with LIKE and NOT LIKE clauses', function () {
83 | expect(parse('SELECT * FROM my_table WHERE foo LIKE \'%a\' AND bar NOT LIKE \'b%\'')).toMatchSnapshot();
84 | });
85 |
86 | it('parses WHERE with ILIKE and NOT ILIKE clauses', function () {
87 | expect(parse('SELECT * FROM my_table WHERE foo ILIKE \'%a\' AND bar NOT ILIKE \'b%\'')).toMatchSnapshot();
88 | });
89 |
90 | it('parses WHERE with ORDER BY clauses', function () {
91 | expect(parse('SELECT * FROM my_table WHERE x > 1 ORDER BY y')).toMatchSnapshot();
92 | });
93 |
94 | it('parses WHERE with multiple ORDER BY clauses', function () {
95 | expect(parse('SELECT * FROM my_table WHERE x > 1 ORDER BY x, y DESC')).toMatchSnapshot();
96 | });
97 |
98 | it('parses WHERE with ORDER BY clauses with direction', function () {
99 | expect(parse('SELECT * FROM my_table WHERE x > 1 ORDER BY y ASC')).toMatchSnapshot();
100 | });
101 |
102 | it('parses WHERE with GROUP BY clauses', function () {
103 | expect(parse('SELECT * FROM my_table WHERE x > 1 GROUP BY x, y')).toMatchSnapshot();
104 | });
105 |
106 | it('parses WHERE with GROUP BY and ORDER BY clauses', function () {
107 | expect(parse('SELECT * FROM my_table WHERE x > 1 GROUP BY x, y ORDER BY COUNT(y) ASC')).toMatchSnapshot();
108 | });
109 |
110 | it('parses WHERE with negative numbers and operaions', function () {
111 | expect(parse('SELECT * FROM my_table WHERE foo < -5 - 4')).toMatchSnapshot();
112 | });
113 |
114 | it('parses GROUP BY and HAVING clauses', function () {
115 | expect(parse('SELECT * FROM my_table GROUP BY x, y HAVING COUNT(`y`) > 1')).toMatchSnapshot();
116 | });
117 |
118 | it('parses UDFs', function () {
119 | expect(parse('SELECT LENGTH(a) FROM my_table')).toMatchSnapshot();
120 | });
121 |
122 | it('parses expressions in place of fields', function () {
123 | expect(parse('SELECT f+LENGTH(f)/3 AS f1 FROM my_table')).toMatchSnapshot();
124 | });
125 |
126 | it('supports booleans', function () {
127 | expect(parse('SELECT null FROM my_table WHERE a = true')).toMatchSnapshot();
128 | });
129 |
130 | it('supports IS and IS NOT', function () {
131 | expect(parse('SELECT * FROM my_table WHERE a IS NULL AND b IS NOT NULL')).toMatchSnapshot();
132 | });
133 |
134 | it('supports nested expressions', function () {
135 | expect(parse('SELECT * FROM my_table WHERE MOD(LENGTH(a) + LENGTH(b), c)')).toMatchSnapshot();
136 | });
137 |
138 | it('supports nested fields using dot syntax', function () {
139 | expect(parse('SELECT a.b.c FROM my_table WHERE a.b > 2')).toMatchSnapshot();
140 | });
141 |
142 | it('supports time window extensions', function () {
143 | expect(parse('SELECT * FROM my_table.win:length(123)')).toMatchSnapshot();
144 | });
145 |
146 | it('parses sub selects', function () {
147 | expect(parse('select * from (select * from my_table)')).toMatchSnapshot();
148 | });
149 |
150 | it('parses named sub selects', function () {
151 | expect(parse('select * from (select * from my_table) t')).toMatchSnapshot();
152 | });
153 |
154 | it('parses single joins', function () {
155 | expect(parse('select * from a join b on a.id = b.id')).toMatchSnapshot();
156 | });
157 |
158 | it('parses right outer joins', function () {
159 | expect(parse('select * from a right outer join b on a.id = b.id')).toMatchSnapshot();
160 | });
161 |
162 | it('parses multiple joins', function () {
163 | expect(parse('select * from a join b on a.id = b.id join c on a.id = c.id')).toMatchSnapshot();
164 | });
165 |
166 | it('parses UNIONs', function () {
167 | expect(parse('select * from a union select * from b union select * from c')).toMatchSnapshot();
168 | });
169 |
170 | it('parses UNION ALL', function () {
171 | expect(parse('select * from a union all select * from b')).toMatchSnapshot();
172 | });
173 | });
174 |
175 | describe('string quoting', function () {
176 | it('doesn\'t choke on escaped quotes', function () {
177 | expect(parse('select * from a where foo = \'I\\\'m\'')).toMatchSnapshot();
178 | });
179 |
180 | it('parses single quote', function () {
181 | expect(parse('select * from a where foo = \'\'\'\'')).toMatchSnapshot();
182 | });
183 |
184 | it('allows using double quotes', function () {
185 | expect(parse('select * from a where foo = "a"')).toMatchSnapshot();
186 | });
187 |
188 | it('allows using two single quotes', function () {
189 | expect(parse('select * from a where foo = \'I\'\'m\'')).toMatchSnapshot();
190 | });
191 |
192 | it('allows nesting different quote styles', function () {
193 | expect(parse('select * from a where foo = "I\'m" ')).toMatchSnapshot();
194 | });
195 | });
196 |
197 | describe('subselect clauses', function () {
198 | it('parses a subselect field', function () {
199 | expect(parse('select (select x from y) from a')).toMatchSnapshot();
200 | });
201 |
202 | it('parses an IN clause containing a list', function () {
203 | expect(parse('select * from a where x in (1,2,3)')).toMatchSnapshot();
204 | });
205 |
206 | it('parses an IN clause containing a query', function () {
207 | expect(parse('select * from a where x in (select foo from bar)')).toMatchSnapshot();
208 | });
209 |
210 | it('parses a NOT IN clause containing a query', function () {
211 | expect(parse('select * from a where x not in (select foo from bar)')).toMatchSnapshot();
212 | });
213 |
214 | it('parses an EXISTS clause containing a query', function () {
215 | expect(parse('select * from a where exists (select foo from bar)')).toMatchSnapshot();
216 | });
217 | });
218 |
219 | describe('aliases', function () {
220 | it('parses aliased table names', function () {
221 | expect(parse('select * from a b')).toMatchSnapshot();
222 | });
223 |
224 | it('parses aliased table names with as', function () {
225 | expect(parse('select * from a as b')).toMatchSnapshot();
226 | });
227 | });
228 |
229 | describe('STARS', function () {
230 | it('parses stars as multiplication', function () {
231 | expect(parse('SELECT * FROM foo WHERE a = 1*2')).toMatchSnapshot();
232 | });
233 | });
234 |
235 | describe('Parameters', function () {
236 | it('parses query parameters', function () {
237 | expect(parse('select * from foo where bar = $12')).toMatchSnapshot();
238 | });
239 | });
240 |
241 | describe('functions', function () {
242 | it('parses function with complex arguments', function () {
243 | expect(parse('SELECT * FROM foo WHERE bar < DATE_SUB(NOW(), INTERVAL 14 DAYS)')).toMatchSnapshot();
244 | });
245 | });
246 |
247 | describe('misc', function () {
248 | it('parses case when statements', function () {
249 | expect(parse('select case when foo = \'a\' then a when foo = \'b\' then b else c end from table')).toMatchSnapshot();
250 | });
251 |
252 | it('parses nested AND', function() {
253 | expect(parse("select * from a where id = 1 AND (id = 2 AND type = 'foo') AND (id = 3 AND type = 'bar')")).toMatchSnapshot();
254 | });
255 | });
256 |
257 | });
258 |
--------------------------------------------------------------------------------
/src/nodes.js:
--------------------------------------------------------------------------------
1 | function indent(str) {
2 | return ((function () {
3 | const ref = str.split('\n');
4 | const results = [];
5 | for (let i = 0, len = ref.length; i < len; i++) {
6 | results.push(` ${ref[i]}`);
7 | }
8 | return results;
9 | })()).join('\n');
10 | }
11 |
12 | exports.Select = class Select {
13 | constructor(fields, source, distinct = false, joins = [], unions = []) {
14 | this.fields = fields;
15 | this.source = source;
16 | this.distinct = distinct;
17 | this.joins = joins;
18 | this.unions = unions;
19 | this.order = null;
20 | this.group = null;
21 | this.where = null;
22 | this.limit = null;
23 | }
24 |
25 | toString() {
26 | const ret = [`SELECT ${this.fields.join(', ')}`];
27 | ret.push(indent(`FROM ${this.source}`));
28 | for (let i = 0, len = this.joins.length; i < len; i++) {
29 | ret.push(indent(this.joins[i].toString()));
30 | }
31 | if (this.where) {
32 | ret.push(indent(this.where.toString()));
33 | }
34 | if (this.group) {
35 | ret.push(indent(this.group.toString()));
36 | }
37 | if (this.order) {
38 | ret.push(indent(this.order.toString()));
39 | }
40 | if (this.limit) {
41 | ret.push(indent(this.limit.toString()));
42 | }
43 | for (let j = 0, len1 = this.unions.length; j < len1; j++) {
44 | ret.push(this.unions[j].toString());
45 | }
46 | return ret.join('\n');
47 | }
48 | };
49 |
50 | exports.SubSelect = class SubSelect {
51 | constructor(select, name = null) {
52 | this.select = select;
53 | this.name = name;
54 | }
55 |
56 | toString() {
57 | const ret = [];
58 | ret.push('(');
59 | ret.push(indent(this.select.toString()));
60 | ret.push(this.name ? `) ${this.name.toString()}` : ')');
61 | return ret.join('\n');
62 | }
63 | };
64 |
65 | exports.Join = class Join {
66 | constructor(right, conditions = null, side = null, mode = null) {
67 | this.right = right;
68 | this.conditions = conditions;
69 | this.side = side;
70 | this.mode = mode;
71 | }
72 |
73 | toString() {
74 | let ret = '';
75 | if (this.side != null) {
76 | ret += `${this.side} `;
77 | }
78 | if (this.mode != null) {
79 | ret += `${this.mode} `;
80 | }
81 | return ret + `JOIN ${this.right}\n` + indent(`ON ${this.conditions}`);
82 | }
83 | };
84 |
85 | exports.Union = class Union {
86 | constructor(query, all1 = false) {
87 | this.query = query;
88 | this.all = all1;
89 | }
90 |
91 | toString() {
92 | const all = this.all ? ' ALL' : '';
93 | return `UNION${all}\n${this.query.toString()}`;
94 | }
95 | };
96 |
97 | exports.LiteralValue = class LiteralValue {
98 | constructor(value1, value2 = null) {
99 | this.value = value1;
100 | this.value2 = value2;
101 | if (this.value2) {
102 | this.nested = true;
103 | this.values = this.value.values;
104 | this.values.push(this.value2);
105 | }
106 | else {
107 | this.nested = false;
108 | this.values = [this.value];
109 | }
110 | }
111 |
112 | // TODO: Backtick quotes only supports MySQL, Postgres uses double-quotes
113 | toString(quote = true) {
114 | if (quote) {
115 | return `\`${this.values.join('`.`')}\``;
116 | }
117 | else {
118 | return `${this.values.join('.')}`;
119 | }
120 | }
121 | };
122 |
123 | exports.StringValue = class StringValue {
124 | constructor(value1, quoteType = '\'\'') {
125 | this.value = value1;
126 | this.quoteType = quoteType;
127 | }
128 |
129 | toString() {
130 | const escaped = this.quoteType === '\'' ? this.value.replace(/(^|[^\\])'/g, '$1\'\'') : this.value;
131 | return `${this.quoteType}${escaped}${this.quoteType}`;
132 | }
133 | };
134 |
135 | exports.NumberValue = class NumberValue {
136 | constructor(value) {
137 | this.value = Number(value);
138 | }
139 |
140 | toString() {
141 | return this.value.toString();
142 | }
143 | };
144 |
145 | exports.ListValue = class ListValue {
146 | constructor(value1) {
147 | this.value = value1;
148 | }
149 |
150 | toString() {
151 | return `(${this.value.join(', ')})`;
152 | }
153 | };
154 |
155 | exports.WhitepaceList = class WhitepaceList {
156 | constructor(value1) {
157 | this.value = value1;
158 | }
159 |
160 | toString() {
161 | // not backtick for literals
162 | return this.value.map(function (value) {
163 | if (value instanceof exports.LiteralValue) {
164 | return value.toString(false);
165 | }
166 | else {
167 | return value.toString();
168 | }
169 | }).join(' ');
170 | }
171 | };
172 |
173 | exports.ParameterValue = class ParameterValue {
174 | constructor(value) {
175 | this.value = value;
176 | this.index = parseInt(value.substr(1), 10) - 1;
177 | }
178 |
179 | toString() {
180 | return `$${this.value}`;
181 | }
182 | };
183 |
184 | exports.ArgumentListValue = class ArgumentListValue {
185 | constructor(value1, distinct = false) {
186 | this.value = value1;
187 | this.distinct = distinct;
188 | }
189 |
190 | toString() {
191 | if (this.distinct) {
192 | return `DISTINCT ${this.value.join(', ')}`;
193 | }
194 | else {
195 | return `${this.value.join(', ')}`;
196 | }
197 | }
198 | };
199 |
200 | exports.BooleanValue = class LiteralValue {
201 | constructor(value) {
202 | this.value = (function () {
203 | switch (value.toLowerCase()) {
204 | case 'true':
205 | return true;
206 | case 'false':
207 | return false;
208 | default:
209 | return null;
210 | }
211 | })();
212 | }
213 |
214 | toString() {
215 | if (this.value != null) {
216 | return this.value.toString().toUpperCase();
217 | }
218 | else {
219 | return 'NULL';
220 | }
221 | }
222 | };
223 |
224 | exports.FunctionValue = class FunctionValue {
225 | constructor(name, _arguments = null, udf = false) {
226 | this.name = name;
227 | this.arguments = _arguments;
228 | this.udf = udf;
229 | }
230 |
231 | toString() {
232 | if (this.arguments) {
233 | return `${this.name.toUpperCase()}(${this.arguments.toString()})`;
234 | }
235 | else {
236 | return `${this.name.toUpperCase()}()`;
237 | }
238 | }
239 | };
240 |
241 | exports.Case = class Case {
242 | constructor(whens, _else) {
243 | this.whens = whens;
244 | this.else = _else;
245 | }
246 |
247 | toString() {
248 | const whensStr = this.whens.map(function (w) {
249 | return w.toString();
250 | }).join(' ');
251 | if (this.else) {
252 | return `CASE ${whensStr} ${this.else.toString()} END`;
253 | }
254 | else {
255 | return `CASE ${whensStr} END`;
256 | }
257 | }
258 | };
259 |
260 | exports.CaseWhen = class CaseWhen {
261 | constructor(whenCondition, resCondition) {
262 | this.whenCondition = whenCondition;
263 | this.resCondition = resCondition;
264 | }
265 |
266 | toString() {
267 | return `WHEN ${this.whenCondition} THEN ${this.resCondition}`;
268 | }
269 | };
270 |
271 | exports.CaseElse = class CaseElse {
272 | constructor(elseCondition) {
273 | this.elseCondition = elseCondition;
274 | }
275 |
276 | toString() {
277 | return `ELSE ${this.elseCondition}`;
278 | }
279 | };
280 |
281 | exports.Order = class Order {
282 | constructor(orderings, offset) {
283 | this.orderings = orderings;
284 | this.offset = offset;
285 | }
286 |
287 | toString() {
288 | return `ORDER BY ${this.orderings.join(', ')}` + (this.offset ? '\n' + this.offset.toString() : '');
289 | }
290 | };
291 |
292 | exports.OrderArgument = class OrderArgument {
293 | constructor(value, direction = 'ASC') {
294 | this.value = value;
295 | this.direction = direction;
296 | null;
297 | }
298 |
299 | toString() {
300 | return `${this.value} ${this.direction}`;
301 | }
302 | };
303 |
304 | exports.Offset = class Offset {
305 | constructor(row_count, limit) {
306 | this.row_count = row_count;
307 | this.limit = limit;
308 | }
309 |
310 | toString() {
311 | return `OFFSET ${this.row_count} ROWS` + (this.limit ? `\nFETCH NEXT ${this.limit} ROWS ONLY` : '');
312 | }
313 | };
314 |
315 | exports.Limit = class Limit {
316 | constructor(value1, offset) {
317 | this.value = value1;
318 | this.offset = offset;
319 | }
320 |
321 | toString() {
322 | return `LIMIT ${this.value}` + (this.offset ? `\nOFFSET ${this.offset}` : '');
323 | }
324 | };
325 |
326 | exports.Table = class Table {
327 | constructor(name, alias = null, win = null, winFn = null, winArg = null) {
328 | this.name = name;
329 | this.alias = alias;
330 | this.win = win;
331 | this.winFn = winFn;
332 | this.winArg = winArg;
333 | }
334 |
335 | toString() {
336 | if (this.win) {
337 | return `${this.name}.${this.win}:${this.winFn}(${this.winArg})`;
338 | }
339 | else if (this.alias) {
340 | return `${this.name} AS ${this.alias}`;
341 | }
342 | else {
343 | return this.name.toString();
344 | }
345 | }
346 | };
347 |
348 | exports.Group = class Group {
349 | constructor(fields) {
350 | this.fields = fields;
351 | this.having = null;
352 | }
353 |
354 | toString() {
355 | const ret = [`GROUP BY ${this.fields.join(', ')}`];
356 | if (this.having) {
357 | ret.push(this.having.toString());
358 | }
359 | return ret.join('\n');
360 | }
361 | };
362 |
363 | exports.Where = class Where {
364 | constructor(conditions) {
365 | this.conditions = conditions;
366 | }
367 |
368 | toString() {
369 | return `WHERE ${this.conditions}`;
370 | }
371 | };
372 |
373 | exports.Having = class Having {
374 | constructor(conditions) {
375 | this.conditions = conditions;
376 | }
377 |
378 | toString() {
379 | return `HAVING ${this.conditions}`;
380 | }
381 | };
382 |
383 | exports.Op = class Op {
384 | constructor(operation, left, right) {
385 | this.operation = operation;
386 | this.left = left;
387 | this.right = right;
388 | }
389 |
390 | toString() {
391 | return `(${this.left} ${this.operation.toUpperCase()} ${this.right})`;
392 | }
393 | };
394 |
395 | exports.UnaryOp = class UnaryOp {
396 | constructor(operator, operand) {
397 | this.operator = operator;
398 | this.operand = operand;
399 | }
400 |
401 | toString() {
402 | return `(${this.operator.toUpperCase()} ${this.operand})`;
403 | }
404 | };
405 |
406 | exports.BetweenOp = class BetweenOp {
407 | constructor(value) {
408 | this.value = value;
409 | }
410 |
411 | toString() {
412 | return `${this.value.join(' AND ')}`;
413 | }
414 | };
415 |
416 | exports.Field = class Field {
417 | constructor(field, name = null) {
418 | this.field = field;
419 | this.name = name;
420 | }
421 |
422 | toString() {
423 | if (this.name) {
424 | return `${this.field} AS ${this.name}`;
425 | }
426 | else {
427 | return this.field.toString();
428 | }
429 | }
430 | };
431 |
432 | exports.Star = class Star {
433 | toString() {
434 | return '*';
435 | }
436 | };
437 |
--------------------------------------------------------------------------------
/src/grammar.js:
--------------------------------------------------------------------------------
1 | const Parser = require('jison').Parser;
2 |
3 | const unwrap = /^function\s*\(.*?\)\s*{\s*return\s*([\s\S]*);\s*}/;
4 | const cleanup = /^function\s*\(.*?\)\s*{\s*(.*?)\s*}/s;
5 |
6 | function o(patternString, action, options) {
7 | patternString = patternString.replace(/\s{2,}/g, ' ');
8 |
9 | if (!action) {
10 | return [patternString, '$$ = $1;', options];
11 | }
12 |
13 | let match;
14 | if ((match = unwrap.exec(action.toString()))) {
15 | action = match[1];
16 | } else if ((match = cleanup.exec(action.toString()))) {
17 | action = `(function(){ ${match[1]} }())`;
18 | } else {
19 | throw `Invalid action ${action}`;
20 | }
21 |
22 | action = action.replace(/\bnew /g, '$&yy.');
23 | action = action.replace(/\s+/g, ' ');
24 |
25 | return [patternString, `$$ = ${action};`, options];
26 | }
27 |
28 | const grammar = {
29 | Root : [
30 | o('Query EOF')
31 | ],
32 | Query : [
33 | o('SelectQuery'),
34 | o('SelectQuery Unions', function ($1, $2) {
35 | $1.unions = $2;
36 | return $1;
37 | })
38 | ],
39 | SelectQuery : [
40 | o('SelectWithLimitQuery'),
41 | o('BasicSelectQuery')
42 | ],
43 | BasicSelectQuery : [
44 | o('Select'),
45 | o('Select OrderClause', function ($1, $2) {
46 | $1.order = $2;
47 | return $1;
48 | }),
49 | o('Select GroupClause', function ($1, $2) {
50 | $1.group = $2;
51 | return $1;
52 | }),
53 | o('Select GroupClause OrderClause', function ($1, $2, $3) {
54 | $1.group = $2;
55 | $1.order = $3;
56 | return $1;
57 | })
58 | ],
59 | SelectWithLimitQuery : [
60 | o('SelectQuery LimitClause', function ($1, $2) {
61 | $1.limit = $2;
62 | return $1;
63 | })
64 | ],
65 | Select : [
66 | o('SelectClause'),
67 | o('SelectClause WhereClause', function ($1, $2) {
68 | $1.where = $2;
69 | return $1;
70 | })
71 | ],
72 | SelectClause : [
73 | o('SELECT Fields FROM Table', function ($2, $4) {
74 | return new Select($2, $4, false);
75 | }),
76 | o('SELECT DISTINCT Fields FROM Table', function ($3, $5) {
77 | return new Select($3, $5, true);
78 | }),
79 | o('SELECT Fields FROM Table Joins', function ($2, $4, $5) {
80 | return new Select($2, $4, false, $5);
81 | }),
82 | o('SELECT DISTINCT Fields FROM Table Joins', function ($3, $5, $6) {
83 | return new Select($3, $5, true, $6);
84 | })
85 | ],
86 | Table : [
87 | o('Literal', function ($1) {
88 | return new Table($1);
89 | }),
90 | o('Literal Literal', function ($1, $2) {
91 | return new Table($1, $2);
92 | }),
93 | o('Literal AS Literal', function ($1, $3) {
94 | return new Table($1, $3);
95 | }),
96 | o('LEFT_PAREN List RIGHT_PAREN', function ($2) {
97 | return $2;
98 | }),
99 | o('LEFT_PAREN Query RIGHT_PAREN', function ($2) {
100 | return new SubSelect($2);
101 | }),
102 | o('LEFT_PAREN Query RIGHT_PAREN Literal', function ($2, $4) {
103 | return new SubSelect($2, $4);
104 | }),
105 | o('Literal WINDOW WINDOW_FUNCTION LEFT_PAREN Number RIGHT_PAREN', function ($1, $2, $3, $5) {
106 | return new Table($1, null, $2, $3, $5);
107 | })
108 | ],
109 | Unions : [
110 | o('Union', function ($1) {
111 | return [$1];
112 | }),
113 | o('Unions Union', function ($1, $2) {
114 | return $1.concat($2);
115 | })
116 | ],
117 | Union : [
118 | o('UNION SelectQuery', function ($2) {
119 | return new Union($2);
120 | }),
121 | o('UNION ALL SelectQuery', function ($3) {
122 | return new Union($3, true);
123 | })
124 | ],
125 | Joins : [
126 | o('Join', function ($1) {
127 | return [$1];
128 | }),
129 | o('Joins Join', function ($1, $2) {
130 | return $1.concat($2);
131 | })
132 | ],
133 | Join : [
134 | o('JOIN Table ON Expression', function ($2, $4) {
135 | return new Join($2, $4);
136 | }),
137 | o('LEFT JOIN Table ON Expression', function ($3, $5) {
138 | return new Join($3, $5, 'LEFT');
139 | }),
140 | o('RIGHT JOIN Table ON Expression', function ($3, $5) {
141 | return new Join($3, $5, 'RIGHT');
142 | }),
143 | o('LEFT INNER JOIN Table ON Expression', function ($4, $6) {
144 | return new Join($4, $6, 'LEFT', 'INNER');
145 | }),
146 | o('RIGHT INNER JOIN Table ON Expression', function ($4, $6) {
147 | return new Join($4, $6, 'RIGHT', 'INNER');
148 | }),
149 | o('LEFT OUTER JOIN Table ON Expression', function ($4, $6) {
150 | return new Join($4, $6, 'LEFT', 'OUTER');
151 | }),
152 | o('RIGHT OUTER JOIN Table ON Expression', function ($4, $6) {
153 | return new Join($4, $6, 'RIGHT', 'OUTER');
154 | })
155 | ],
156 | WhereClause : [
157 | o('WHERE Expression', function ($2) {
158 | return new Where($2);
159 | })
160 | ],
161 | LimitClause : [
162 | o('LIMIT Number', function ($2) {
163 | return new Limit($2);
164 | }),
165 | o('LIMIT Number SEPARATOR Number', function ($2, $4) {
166 | return new Limit($4, $2);
167 | }),
168 | o('LIMIT Number OFFSET Number', function ($2, $4) {
169 | return new Limit($2, $4);
170 | })
171 | ],
172 | OrderClause : [
173 | o('ORDER BY OrderArgs', function ($3) {
174 | return new Order($3);
175 | }),
176 | o('ORDER BY OrderArgs OffsetClause', function ($3, $4) {
177 | return new Order($3, $4);
178 | })
179 | ],
180 | OrderArgs : [
181 | o('OrderArg', function ($1) {
182 | return [$1];
183 | }),
184 | o('OrderArgs SEPARATOR OrderArg', function ($1, $3) {
185 | return $1.concat($3);
186 | })
187 | ],
188 | OrderArg : [
189 | o('Value', function ($1) {
190 | return new OrderArgument($1, 'ASC');
191 | }),
192 | o('Value DIRECTION', function ($1, $2) {
193 | return new OrderArgument($1, $2);
194 | })
195 | ],
196 | OffsetClause : [
197 | // MS SQL Server 2012+
198 | o('OFFSET OffsetRows', function ($2) {
199 | return new Offset($2);
200 | }),
201 | o('OFFSET OffsetRows FetchClause', function ($2, $3) {
202 | return new Offset($2, $3);
203 | })
204 | ],
205 | OffsetRows : [
206 | o('Number ROW', function ($1) {
207 | return $1;
208 | }),
209 | o('Number ROWS', function ($1) {
210 | return $1;
211 | })
212 | ],
213 | FetchClause : [
214 | o('FETCH FIRST OffsetRows ONLY', function ($3) {
215 | return $3;
216 | }),
217 | o('FETCH NEXT OffsetRows ONLY', function ($3) {
218 | return $3;
219 | })
220 | ],
221 | GroupClause : [
222 | o('GroupBasicClause', function ($1) {
223 | return $1;
224 | }),
225 | o('GroupBasicClause HavingClause', function ($1, $2) {
226 | $1.having = $2;
227 | return $1;
228 | })
229 | ],
230 | GroupBasicClause : [
231 | o('GROUP BY ArgumentList', function ($3) {
232 | return new Group($3);
233 | })
234 | ],
235 | HavingClause : [
236 | o('HAVING Expression', function ($2) {
237 | return new Having($2);
238 | })
239 | ],
240 | Expression : [
241 | o('LEFT_PAREN Expression RIGHT_PAREN', function ($2) {
242 | return $2;
243 | }),
244 | o('Expression MATH Expression', function ($1, $2, $3) {
245 | return new Op($2, $1, $3);
246 | }),
247 | o('Expression MATH_MULTI Expression', function ($1, $2, $3) {
248 | return new Op($2, $1, $3);
249 | }),
250 | o('Expression OPERATOR Expression', function ($1, $2, $3) {
251 | return new Op($2, $1, $3);
252 | }),
253 | o('Expression BETWEEN BetweenExpression', function ($1, $2, $3) {
254 | return new Op($2, $1, $3);
255 | }),
256 | o('Expression CONDITIONAL Expression', function ($1, $2, $3) {
257 | return new Op($2, $1, $3);
258 | }),
259 | o('Value SUB_SELECT_OP LEFT_PAREN List RIGHT_PAREN', function ($1, $2, $4) {
260 | return new Op($2, $1, $4);
261 | }),
262 | o('Value SUB_SELECT_OP SubSelectExpression', function ($1, $2, $3) {
263 | return new Op($2, $1, $3);
264 | }),
265 | o('SUB_SELECT_UNARY_OP SubSelectExpression', function ($1, $2) {
266 | return new UnaryOp($1, $2);
267 | }),
268 | o('SubSelectExpression', function ($1) {
269 | return $1;
270 | }),
271 | o('WhitepaceList', function ($1) {
272 | return new WhitepaceList($1);
273 | }),
274 | o('CaseStatement', function ($1) {
275 | return $1;
276 | }),
277 | o('Value', function ($1) {
278 | return $1;
279 | })
280 | ],
281 | BetweenExpression : [
282 | o('Expression CONDITIONAL Expression', function ($1, $3) {
283 | return new BetweenOp([$1, $3]);
284 | })
285 | ],
286 | CaseStatement : [
287 | o('CASE CaseWhens END', function ($2) {
288 | return new Case($2);
289 | }),
290 | o('CASE CaseWhens CaseElse END', function ($2, $3) {
291 | return new Case($2, $3);
292 | })
293 | ],
294 | CaseWhen : [
295 | o('WHEN Expression THEN Expression', function ($2, $4) {
296 | return new CaseWhen($2, $4);
297 | })
298 | ],
299 | CaseWhens : [
300 | o('CaseWhens CaseWhen', function ($1, $2) {
301 | return $1.concat($2);
302 | }),
303 | o('CaseWhen', function ($1) {
304 | return [$1];
305 | })
306 | ],
307 | CaseElse : [
308 | o('ELSE Expression', function ($2) {
309 | return new CaseElse($2);
310 | })
311 | ],
312 | SubSelectExpression : [
313 | o('LEFT_PAREN Query RIGHT_PAREN', function ($2) {
314 | return new SubSelect($2);
315 | })
316 | ],
317 | Value : [
318 | o('Literal'),
319 | o('Number'),
320 | o('String'),
321 | o('Function'),
322 | o('UserFunction'),
323 | o('Boolean'),
324 | o('Parameter')
325 | ],
326 | WhitepaceList : [
327 | o('Value Value', function ($1, $2) {
328 | return [$1, $2];
329 | }),
330 | o('WhitepaceList Value', function ($1, $2) {
331 | $1.push($2);
332 | return $1;
333 | })
334 | ],
335 | List : [
336 | o('ArgumentList', function ($1) {
337 | return new ListValue($1);
338 | })
339 | ],
340 | Number : [
341 | o('NUMBER', function ($1) {
342 | return new NumberValue($1);
343 | })
344 | ],
345 | Boolean : [
346 | o('BOOLEAN', function ($1) {
347 | return new BooleanValue($1);
348 | })
349 | ],
350 | Parameter : [
351 | o('PARAMETER', function ($1) {
352 | return new ParameterValue($1);
353 | })
354 | ],
355 | String : [
356 | o('STRING', function ($1) {
357 | return new StringValue($1, "'");
358 | }),
359 | o('DBLSTRING', function ($1) {
360 | return new StringValue($1, '"');
361 | })
362 | ],
363 | Literal : [
364 | o('LITERAL', function ($1) {
365 | return new LiteralValue($1);
366 | }),
367 | o('Literal DOT LITERAL', function ($1, $3) {
368 | return new LiteralValue($1, $3);
369 | })
370 | ],
371 | Function : [
372 | o('FUNCTION LEFT_PAREN AggregateArgumentList RIGHT_PAREN', function ($1, $3) {
373 | return new FunctionValue($1, $3);
374 | })
375 | ],
376 | UserFunction : [
377 | o('LITERAL LEFT_PAREN RIGHT_PAREN', function ($1) {
378 | return new FunctionValue($1, null, true);
379 | }),
380 | o('LITERAL LEFT_PAREN AggregateArgumentList RIGHT_PAREN', function ($1, $3) {
381 | return new FunctionValue($1, $3, true);
382 | }),
383 | o('LITERAL LEFT_PAREN Case RIGHT_PAREN', function ($1, $3) {
384 | return new FunctionValue($1, $3, true);
385 | })
386 | ],
387 | AggregateArgumentList: [
388 | o('ArgumentList', function ($1) {
389 | return new ArgumentListValue($1);
390 | }),
391 | o('DISTINCT ArgumentList', function ($2) {
392 | return new ArgumentListValue($2, true);
393 | })
394 | ],
395 | ArgumentList : [
396 | o('Expression', function ($1) {
397 | return [$1];
398 | }),
399 | o('ArgumentList SEPARATOR Expression', function ($1, $3) {
400 | return $1.concat($3);
401 | })
402 | ],
403 | Fields : [
404 | o('Field', function ($1) {
405 | return [$1];
406 | }),
407 | o('Fields SEPARATOR Field', function ($1, $3) {
408 | return $1.concat($3);
409 | })
410 | ],
411 | Field : [
412 | o('STAR', function () {
413 | return new Star();
414 | }),
415 | o('Expression', function ($1) {
416 | return new Field($1);
417 | }),
418 | o('Expression AS Literal', function ($1, $3) {
419 | return new Field($1, $3);
420 | })
421 | ]
422 | };
423 |
424 | const tokens = [];
425 |
426 | const operators = [
427 | ['left', 'Op'],
428 | ['left', 'MATH_MULTI'],
429 | ['left', 'MATH'],
430 | ['left', 'OPERATOR'],
431 | ['left', 'CONDITIONAL']
432 | ];
433 |
434 | for (let name in grammar) {
435 | const alternatives = grammar[name];
436 | grammar[name] = (function () {
437 | const results = [];
438 | for (let i = 0, len = alternatives.length; i < len; i++) {
439 | const alt = alternatives[i];
440 | const ref = alt[0].split(' ');
441 | for (let j = 0, len1 = ref.length; j < len1; j++) {
442 | token = ref[j];
443 | if (!grammar[token]) {
444 | tokens.push(token);
445 | }
446 | }
447 | if (name === 'Root') {
448 | alt[1] = `return ${alt[1]}`;
449 | }
450 | results.push(alt);
451 | }
452 | return results;
453 | })();
454 | }
455 |
456 | exports.parser = new Parser({
457 | tokens : tokens.join(' '),
458 | bnf : grammar,
459 | operators : operators.reverse(),
460 | startSymbol: 'Root',
461 | }, {
462 | moduleType: 'js',
463 | });
464 |
--------------------------------------------------------------------------------
/src/compiled_parser.js:
--------------------------------------------------------------------------------
1 | /* parser generated by jison 0.4.18 */
2 | /*
3 | Returns a Parser object of the following structure:
4 |
5 | Parser: {
6 | yy: {}
7 | }
8 |
9 | Parser.prototype: {
10 | yy: {},
11 | trace: function(),
12 | symbols_: {associative list: name ==> number},
13 | terminals_: {associative list: number ==> name},
14 | productions_: [...],
15 | performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
16 | table: [...],
17 | defaultActions: {...},
18 | parseError: function(str, hash),
19 | parse: function(input),
20 |
21 | lexer: {
22 | EOF: 1,
23 | parseError: function(str, hash),
24 | setInput: function(input),
25 | input: function(),
26 | unput: function(str),
27 | more: function(),
28 | less: function(n),
29 | pastInput: function(),
30 | upcomingInput: function(),
31 | showPosition: function(),
32 | test_match: function(regex_match_array, rule_index),
33 | next: function(),
34 | lex: function(),
35 | begin: function(condition),
36 | popState: function(),
37 | _currentRules: function(),
38 | topState: function(),
39 | pushState: function(condition),
40 |
41 | options: {
42 | ranges: boolean (optional: true ==> token location info will include a .range[] member)
43 | flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
44 | backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
45 | },
46 |
47 | performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
48 | rules: [...],
49 | conditions: {associative list: name ==> set},
50 | }
51 | }
52 |
53 |
54 | token location info (@$, _$, etc.): {
55 | first_line: n,
56 | last_line: n,
57 | first_column: n,
58 | last_column: n,
59 | range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
60 | }
61 |
62 |
63 | the parseError function receives a 'hash' object with these members for lexer and parser errors: {
64 | text: (matched text)
65 | token: (the produced terminal token, if any)
66 | line: (yylineno)
67 | }
68 | while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
69 | loc: (yylloc)
70 | expected: (string describing the set of expected tokens)
71 | recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
72 | }
73 | */
74 | var parser = (function(){
75 | var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,8],$V1=[5,26],$V2=[1,14],$V3=[1,13],$V4=[5,26,31,42],$V5=[1,17],$V6=[5,26,31,42,45,62],$V7=[1,27],$V8=[1,29],$V9=[1,40],$Va=[1,42],$Vb=[1,46],$Vc=[1,47],$Vd=[1,43],$Ve=[1,44],$Vf=[1,41],$Vg=[1,45],$Vh=[1,25],$Vi=[5,26,31],$Vj=[5,26,31,42,45],$Vk=[1,59],$Vl=[18,43],$Vm=[1,62],$Vn=[1,63],$Vo=[1,64],$Vp=[1,65],$Vq=[1,66],$Vr=[5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,66,67,68,70,78,81,82,83],$Vs=[5,18,23,26,31,34,37,38,41,42,43,44,45,51,62,64,65,66,67,68,70,71,78,81,82,83,89,90,91,92,93,94,96],$Vt=[1,74],$Vu=[1,77],$Vv=[2,93],$Vw=[1,91],$Vx=[1,92],$Vy=[5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,66,67,68,70,78,81,82,83,89,90,91,92,93,94,96],$Vz=[78,81,83],$VA=[1,116],$VB=[5,26,31,42,43,44],$VC=[1,124],$VD=[5,26,31,42,43,45,64],$VE=[5,26,31,41,42,45,62],$VF=[1,127],$VG=[1,128],$VH=[1,129],$VI=[5,26,31,34,35,37,38,41,42,45,62],$VJ=[5,18,23,26,31,34,37,38,41,42,43,45,62,64,70,78,81,82,83],$VK=[5,26,31,34,37,38,41,42,45,62],$VL=[5,26,31,42,56,58];
76 | var parser = {trace: function trace () { },
77 | yy: {},
78 | symbols_: {"error":2,"Root":3,"Query":4,"EOF":5,"SelectQuery":6,"Unions":7,"SelectWithLimitQuery":8,"BasicSelectQuery":9,"Select":10,"OrderClause":11,"GroupClause":12,"LimitClause":13,"SelectClause":14,"WhereClause":15,"SELECT":16,"Fields":17,"FROM":18,"Table":19,"DISTINCT":20,"Joins":21,"Literal":22,"AS":23,"LEFT_PAREN":24,"List":25,"RIGHT_PAREN":26,"WINDOW":27,"WINDOW_FUNCTION":28,"Number":29,"Union":30,"UNION":31,"ALL":32,"Join":33,"JOIN":34,"ON":35,"Expression":36,"LEFT":37,"RIGHT":38,"INNER":39,"OUTER":40,"WHERE":41,"LIMIT":42,"SEPARATOR":43,"OFFSET":44,"ORDER":45,"BY":46,"OrderArgs":47,"OffsetClause":48,"OrderArg":49,"Value":50,"DIRECTION":51,"OffsetRows":52,"FetchClause":53,"ROW":54,"ROWS":55,"FETCH":56,"FIRST":57,"ONLY":58,"NEXT":59,"GroupBasicClause":60,"HavingClause":61,"GROUP":62,"ArgumentList":63,"HAVING":64,"MATH":65,"MATH_MULTI":66,"OPERATOR":67,"BETWEEN":68,"BetweenExpression":69,"CONDITIONAL":70,"SUB_SELECT_OP":71,"SubSelectExpression":72,"SUB_SELECT_UNARY_OP":73,"WhitepaceList":74,"CaseStatement":75,"CASE":76,"CaseWhens":77,"END":78,"CaseElse":79,"CaseWhen":80,"WHEN":81,"THEN":82,"ELSE":83,"String":84,"Function":85,"UserFunction":86,"Boolean":87,"Parameter":88,"NUMBER":89,"BOOLEAN":90,"PARAMETER":91,"STRING":92,"DBLSTRING":93,"LITERAL":94,"DOT":95,"FUNCTION":96,"AggregateArgumentList":97,"Case":98,"Field":99,"STAR":100,"$accept":0,"$end":1},
79 | terminals_: {2:"error",5:"EOF",16:"SELECT",18:"FROM",20:"DISTINCT",23:"AS",24:"LEFT_PAREN",26:"RIGHT_PAREN",27:"WINDOW",28:"WINDOW_FUNCTION",31:"UNION",32:"ALL",34:"JOIN",35:"ON",37:"LEFT",38:"RIGHT",39:"INNER",40:"OUTER",41:"WHERE",42:"LIMIT",43:"SEPARATOR",44:"OFFSET",45:"ORDER",46:"BY",51:"DIRECTION",54:"ROW",55:"ROWS",56:"FETCH",57:"FIRST",58:"ONLY",59:"NEXT",62:"GROUP",64:"HAVING",65:"MATH",66:"MATH_MULTI",67:"OPERATOR",68:"BETWEEN",70:"CONDITIONAL",71:"SUB_SELECT_OP",73:"SUB_SELECT_UNARY_OP",76:"CASE",78:"END",81:"WHEN",82:"THEN",83:"ELSE",89:"NUMBER",90:"BOOLEAN",91:"PARAMETER",92:"STRING",93:"DBLSTRING",94:"LITERAL",95:"DOT",96:"FUNCTION",98:"Case",100:"STAR"},
80 | productions_: [0,[3,2],[4,1],[4,2],[6,1],[6,1],[9,1],[9,2],[9,2],[9,3],[8,2],[10,1],[10,2],[14,4],[14,5],[14,5],[14,6],[19,1],[19,2],[19,3],[19,3],[19,3],[19,4],[19,6],[7,1],[7,2],[30,2],[30,3],[21,1],[21,2],[33,4],[33,5],[33,5],[33,6],[33,6],[33,6],[33,6],[15,2],[13,2],[13,4],[13,4],[11,3],[11,4],[47,1],[47,3],[49,1],[49,2],[48,2],[48,3],[52,2],[52,2],[53,4],[53,4],[12,1],[12,2],[60,3],[61,2],[36,3],[36,3],[36,3],[36,3],[36,3],[36,3],[36,5],[36,3],[36,2],[36,1],[36,1],[36,1],[36,1],[69,3],[75,3],[75,4],[80,4],[77,2],[77,1],[79,2],[72,3],[50,1],[50,1],[50,1],[50,1],[50,1],[50,1],[50,1],[74,2],[74,2],[25,1],[29,1],[87,1],[88,1],[84,1],[84,1],[22,1],[22,3],[85,4],[86,3],[86,4],[86,4],[97,1],[97,2],[63,1],[63,3],[17,1],[17,3],[99,1],[99,1],[99,3]],
81 | performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
82 | /* this == yyval */
83 |
84 | var $0 = $$.length - 1;
85 | switch (yystate) {
86 | case 1:
87 | return this.$ = $$[$0-1];
88 | break;
89 | case 2: case 4: case 5: case 6: case 11: case 53: case 66: case 68: case 69: case 78: case 79: case 80: case 81: case 82: case 83: case 84:
90 | this.$ = $$[$0];
91 | break;
92 | case 3:
93 | this.$ = (function(){ $$[$0-1].unions = $$[$0]; return $$[$0-1]; }());
94 | break;
95 | case 7:
96 | this.$ = (function(){ $$[$0-1].order = $$[$0]; return $$[$0-1]; }());
97 | break;
98 | case 8:
99 | this.$ = (function(){ $$[$0-1].group = $$[$0]; return $$[$0-1]; }());
100 | break;
101 | case 9:
102 | this.$ = (function(){ $$[$0-2].group = $$[$0-1]; $$[$0-2].order = $$[$0]; return $$[$0-2]; }());
103 | break;
104 | case 10:
105 | this.$ = (function(){ $$[$0-1].limit = $$[$0]; return $$[$0-1]; }());
106 | break;
107 | case 12:
108 | this.$ = (function(){ $$[$0-1].where = $$[$0]; return $$[$0-1]; }());
109 | break;
110 | case 13:
111 | this.$ = new yy.Select($$[$0-2], $$[$0], false);
112 | break;
113 | case 14:
114 | this.$ = new yy.Select($$[$0-2], $$[$0], true);
115 | break;
116 | case 15:
117 | this.$ = new yy.Select($$[$0-3], $$[$0-1], false, $$[$0]);
118 | break;
119 | case 16:
120 | this.$ = new yy.Select($$[$0-3], $$[$0-1], true, $$[$0]);
121 | break;
122 | case 17:
123 | this.$ = new yy.Table($$[$0]);
124 | break;
125 | case 18:
126 | this.$ = new yy.Table($$[$0-1], $$[$0]);
127 | break;
128 | case 19:
129 | this.$ = new yy.Table($$[$0-2], $$[$0]);
130 | break;
131 | case 20: case 49: case 50: case 51: case 52: case 57:
132 | this.$ = $$[$0-1];
133 | break;
134 | case 21: case 77:
135 | this.$ = new yy.SubSelect($$[$0-1]);
136 | break;
137 | case 22:
138 | this.$ = new yy.SubSelect($$[$0-2], $$[$0]);
139 | break;
140 | case 23:
141 | this.$ = new yy.Table($$[$0-5], null, $$[$0-4], $$[$0-3], $$[$0-1]);
142 | break;
143 | case 24: case 28: case 43: case 75: case 101: case 103:
144 | this.$ = [$$[$0]];
145 | break;
146 | case 25: case 29: case 74:
147 | this.$ = $$[$0-1].concat($$[$0]);
148 | break;
149 | case 26:
150 | this.$ = new yy.Union($$[$0]);
151 | break;
152 | case 27:
153 | this.$ = new yy.Union($$[$0], true);
154 | break;
155 | case 30:
156 | this.$ = new yy.Join($$[$0-2], $$[$0]);
157 | break;
158 | case 31:
159 | this.$ = new yy.Join($$[$0-2], $$[$0], 'LEFT');
160 | break;
161 | case 32:
162 | this.$ = new yy.Join($$[$0-2], $$[$0], 'RIGHT');
163 | break;
164 | case 33:
165 | this.$ = new yy.Join($$[$0-2], $$[$0], 'LEFT', 'INNER');
166 | break;
167 | case 34:
168 | this.$ = new yy.Join($$[$0-2], $$[$0], 'RIGHT', 'INNER');
169 | break;
170 | case 35:
171 | this.$ = new yy.Join($$[$0-2], $$[$0], 'LEFT', 'OUTER');
172 | break;
173 | case 36:
174 | this.$ = new yy.Join($$[$0-2], $$[$0], 'RIGHT', 'OUTER');
175 | break;
176 | case 37:
177 | this.$ = new yy.Where($$[$0]);
178 | break;
179 | case 38:
180 | this.$ = new yy.Limit($$[$0]);
181 | break;
182 | case 39:
183 | this.$ = new yy.Limit($$[$0], $$[$0-2]);
184 | break;
185 | case 40:
186 | this.$ = new yy.Limit($$[$0-2], $$[$0]);
187 | break;
188 | case 41:
189 | this.$ = new yy.Order($$[$0]);
190 | break;
191 | case 42:
192 | this.$ = new yy.Order($$[$0-1], $$[$0]);
193 | break;
194 | case 44: case 102: case 104:
195 | this.$ = $$[$0-2].concat($$[$0]);
196 | break;
197 | case 45:
198 | this.$ = new yy.OrderArgument($$[$0], 'ASC');
199 | break;
200 | case 46:
201 | this.$ = new yy.OrderArgument($$[$0-1], $$[$0]);
202 | break;
203 | case 47:
204 | this.$ = new yy.Offset($$[$0]);
205 | break;
206 | case 48:
207 | this.$ = new yy.Offset($$[$0-1], $$[$0]);
208 | break;
209 | case 54:
210 | this.$ = (function(){ $$[$0-1].having = $$[$0]; return $$[$0-1]; }());
211 | break;
212 | case 55:
213 | this.$ = new yy.Group($$[$0]);
214 | break;
215 | case 56:
216 | this.$ = new yy.Having($$[$0]);
217 | break;
218 | case 58: case 59: case 60: case 61: case 62: case 64:
219 | this.$ = new yy.Op($$[$0-1], $$[$0-2], $$[$0]);
220 | break;
221 | case 63:
222 | this.$ = new yy.Op($$[$0-3], $$[$0-4], $$[$0-1]);
223 | break;
224 | case 65:
225 | this.$ = new yy.UnaryOp($$[$0-1], $$[$0]);
226 | break;
227 | case 67:
228 | this.$ = new yy.WhitepaceList($$[$0]);
229 | break;
230 | case 70:
231 | this.$ = new yy.BetweenOp([$$[$0-2], $$[$0]]);
232 | break;
233 | case 71:
234 | this.$ = new yy.Case($$[$0-1]);
235 | break;
236 | case 72:
237 | this.$ = new yy.Case($$[$0-2], $$[$0-1]);
238 | break;
239 | case 73:
240 | this.$ = new yy.CaseWhen($$[$0-2], $$[$0]);
241 | break;
242 | case 76:
243 | this.$ = new yy.CaseElse($$[$0]);
244 | break;
245 | case 85:
246 | this.$ = [$$[$0-1], $$[$0]];
247 | break;
248 | case 86:
249 | this.$ = (function(){ $$[$0-1].push($$[$0]); return $$[$0-1]; }());
250 | break;
251 | case 87:
252 | this.$ = new yy.ListValue($$[$0]);
253 | break;
254 | case 88:
255 | this.$ = new yy.NumberValue($$[$0]);
256 | break;
257 | case 89:
258 | this.$ = new yy.BooleanValue($$[$0]);
259 | break;
260 | case 90:
261 | this.$ = new yy.ParameterValue($$[$0]);
262 | break;
263 | case 91:
264 | this.$ = new yy.StringValue($$[$0], "'");
265 | break;
266 | case 92:
267 | this.$ = new yy.StringValue($$[$0], '"');
268 | break;
269 | case 93:
270 | this.$ = new yy.LiteralValue($$[$0]);
271 | break;
272 | case 94:
273 | this.$ = new yy.LiteralValue($$[$0-2], $$[$0]);
274 | break;
275 | case 95:
276 | this.$ = new yy.FunctionValue($$[$0-3], $$[$0-1]);
277 | break;
278 | case 96:
279 | this.$ = new yy.FunctionValue($$[$0-2], null, true);
280 | break;
281 | case 97: case 98:
282 | this.$ = new yy.FunctionValue($$[$0-3], $$[$0-1], true);
283 | break;
284 | case 99:
285 | this.$ = new yy.ArgumentListValue($$[$0]);
286 | break;
287 | case 100:
288 | this.$ = new yy.ArgumentListValue($$[$0], true);
289 | break;
290 | case 105:
291 | this.$ = new yy.Star();
292 | break;
293 | case 106:
294 | this.$ = new yy.Field($$[$0]);
295 | break;
296 | case 107:
297 | this.$ = new yy.Field($$[$0-2], $$[$0]);
298 | break;
299 | }
300 | },
301 | table: [{3:1,4:2,6:3,8:4,9:5,10:6,14:7,16:$V0},{1:[3]},{5:[1,9]},o($V1,[2,2],{7:10,13:11,30:12,31:$V2,42:$V3}),o($V4,[2,4]),o($V4,[2,5]),o($V4,[2,6],{11:15,12:16,60:18,45:$V5,62:[1,19]}),o($V6,[2,11],{15:20,41:[1,21]}),{17:22,20:[1,23],22:33,24:$V7,29:34,36:26,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg,99:24,100:$Vh},{1:[2,1]},o($V1,[2,3],{30:48,31:$V2}),o($V4,[2,10]),o($Vi,[2,24]),{29:49,89:$Va},{6:50,8:4,9:5,10:6,14:7,16:$V0,32:[1,51]},o($V4,[2,7]),o($V4,[2,8],{11:52,45:$V5}),{46:[1,53]},o($Vj,[2,53],{61:54,64:[1,55]}),{46:[1,56]},o($V6,[2,12]),{22:33,24:$V7,29:34,36:57,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{18:[1,58],43:$Vk},{17:60,22:33,24:$V7,29:34,36:26,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg,99:24,100:$Vh},o($Vl,[2,103]),o($Vl,[2,105]),o($Vl,[2,106],{23:[1,61],65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),{4:68,6:3,8:4,9:5,10:6,14:7,16:$V0,22:33,24:$V7,29:34,36:67,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($Vr,[2,69],{22:33,29:34,84:35,85:36,86:37,87:38,88:39,50:70,71:[1,69],89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg}),{24:[1,72],72:71},o($Vr,[2,66]),o($Vr,[2,67],{22:33,29:34,84:35,85:36,86:37,87:38,88:39,50:73,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg}),o($Vr,[2,68]),o($Vs,[2,78],{95:$Vt}),o($Vs,[2,79]),o($Vs,[2,80]),o($Vs,[2,81]),o($Vs,[2,82]),o($Vs,[2,83]),o($Vs,[2,84]),{77:75,80:76,81:$Vu},o([5,18,23,26,31,34,37,38,41,42,43,44,45,51,62,64,65,66,67,68,70,71,78,81,82,83,89,90,91,92,93,94,95,96],$Vv,{24:[1,78]}),o([5,18,23,26,31,34,37,38,41,42,43,44,45,51,54,55,62,64,65,66,67,68,70,71,78,81,82,83,89,90,91,92,93,94,96],[2,88]),o($Vs,[2,91]),o($Vs,[2,92]),{24:[1,79]},o($Vs,[2,89]),o($Vs,[2,90]),o($Vi,[2,25]),o($V4,[2,38],{43:[1,80],44:[1,81]}),o($Vi,[2,26],{13:11,42:$V3}),{6:82,8:4,9:5,10:6,14:7,16:$V0},o($V4,[2,9]),{22:33,29:34,47:83,49:84,50:85,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($Vj,[2,54]),{22:33,24:$V7,29:34,36:86,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{22:33,24:$V7,29:34,36:88,50:28,63:87,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($V6,[2,37],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),{19:89,22:90,24:$Vw,94:$Vx},{22:33,24:$V7,29:34,36:26,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg,99:93,100:$Vh},{18:[1,94],43:$Vk},{22:95,94:$Vx},{22:33,24:$V7,29:34,36:96,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{22:33,24:$V7,29:34,36:97,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{22:33,24:$V7,29:34,36:98,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{22:33,24:$V7,29:34,36:100,50:28,69:99,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{22:33,24:$V7,29:34,36:101,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{26:[1,102],65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq},{26:[1,103]},{24:[1,104],72:105},o($Vy,[2,85]),o($Vr,[2,65]),{4:68,6:3,8:4,9:5,10:6,14:7,16:$V0},o($Vy,[2,86]),{94:[1,106]},{78:[1,107],79:108,80:109,81:$Vu,83:[1,110]},o($Vz,[2,75]),{22:33,24:$V7,29:34,36:111,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{20:$VA,22:33,24:$V7,26:[1,112],29:34,36:88,50:28,63:115,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg,97:113,98:[1,114]},{20:$VA,22:33,24:$V7,29:34,36:88,50:28,63:115,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg,97:117},{29:118,89:$Va},{29:119,89:$Va},o($Vi,[2,27],{13:11,42:$V3}),o($V4,[2,41],{48:120,43:[1,121],44:[1,122]}),o($VB,[2,43]),o($VB,[2,45],{51:[1,123]}),o($Vj,[2,56],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),o([5,26,31,42,45,64],[2,55],{43:$VC}),o($VD,[2,101],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),o($VE,[2,13],{21:125,33:126,34:$VF,37:$VG,38:$VH}),o($VI,[2,17],{22:130,23:[1,131],27:[1,132],94:$Vx,95:$Vt}),{4:134,6:3,8:4,9:5,10:6,14:7,16:$V0,22:33,24:$V7,25:133,29:34,36:88,50:28,63:135,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o([5,18,23,26,27,31,34,35,37,38,41,42,43,45,62,94,95],$Vv),o($Vl,[2,104]),{19:136,22:90,24:$Vw,94:$Vx},o($Vl,[2,107],{95:$Vt}),o([5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,67,70,78,81,82,83],[2,58],{66:$Vn,68:$Vp}),o([5,18,23,26,31,34,37,38,41,42,43,45,62,64,65,66,67,70,78,81,82,83],[2,59],{68:$Vp}),o([5,18,23,26,31,34,37,38,41,42,43,45,62,64,67,70,78,81,82,83],[2,60],{65:$Vm,66:$Vn,68:$Vp}),o($Vr,[2,61]),{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:[1,137]},o($VJ,[2,62],{65:$Vm,66:$Vn,67:$Vo,68:$Vp}),o($Vr,[2,57]),o($Vr,[2,77]),{4:68,6:3,8:4,9:5,10:6,14:7,16:$V0,22:33,24:$V7,25:138,29:34,36:88,50:28,63:135,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($Vr,[2,64]),o([5,18,23,26,27,31,34,35,37,38,41,42,43,44,45,51,62,64,65,66,67,68,70,71,78,81,82,83,89,90,91,92,93,94,95,96],[2,94]),o($Vr,[2,71]),{78:[1,139]},o($Vz,[2,74]),{22:33,24:$V7,29:34,36:140,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq,82:[1,141]},o($Vs,[2,96]),{26:[1,142]},{26:[1,143]},{26:[2,99],43:$VC},{22:33,24:$V7,29:34,36:88,50:28,63:144,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{26:[1,145]},o($V4,[2,39]),o($V4,[2,40]),o($V4,[2,42]),{22:33,29:34,49:146,50:85,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{29:148,52:147,89:$Va},o($VB,[2,46]),{22:33,24:$V7,29:34,36:149,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($VE,[2,15],{33:150,34:$VF,37:$VG,38:$VH}),o($VK,[2,28]),{19:151,22:90,24:$Vw,94:$Vx},{34:[1,152],39:[1,153],40:[1,154]},{34:[1,155],39:[1,156],40:[1,157]},o($VI,[2,18],{95:$Vt}),{22:158,94:$Vx},{28:[1,159]},{26:[1,160]},{26:[1,161]},{26:[2,87],43:$VC},o($VE,[2,14],{33:126,21:162,34:$VF,37:$VG,38:$VH}),{22:33,24:$V7,29:34,36:163,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{26:[1,164]},o($Vr,[2,72]),{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq,78:[2,76]},{22:33,24:$V7,29:34,36:165,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($Vs,[2,97]),o($Vs,[2,98]),{26:[2,100],43:$VC},o($Vs,[2,95]),o($VB,[2,44]),o($V4,[2,47],{53:166,56:[1,167]}),{54:[1,168],55:[1,169]},o($VD,[2,102],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),o($VK,[2,29]),{35:[1,170]},{19:171,22:90,24:$Vw,94:$Vx},{34:[1,172]},{34:[1,173]},{19:174,22:90,24:$Vw,94:$Vx},{34:[1,175]},{34:[1,176]},o($VI,[2,19],{95:$Vt}),{24:[1,177]},o($VI,[2,20]),o($VI,[2,21],{22:178,94:$Vx}),o($VE,[2,16],{33:150,34:$VF,37:$VG,38:$VH}),o($VJ,[2,70],{65:$Vm,66:$Vn,67:$Vo,68:$Vp}),o($Vr,[2,63]),o($Vz,[2,73],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),o($V4,[2,48]),{57:[1,179],59:[1,180]},o($VL,[2,49]),o($VL,[2,50]),{22:33,24:$V7,29:34,36:181,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{35:[1,182]},{19:183,22:90,24:$Vw,94:$Vx},{19:184,22:90,24:$Vw,94:$Vx},{35:[1,185]},{19:186,22:90,24:$Vw,94:$Vx},{19:187,22:90,24:$Vw,94:$Vx},{29:188,89:$Va},o($VI,[2,22],{95:$Vt}),{29:148,52:189,89:$Va},{29:148,52:190,89:$Va},o($VK,[2,30],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),{22:33,24:$V7,29:34,36:191,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{35:[1,192]},{35:[1,193]},{22:33,24:$V7,29:34,36:194,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{35:[1,195]},{35:[1,196]},{26:[1,197]},{58:[1,198]},{58:[1,199]},o($VK,[2,31],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),{22:33,24:$V7,29:34,36:200,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{22:33,24:$V7,29:34,36:201,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($VK,[2,32],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),{22:33,24:$V7,29:34,36:202,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},{22:33,24:$V7,29:34,36:203,50:28,72:30,73:$V8,74:31,75:32,76:$V9,84:35,85:36,86:37,87:38,88:39,89:$Va,90:$Vb,91:$Vc,92:$Vd,93:$Ve,94:$Vf,96:$Vg},o($VI,[2,23]),o($V4,[2,51]),o($V4,[2,52]),o($VK,[2,33],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),o($VK,[2,35],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),o($VK,[2,34],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq}),o($VK,[2,36],{65:$Vm,66:$Vn,67:$Vo,68:$Vp,70:$Vq})],
302 | defaultActions: {9:[2,1]},
303 | parseError: function parseError (str, hash) {
304 | if (hash.recoverable) {
305 | this.trace(str);
306 | } else {
307 | var error = new Error(str);
308 | error.hash = hash;
309 | throw error;
310 | }
311 | },
312 | parse: function parse(input) {
313 | var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
314 | var args = lstack.slice.call(arguments, 1);
315 | var lexer = Object.create(this.lexer);
316 | var sharedState = { yy: {} };
317 | for (var k in this.yy) {
318 | if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
319 | sharedState.yy[k] = this.yy[k];
320 | }
321 | }
322 | lexer.setInput(input, sharedState.yy);
323 | sharedState.yy.lexer = lexer;
324 | sharedState.yy.parser = this;
325 | if (typeof lexer.yylloc == 'undefined') {
326 | lexer.yylloc = {};
327 | }
328 | var yyloc = lexer.yylloc;
329 | lstack.push(yyloc);
330 | var ranges = lexer.options && lexer.options.ranges;
331 | if (typeof sharedState.yy.parseError === 'function') {
332 | this.parseError = sharedState.yy.parseError;
333 | } else {
334 | this.parseError = Object.getPrototypeOf(this).parseError;
335 | }
336 | function popStack(n) {
337 | stack.length = stack.length - 2 * n;
338 | vstack.length = vstack.length - n;
339 | lstack.length = lstack.length - n;
340 | }
341 | _token_stack:
342 | var lex = function () {
343 | var token;
344 | token = lexer.lex() || EOF;
345 | if (typeof token !== 'number') {
346 | token = self.symbols_[token] || token;
347 | }
348 | return token;
349 | };
350 | var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
351 | while (true) {
352 | state = stack[stack.length - 1];
353 | if (this.defaultActions[state]) {
354 | action = this.defaultActions[state];
355 | } else {
356 | if (symbol === null || typeof symbol == 'undefined') {
357 | symbol = lex();
358 | }
359 | action = table[state] && table[state][symbol];
360 | }
361 | if (typeof action === 'undefined' || !action.length || !action[0]) {
362 | var errStr = '';
363 | expected = [];
364 | for (p in table[state]) {
365 | if (this.terminals_[p] && p > TERROR) {
366 | expected.push('\'' + this.terminals_[p] + '\'');
367 | }
368 | }
369 | if (lexer.showPosition) {
370 | errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
371 | } else {
372 | errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
373 | }
374 | this.parseError(errStr, {
375 | text: lexer.match,
376 | token: this.terminals_[symbol] || symbol,
377 | line: lexer.yylineno,
378 | loc: yyloc,
379 | expected: expected
380 | });
381 | }
382 | if (action[0] instanceof Array && action.length > 1) {
383 | throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
384 | }
385 | switch (action[0]) {
386 | case 1:
387 | stack.push(symbol);
388 | vstack.push(lexer.yytext);
389 | lstack.push(lexer.yylloc);
390 | stack.push(action[1]);
391 | symbol = null;
392 | if (!preErrorSymbol) {
393 | yyleng = lexer.yyleng;
394 | yytext = lexer.yytext;
395 | yylineno = lexer.yylineno;
396 | yyloc = lexer.yylloc;
397 | if (recovering > 0) {
398 | recovering--;
399 | }
400 | } else {
401 | symbol = preErrorSymbol;
402 | preErrorSymbol = null;
403 | }
404 | break;
405 | case 2:
406 | len = this.productions_[action[1]][1];
407 | yyval.$ = vstack[vstack.length - len];
408 | yyval._$ = {
409 | first_line: lstack[lstack.length - (len || 1)].first_line,
410 | last_line: lstack[lstack.length - 1].last_line,
411 | first_column: lstack[lstack.length - (len || 1)].first_column,
412 | last_column: lstack[lstack.length - 1].last_column
413 | };
414 | if (ranges) {
415 | yyval._$.range = [
416 | lstack[lstack.length - (len || 1)].range[0],
417 | lstack[lstack.length - 1].range[1]
418 | ];
419 | }
420 | r = this.performAction.apply(yyval, [
421 | yytext,
422 | yyleng,
423 | yylineno,
424 | sharedState.yy,
425 | action[1],
426 | vstack,
427 | lstack
428 | ].concat(args));
429 | if (typeof r !== 'undefined') {
430 | return r;
431 | }
432 | if (len) {
433 | stack = stack.slice(0, -1 * len * 2);
434 | vstack = vstack.slice(0, -1 * len);
435 | lstack = lstack.slice(0, -1 * len);
436 | }
437 | stack.push(this.productions_[action[1]][0]);
438 | vstack.push(yyval.$);
439 | lstack.push(yyval._$);
440 | newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
441 | stack.push(newState);
442 | break;
443 | case 3:
444 | return true;
445 | }
446 | }
447 | return true;
448 | }};
449 |
450 | function Parser () {
451 | this.yy = {};
452 | }
453 | Parser.prototype = parser;parser.Parser = Parser;
454 | return new Parser;
455 | })();
456 |
457 | exports.parser = parser;
--------------------------------------------------------------------------------
/browser/sql-parser.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * SQLParser (v1.3.0)
3 | * @copyright 2012-2015 Andy Kent
4 | * @copyright 2015-2019 Damien "Mistic" Sorel
5 | * @licence MIT
6 | */
7 | (function (global, factory) {
8 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
9 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
10 | (global = global || self, factory(global.SQLParser = {}));
11 | }(this, (function (exports) { 'use strict';
12 |
13 | function createCommonjsModule(fn, module) {
14 | return module = { exports: {} }, fn(module, module.exports), module.exports;
15 | }
16 |
17 | var SQL_FUNCTIONS = ['AVG', 'COUNT', 'MIN', 'MAX', 'SUM'];
18 | var SQL_SORT_ORDERS = ['ASC', 'DESC'];
19 | var SQL_OPERATORS = ['=', '!=', '>=', '>', '<=', '<>', '<', 'LIKE', 'NOT LIKE', 'ILIKE', 'NOT ILIKE', 'IS NOT', 'IS', 'REGEXP', 'NOT REGEXP'];
20 | var SUB_SELECT_OP = ['IN', 'NOT IN', 'ANY', 'ALL', 'SOME'];
21 | var SUB_SELECT_UNARY_OP = ['EXISTS'];
22 | var SQL_CONDITIONALS = ['AND', 'OR'];
23 | var SQL_BETWEENS = ['BETWEEN', 'NOT BETWEEN'];
24 | var BOOLEAN = ['TRUE', 'FALSE', 'NULL'];
25 | var MATH = ['+', '-', '||', '&&'];
26 | var MATH_MULTI = ['/', '*'];
27 | var STAR = /^\*/;
28 | var SEPARATOR = /^,/;
29 | var WHITESPACE = /^[ \n\r]+/;
30 | var LITERAL = /^`?([a-z_][a-z0-9_]{0,}(\:(number|float|string|date|boolean))?)`?/i;
31 | var PARAMETER = /^\$([a-z0-9_]+(\:(number|float|string|date|boolean))?)/;
32 | var NUMBER = /^[+-]?[0-9]+(\.[0-9]+)?/;
33 | var STRING = /^'((?:[^\\']+?|\\.|'')*)'(?!')/;
34 | var DBLSTRING = /^"([^\\"]*(?:\\.[^\\"]*)*)"/;
35 |
36 | var Lexer =
37 | /*#__PURE__*/
38 | function () {
39 | function Lexer(sql, opts) {
40 | if (opts === void 0) {
41 | opts = {};
42 | }
43 |
44 | this.sql = sql;
45 | this.preserveWhitespace = opts.preserveWhitespace || false;
46 | this.tokens = [];
47 | this.currentLine = 1;
48 | this.currentOffset = 0;
49 | var i = 0;
50 |
51 | while (!!(this.chunk = sql.slice(i))) {
52 | var bytesConsumed = this.keywordToken() || this.starToken() || this.booleanToken() || this.functionToken() || this.windowExtension() || this.sortOrderToken() || this.seperatorToken() || this.operatorToken() || this.numberToken() || this.mathToken() || this.dotToken() || this.conditionalToken() || this.betweenToken() || this.subSelectOpToken() || this.subSelectUnaryOpToken() || this.stringToken() || this.parameterToken() || this.parensToken() || this.whitespaceToken() || this.literalToken();
53 |
54 | if (bytesConsumed < 1) {
55 | throw new Error("NOTHING CONSUMED: Stopped at - '" + this.chunk.slice(0, 30) + "'");
56 | }
57 |
58 | i += bytesConsumed;
59 | this.currentOffset += bytesConsumed;
60 | }
61 |
62 | this.token('EOF', '');
63 | this.postProcess();
64 | }
65 |
66 | var _proto = Lexer.prototype;
67 |
68 | _proto.postProcess = function postProcess() {
69 | var results = [];
70 |
71 | for (var _i = 0, j = 0, len = this.tokens.length; j < len; _i = ++j) {
72 | var token = this.tokens[_i];
73 |
74 | if (token[0] === 'STAR') {
75 | var next_token = this.tokens[_i + 1];
76 |
77 | if (!(next_token[0] === 'SEPARATOR' || next_token[0] === 'FROM')) {
78 | results.push(token[0] = 'MATH_MULTI');
79 | } else {
80 | results.push(void 0);
81 | }
82 | } else {
83 | results.push(void 0);
84 | }
85 | }
86 |
87 | return results;
88 | };
89 |
90 | _proto.token = function token(name, value) {
91 | return this.tokens.push([name, value, this.currentLine, this.currentOffset]);
92 | };
93 |
94 | _proto.tokenizeFromStringRegex = function tokenizeFromStringRegex(name, regex, part, lengthPart, output) {
95 | if (part === void 0) {
96 | part = 0;
97 | }
98 |
99 | if (lengthPart === void 0) {
100 | lengthPart = part;
101 | }
102 |
103 | if (output === void 0) {
104 | output = true;
105 | }
106 |
107 | var match = regex.exec(this.chunk);
108 |
109 | if (!match) {
110 | return 0;
111 | }
112 |
113 | var partMatch = match[part].replace(/''/g, '\'');
114 |
115 | if (output) {
116 | this.token(name, partMatch);
117 | }
118 |
119 | return match[lengthPart].length;
120 | };
121 |
122 | _proto.tokenizeFromRegex = function tokenizeFromRegex(name, regex, part, lengthPart, output) {
123 | if (part === void 0) {
124 | part = 0;
125 | }
126 |
127 | if (lengthPart === void 0) {
128 | lengthPart = part;
129 | }
130 |
131 | if (output === void 0) {
132 | output = true;
133 | }
134 |
135 | var match = regex.exec(this.chunk);
136 |
137 | if (!match) {
138 | return 0;
139 | }
140 |
141 | var partMatch = match[part];
142 |
143 | if (output) {
144 | this.token(name, partMatch);
145 | }
146 |
147 | return match[lengthPart].length;
148 | };
149 |
150 | _proto.tokenizeFromWord = function tokenizeFromWord(name, word) {
151 | if (word === void 0) {
152 | word = name;
153 | }
154 |
155 | word = this.regexEscape(word);
156 | var matcher = /^\w+$/.test(word) ? new RegExp("^(" + word + ")\\b", 'ig') : new RegExp("^(" + word + ")", 'ig');
157 | var match = matcher.exec(this.chunk);
158 |
159 | if (!match) {
160 | return 0;
161 | }
162 |
163 | this.token(name, match[1]);
164 | return match[1].length;
165 | };
166 |
167 | _proto.tokenizeFromList = function tokenizeFromList(name, list) {
168 | var ret = 0;
169 |
170 | for (var j = 0, len = list.length; j < len; j++) {
171 | var entry = list[j];
172 | ret = this.tokenizeFromWord(name, entry);
173 |
174 | if (ret > 0) {
175 | break;
176 | }
177 | }
178 |
179 | return ret;
180 | };
181 |
182 | _proto.keywordToken = function keywordToken() {
183 | return this.tokenizeFromWord('SELECT') || this.tokenizeFromWord('INSERT') || this.tokenizeFromWord('INTO') || this.tokenizeFromWord('DEFAULT') || this.tokenizeFromWord('VALUES') || this.tokenizeFromWord('DISTINCT') || this.tokenizeFromWord('FROM') || this.tokenizeFromWord('WHERE') || this.tokenizeFromWord('GROUP') || this.tokenizeFromWord('ORDER') || this.tokenizeFromWord('BY') || this.tokenizeFromWord('HAVING') || this.tokenizeFromWord('LIMIT') || this.tokenizeFromWord('JOIN') || this.tokenizeFromWord('LEFT') || this.tokenizeFromWord('RIGHT') || this.tokenizeFromWord('INNER') || this.tokenizeFromWord('OUTER') || this.tokenizeFromWord('ON') || this.tokenizeFromWord('AS') || this.tokenizeFromWord('CASE') || this.tokenizeFromWord('WHEN') || this.tokenizeFromWord('THEN') || this.tokenizeFromWord('ELSE') || this.tokenizeFromWord('END') || this.tokenizeFromWord('UNION') || this.tokenizeFromWord('ALL') || this.tokenizeFromWord('LIMIT') || this.tokenizeFromWord('OFFSET') || this.tokenizeFromWord('FETCH') || this.tokenizeFromWord('ROW') || this.tokenizeFromWord('ROWS') || this.tokenizeFromWord('ONLY') || this.tokenizeFromWord('NEXT') || this.tokenizeFromWord('FIRST');
184 | };
185 |
186 | _proto.dotToken = function dotToken() {
187 | return this.tokenizeFromWord('DOT', '.');
188 | };
189 |
190 | _proto.operatorToken = function operatorToken() {
191 | return this.tokenizeFromList('OPERATOR', SQL_OPERATORS);
192 | };
193 |
194 | _proto.mathToken = function mathToken() {
195 | return this.tokenizeFromList('MATH', MATH) || this.tokenizeFromList('MATH_MULTI', MATH_MULTI);
196 | };
197 |
198 | _proto.conditionalToken = function conditionalToken() {
199 | return this.tokenizeFromList('CONDITIONAL', SQL_CONDITIONALS);
200 | };
201 |
202 | _proto.betweenToken = function betweenToken() {
203 | return this.tokenizeFromList('BETWEEN', SQL_BETWEENS);
204 | };
205 |
206 | _proto.subSelectOpToken = function subSelectOpToken() {
207 | return this.tokenizeFromList('SUB_SELECT_OP', SUB_SELECT_OP);
208 | };
209 |
210 | _proto.subSelectUnaryOpToken = function subSelectUnaryOpToken() {
211 | return this.tokenizeFromList('SUB_SELECT_UNARY_OP', SUB_SELECT_UNARY_OP);
212 | };
213 |
214 | _proto.functionToken = function functionToken() {
215 | return this.tokenizeFromList('FUNCTION', SQL_FUNCTIONS);
216 | };
217 |
218 | _proto.sortOrderToken = function sortOrderToken() {
219 | return this.tokenizeFromList('DIRECTION', SQL_SORT_ORDERS);
220 | };
221 |
222 | _proto.booleanToken = function booleanToken() {
223 | return this.tokenizeFromList('BOOLEAN', BOOLEAN);
224 | };
225 |
226 | _proto.starToken = function starToken() {
227 | return this.tokenizeFromRegex('STAR', STAR);
228 | };
229 |
230 | _proto.seperatorToken = function seperatorToken() {
231 | return this.tokenizeFromRegex('SEPARATOR', SEPARATOR);
232 | };
233 |
234 | _proto.literalToken = function literalToken() {
235 | return this.tokenizeFromRegex('LITERAL', LITERAL, 1, 0);
236 | };
237 |
238 | _proto.numberToken = function numberToken() {
239 | return this.tokenizeFromRegex('NUMBER', NUMBER);
240 | };
241 |
242 | _proto.parameterToken = function parameterToken() {
243 | return this.tokenizeFromRegex('PARAMETER', PARAMETER, 1, 0);
244 | };
245 |
246 | _proto.stringToken = function stringToken() {
247 | return this.tokenizeFromStringRegex('STRING', STRING, 1, 0) || this.tokenizeFromRegex('DBLSTRING', DBLSTRING, 1, 0);
248 | };
249 |
250 | _proto.parensToken = function parensToken() {
251 | return this.tokenizeFromRegex('LEFT_PAREN', /^\(/) || this.tokenizeFromRegex('RIGHT_PAREN', /^\)/);
252 | };
253 |
254 | _proto.windowExtension = function windowExtension() {
255 | var match = /^\.(win):(length|time)/i.exec(this.chunk);
256 |
257 | if (!match) {
258 | return 0;
259 | }
260 |
261 | this.token('WINDOW', match[1]);
262 | this.token('WINDOW_FUNCTION', match[2]);
263 | return match[0].length;
264 | };
265 |
266 | _proto.whitespaceToken = function whitespaceToken() {
267 | var match = WHITESPACE.exec(this.chunk);
268 |
269 | if (!match) {
270 | return 0;
271 | }
272 |
273 | var partMatch = match[0];
274 |
275 | if (this.preserveWhitespace) {
276 | this.token('WHITESPACE', partMatch);
277 | }
278 |
279 | var newlines = partMatch.match(/\n/g, '');
280 | this.currentLine += (newlines != null ? newlines.length : void 0) || 0;
281 | return partMatch.length;
282 | };
283 |
284 | _proto.regexEscape = function regexEscape(str) {
285 | return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
286 | };
287 |
288 | return Lexer;
289 | }();
290 |
291 | var tokenize = function tokenize(sql, opts) {
292 | return new Lexer(sql, opts).tokens;
293 | };
294 |
295 | var lexer = {
296 | tokenize: tokenize
297 | };
298 |
299 | /* parser generated by jison 0.4.18 */
300 |
301 | /*
302 | Returns a Parser object of the following structure:
303 |
304 | Parser: {
305 | yy: {}
306 | }
307 |
308 | Parser.prototype: {
309 | yy: {},
310 | trace: function(),
311 | symbols_: {associative list: name ==> number},
312 | terminals_: {associative list: number ==> name},
313 | productions_: [...],
314 | performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$),
315 | table: [...],
316 | defaultActions: {...},
317 | parseError: function(str, hash),
318 | parse: function(input),
319 |
320 | lexer: {
321 | EOF: 1,
322 | parseError: function(str, hash),
323 | setInput: function(input),
324 | input: function(),
325 | unput: function(str),
326 | more: function(),
327 | less: function(n),
328 | pastInput: function(),
329 | upcomingInput: function(),
330 | showPosition: function(),
331 | test_match: function(regex_match_array, rule_index),
332 | next: function(),
333 | lex: function(),
334 | begin: function(condition),
335 | popState: function(),
336 | _currentRules: function(),
337 | topState: function(),
338 | pushState: function(condition),
339 |
340 | options: {
341 | ranges: boolean (optional: true ==> token location info will include a .range[] member)
342 | flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match)
343 | backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code)
344 | },
345 |
346 | performAction: function(yy, yy_, $avoiding_name_collisions, YY_START),
347 | rules: [...],
348 | conditions: {associative list: name ==> set},
349 | }
350 | }
351 |
352 |
353 | token location info (@$, _$, etc.): {
354 | first_line: n,
355 | last_line: n,
356 | first_column: n,
357 | last_column: n,
358 | range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based)
359 | }
360 |
361 |
362 | the parseError function receives a 'hash' object with these members for lexer and parser errors: {
363 | text: (matched text)
364 | token: (the produced terminal token, if any)
365 | line: (yylineno)
366 | }
367 | while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: {
368 | loc: (yylloc)
369 | expected: (string describing the set of expected tokens)
370 | recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error)
371 | }
372 | */
373 | var parser = function () {
374 | var o = function o(k, v, _o, l) {
375 | for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v) {
376 | }
377 |
378 | return _o;
379 | },
380 | $V0 = [1, 8],
381 | $V1 = [5, 26],
382 | $V2 = [1, 14],
383 | $V3 = [1, 13],
384 | $V4 = [5, 26, 31, 42],
385 | $V5 = [1, 17],
386 | $V6 = [5, 26, 31, 42, 45, 62],
387 | $V7 = [1, 27],
388 | $V8 = [1, 29],
389 | $V9 = [1, 40],
390 | $Va = [1, 42],
391 | $Vb = [1, 46],
392 | $Vc = [1, 47],
393 | $Vd = [1, 43],
394 | $Ve = [1, 44],
395 | $Vf = [1, 41],
396 | $Vg = [1, 45],
397 | $Vh = [1, 25],
398 | $Vi = [5, 26, 31],
399 | $Vj = [5, 26, 31, 42, 45],
400 | $Vk = [1, 59],
401 | $Vl = [18, 43],
402 | $Vm = [1, 62],
403 | $Vn = [1, 63],
404 | $Vo = [1, 64],
405 | $Vp = [1, 65],
406 | $Vq = [1, 66],
407 | $Vr = [5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 45, 62, 64, 65, 66, 67, 68, 70, 78, 81, 82, 83],
408 | $Vs = [5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 44, 45, 51, 62, 64, 65, 66, 67, 68, 70, 71, 78, 81, 82, 83, 89, 90, 91, 92, 93, 94, 96],
409 | $Vt = [1, 74],
410 | $Vu = [1, 77],
411 | $Vv = [2, 93],
412 | $Vw = [1, 91],
413 | $Vx = [1, 92],
414 | $Vy = [5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 45, 62, 64, 65, 66, 67, 68, 70, 78, 81, 82, 83, 89, 90, 91, 92, 93, 94, 96],
415 | $Vz = [78, 81, 83],
416 | $VA = [1, 116],
417 | $VB = [5, 26, 31, 42, 43, 44],
418 | $VC = [1, 124],
419 | $VD = [5, 26, 31, 42, 43, 45, 64],
420 | $VE = [5, 26, 31, 41, 42, 45, 62],
421 | $VF = [1, 127],
422 | $VG = [1, 128],
423 | $VH = [1, 129],
424 | $VI = [5, 26, 31, 34, 35, 37, 38, 41, 42, 45, 62],
425 | $VJ = [5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 45, 62, 64, 70, 78, 81, 82, 83],
426 | $VK = [5, 26, 31, 34, 37, 38, 41, 42, 45, 62],
427 | $VL = [5, 26, 31, 42, 56, 58];
428 |
429 | var parser = {
430 | trace: function trace() {},
431 | yy: {},
432 | symbols_: {
433 | "error": 2,
434 | "Root": 3,
435 | "Query": 4,
436 | "EOF": 5,
437 | "SelectQuery": 6,
438 | "Unions": 7,
439 | "SelectWithLimitQuery": 8,
440 | "BasicSelectQuery": 9,
441 | "Select": 10,
442 | "OrderClause": 11,
443 | "GroupClause": 12,
444 | "LimitClause": 13,
445 | "SelectClause": 14,
446 | "WhereClause": 15,
447 | "SELECT": 16,
448 | "Fields": 17,
449 | "FROM": 18,
450 | "Table": 19,
451 | "DISTINCT": 20,
452 | "Joins": 21,
453 | "Literal": 22,
454 | "AS": 23,
455 | "LEFT_PAREN": 24,
456 | "List": 25,
457 | "RIGHT_PAREN": 26,
458 | "WINDOW": 27,
459 | "WINDOW_FUNCTION": 28,
460 | "Number": 29,
461 | "Union": 30,
462 | "UNION": 31,
463 | "ALL": 32,
464 | "Join": 33,
465 | "JOIN": 34,
466 | "ON": 35,
467 | "Expression": 36,
468 | "LEFT": 37,
469 | "RIGHT": 38,
470 | "INNER": 39,
471 | "OUTER": 40,
472 | "WHERE": 41,
473 | "LIMIT": 42,
474 | "SEPARATOR": 43,
475 | "OFFSET": 44,
476 | "ORDER": 45,
477 | "BY": 46,
478 | "OrderArgs": 47,
479 | "OffsetClause": 48,
480 | "OrderArg": 49,
481 | "Value": 50,
482 | "DIRECTION": 51,
483 | "OffsetRows": 52,
484 | "FetchClause": 53,
485 | "ROW": 54,
486 | "ROWS": 55,
487 | "FETCH": 56,
488 | "FIRST": 57,
489 | "ONLY": 58,
490 | "NEXT": 59,
491 | "GroupBasicClause": 60,
492 | "HavingClause": 61,
493 | "GROUP": 62,
494 | "ArgumentList": 63,
495 | "HAVING": 64,
496 | "MATH": 65,
497 | "MATH_MULTI": 66,
498 | "OPERATOR": 67,
499 | "BETWEEN": 68,
500 | "BetweenExpression": 69,
501 | "CONDITIONAL": 70,
502 | "SUB_SELECT_OP": 71,
503 | "SubSelectExpression": 72,
504 | "SUB_SELECT_UNARY_OP": 73,
505 | "WhitepaceList": 74,
506 | "CaseStatement": 75,
507 | "CASE": 76,
508 | "CaseWhens": 77,
509 | "END": 78,
510 | "CaseElse": 79,
511 | "CaseWhen": 80,
512 | "WHEN": 81,
513 | "THEN": 82,
514 | "ELSE": 83,
515 | "String": 84,
516 | "Function": 85,
517 | "UserFunction": 86,
518 | "Boolean": 87,
519 | "Parameter": 88,
520 | "NUMBER": 89,
521 | "BOOLEAN": 90,
522 | "PARAMETER": 91,
523 | "STRING": 92,
524 | "DBLSTRING": 93,
525 | "LITERAL": 94,
526 | "DOT": 95,
527 | "FUNCTION": 96,
528 | "AggregateArgumentList": 97,
529 | "Case": 98,
530 | "Field": 99,
531 | "STAR": 100,
532 | "$accept": 0,
533 | "$end": 1
534 | },
535 | terminals_: {
536 | 2: "error",
537 | 5: "EOF",
538 | 16: "SELECT",
539 | 18: "FROM",
540 | 20: "DISTINCT",
541 | 23: "AS",
542 | 24: "LEFT_PAREN",
543 | 26: "RIGHT_PAREN",
544 | 27: "WINDOW",
545 | 28: "WINDOW_FUNCTION",
546 | 31: "UNION",
547 | 32: "ALL",
548 | 34: "JOIN",
549 | 35: "ON",
550 | 37: "LEFT",
551 | 38: "RIGHT",
552 | 39: "INNER",
553 | 40: "OUTER",
554 | 41: "WHERE",
555 | 42: "LIMIT",
556 | 43: "SEPARATOR",
557 | 44: "OFFSET",
558 | 45: "ORDER",
559 | 46: "BY",
560 | 51: "DIRECTION",
561 | 54: "ROW",
562 | 55: "ROWS",
563 | 56: "FETCH",
564 | 57: "FIRST",
565 | 58: "ONLY",
566 | 59: "NEXT",
567 | 62: "GROUP",
568 | 64: "HAVING",
569 | 65: "MATH",
570 | 66: "MATH_MULTI",
571 | 67: "OPERATOR",
572 | 68: "BETWEEN",
573 | 70: "CONDITIONAL",
574 | 71: "SUB_SELECT_OP",
575 | 73: "SUB_SELECT_UNARY_OP",
576 | 76: "CASE",
577 | 78: "END",
578 | 81: "WHEN",
579 | 82: "THEN",
580 | 83: "ELSE",
581 | 89: "NUMBER",
582 | 90: "BOOLEAN",
583 | 91: "PARAMETER",
584 | 92: "STRING",
585 | 93: "DBLSTRING",
586 | 94: "LITERAL",
587 | 95: "DOT",
588 | 96: "FUNCTION",
589 | 98: "Case",
590 | 100: "STAR"
591 | },
592 | productions_: [0, [3, 2], [4, 1], [4, 2], [6, 1], [6, 1], [9, 1], [9, 2], [9, 2], [9, 3], [8, 2], [10, 1], [10, 2], [14, 4], [14, 5], [14, 5], [14, 6], [19, 1], [19, 2], [19, 3], [19, 3], [19, 3], [19, 4], [19, 6], [7, 1], [7, 2], [30, 2], [30, 3], [21, 1], [21, 2], [33, 4], [33, 5], [33, 5], [33, 6], [33, 6], [33, 6], [33, 6], [15, 2], [13, 2], [13, 4], [13, 4], [11, 3], [11, 4], [47, 1], [47, 3], [49, 1], [49, 2], [48, 2], [48, 3], [52, 2], [52, 2], [53, 4], [53, 4], [12, 1], [12, 2], [60, 3], [61, 2], [36, 3], [36, 3], [36, 3], [36, 3], [36, 3], [36, 3], [36, 5], [36, 3], [36, 2], [36, 1], [36, 1], [36, 1], [36, 1], [69, 3], [75, 3], [75, 4], [80, 4], [77, 2], [77, 1], [79, 2], [72, 3], [50, 1], [50, 1], [50, 1], [50, 1], [50, 1], [50, 1], [50, 1], [74, 2], [74, 2], [25, 1], [29, 1], [87, 1], [88, 1], [84, 1], [84, 1], [22, 1], [22, 3], [85, 4], [86, 3], [86, 4], [86, 4], [97, 1], [97, 2], [63, 1], [63, 3], [17, 1], [17, 3], [99, 1], [99, 1], [99, 3]],
593 | performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate
594 | /* action[1] */
595 | , $$
596 | /* vstack */
597 | , _$
598 | /* lstack */
599 | ) {
600 | /* this == yyval */
601 | var $0 = $$.length - 1;
602 |
603 | switch (yystate) {
604 | case 1:
605 | return this.$ = $$[$0 - 1];
606 |
607 | case 2:
608 | case 4:
609 | case 5:
610 | case 6:
611 | case 11:
612 | case 53:
613 | case 66:
614 | case 68:
615 | case 69:
616 | case 78:
617 | case 79:
618 | case 80:
619 | case 81:
620 | case 82:
621 | case 83:
622 | case 84:
623 | this.$ = $$[$0];
624 | break;
625 |
626 | case 3:
627 | this.$ = function () {
628 | $$[$0 - 1].unions = $$[$0];
629 | return $$[$0 - 1];
630 | }();
631 |
632 | break;
633 |
634 | case 7:
635 | this.$ = function () {
636 | $$[$0 - 1].order = $$[$0];
637 | return $$[$0 - 1];
638 | }();
639 |
640 | break;
641 |
642 | case 8:
643 | this.$ = function () {
644 | $$[$0 - 1].group = $$[$0];
645 | return $$[$0 - 1];
646 | }();
647 |
648 | break;
649 |
650 | case 9:
651 | this.$ = function () {
652 | $$[$0 - 2].group = $$[$0 - 1];
653 | $$[$0 - 2].order = $$[$0];
654 | return $$[$0 - 2];
655 | }();
656 |
657 | break;
658 |
659 | case 10:
660 | this.$ = function () {
661 | $$[$0 - 1].limit = $$[$0];
662 | return $$[$0 - 1];
663 | }();
664 |
665 | break;
666 |
667 | case 12:
668 | this.$ = function () {
669 | $$[$0 - 1].where = $$[$0];
670 | return $$[$0 - 1];
671 | }();
672 |
673 | break;
674 |
675 | case 13:
676 | this.$ = new yy.Select($$[$0 - 2], $$[$0], false);
677 | break;
678 |
679 | case 14:
680 | this.$ = new yy.Select($$[$0 - 2], $$[$0], true);
681 | break;
682 |
683 | case 15:
684 | this.$ = new yy.Select($$[$0 - 3], $$[$0 - 1], false, $$[$0]);
685 | break;
686 |
687 | case 16:
688 | this.$ = new yy.Select($$[$0 - 3], $$[$0 - 1], true, $$[$0]);
689 | break;
690 |
691 | case 17:
692 | this.$ = new yy.Table($$[$0]);
693 | break;
694 |
695 | case 18:
696 | this.$ = new yy.Table($$[$0 - 1], $$[$0]);
697 | break;
698 |
699 | case 19:
700 | this.$ = new yy.Table($$[$0 - 2], $$[$0]);
701 | break;
702 |
703 | case 20:
704 | case 49:
705 | case 50:
706 | case 51:
707 | case 52:
708 | case 57:
709 | this.$ = $$[$0 - 1];
710 | break;
711 |
712 | case 21:
713 | case 77:
714 | this.$ = new yy.SubSelect($$[$0 - 1]);
715 | break;
716 |
717 | case 22:
718 | this.$ = new yy.SubSelect($$[$0 - 2], $$[$0]);
719 | break;
720 |
721 | case 23:
722 | this.$ = new yy.Table($$[$0 - 5], null, $$[$0 - 4], $$[$0 - 3], $$[$0 - 1]);
723 | break;
724 |
725 | case 24:
726 | case 28:
727 | case 43:
728 | case 75:
729 | case 101:
730 | case 103:
731 | this.$ = [$$[$0]];
732 | break;
733 |
734 | case 25:
735 | case 29:
736 | case 74:
737 | this.$ = $$[$0 - 1].concat($$[$0]);
738 | break;
739 |
740 | case 26:
741 | this.$ = new yy.Union($$[$0]);
742 | break;
743 |
744 | case 27:
745 | this.$ = new yy.Union($$[$0], true);
746 | break;
747 |
748 | case 30:
749 | this.$ = new yy.Join($$[$0 - 2], $$[$0]);
750 | break;
751 |
752 | case 31:
753 | this.$ = new yy.Join($$[$0 - 2], $$[$0], 'LEFT');
754 | break;
755 |
756 | case 32:
757 | this.$ = new yy.Join($$[$0 - 2], $$[$0], 'RIGHT');
758 | break;
759 |
760 | case 33:
761 | this.$ = new yy.Join($$[$0 - 2], $$[$0], 'LEFT', 'INNER');
762 | break;
763 |
764 | case 34:
765 | this.$ = new yy.Join($$[$0 - 2], $$[$0], 'RIGHT', 'INNER');
766 | break;
767 |
768 | case 35:
769 | this.$ = new yy.Join($$[$0 - 2], $$[$0], 'LEFT', 'OUTER');
770 | break;
771 |
772 | case 36:
773 | this.$ = new yy.Join($$[$0 - 2], $$[$0], 'RIGHT', 'OUTER');
774 | break;
775 |
776 | case 37:
777 | this.$ = new yy.Where($$[$0]);
778 | break;
779 |
780 | case 38:
781 | this.$ = new yy.Limit($$[$0]);
782 | break;
783 |
784 | case 39:
785 | this.$ = new yy.Limit($$[$0], $$[$0 - 2]);
786 | break;
787 |
788 | case 40:
789 | this.$ = new yy.Limit($$[$0 - 2], $$[$0]);
790 | break;
791 |
792 | case 41:
793 | this.$ = new yy.Order($$[$0]);
794 | break;
795 |
796 | case 42:
797 | this.$ = new yy.Order($$[$0 - 1], $$[$0]);
798 | break;
799 |
800 | case 44:
801 | case 102:
802 | case 104:
803 | this.$ = $$[$0 - 2].concat($$[$0]);
804 | break;
805 |
806 | case 45:
807 | this.$ = new yy.OrderArgument($$[$0], 'ASC');
808 | break;
809 |
810 | case 46:
811 | this.$ = new yy.OrderArgument($$[$0 - 1], $$[$0]);
812 | break;
813 |
814 | case 47:
815 | this.$ = new yy.Offset($$[$0]);
816 | break;
817 |
818 | case 48:
819 | this.$ = new yy.Offset($$[$0 - 1], $$[$0]);
820 | break;
821 |
822 | case 54:
823 | this.$ = function () {
824 | $$[$0 - 1].having = $$[$0];
825 | return $$[$0 - 1];
826 | }();
827 |
828 | break;
829 |
830 | case 55:
831 | this.$ = new yy.Group($$[$0]);
832 | break;
833 |
834 | case 56:
835 | this.$ = new yy.Having($$[$0]);
836 | break;
837 |
838 | case 58:
839 | case 59:
840 | case 60:
841 | case 61:
842 | case 62:
843 | case 64:
844 | this.$ = new yy.Op($$[$0 - 1], $$[$0 - 2], $$[$0]);
845 | break;
846 |
847 | case 63:
848 | this.$ = new yy.Op($$[$0 - 3], $$[$0 - 4], $$[$0 - 1]);
849 | break;
850 |
851 | case 65:
852 | this.$ = new yy.UnaryOp($$[$0 - 1], $$[$0]);
853 | break;
854 |
855 | case 67:
856 | this.$ = new yy.WhitepaceList($$[$0]);
857 | break;
858 |
859 | case 70:
860 | this.$ = new yy.BetweenOp([$$[$0 - 2], $$[$0]]);
861 | break;
862 |
863 | case 71:
864 | this.$ = new yy.Case($$[$0 - 1]);
865 | break;
866 |
867 | case 72:
868 | this.$ = new yy.Case($$[$0 - 2], $$[$0 - 1]);
869 | break;
870 |
871 | case 73:
872 | this.$ = new yy.CaseWhen($$[$0 - 2], $$[$0]);
873 | break;
874 |
875 | case 76:
876 | this.$ = new yy.CaseElse($$[$0]);
877 | break;
878 |
879 | case 85:
880 | this.$ = [$$[$0 - 1], $$[$0]];
881 | break;
882 |
883 | case 86:
884 | this.$ = function () {
885 | $$[$0 - 1].push($$[$0]);
886 | return $$[$0 - 1];
887 | }();
888 |
889 | break;
890 |
891 | case 87:
892 | this.$ = new yy.ListValue($$[$0]);
893 | break;
894 |
895 | case 88:
896 | this.$ = new yy.NumberValue($$[$0]);
897 | break;
898 |
899 | case 89:
900 | this.$ = new yy.BooleanValue($$[$0]);
901 | break;
902 |
903 | case 90:
904 | this.$ = new yy.ParameterValue($$[$0]);
905 | break;
906 |
907 | case 91:
908 | this.$ = new yy.StringValue($$[$0], "'");
909 | break;
910 |
911 | case 92:
912 | this.$ = new yy.StringValue($$[$0], '"');
913 | break;
914 |
915 | case 93:
916 | this.$ = new yy.LiteralValue($$[$0]);
917 | break;
918 |
919 | case 94:
920 | this.$ = new yy.LiteralValue($$[$0 - 2], $$[$0]);
921 | break;
922 |
923 | case 95:
924 | this.$ = new yy.FunctionValue($$[$0 - 3], $$[$0 - 1]);
925 | break;
926 |
927 | case 96:
928 | this.$ = new yy.FunctionValue($$[$0 - 2], null, true);
929 | break;
930 |
931 | case 97:
932 | case 98:
933 | this.$ = new yy.FunctionValue($$[$0 - 3], $$[$0 - 1], true);
934 | break;
935 |
936 | case 99:
937 | this.$ = new yy.ArgumentListValue($$[$0]);
938 | break;
939 |
940 | case 100:
941 | this.$ = new yy.ArgumentListValue($$[$0], true);
942 | break;
943 |
944 | case 105:
945 | this.$ = new yy.Star();
946 | break;
947 |
948 | case 106:
949 | this.$ = new yy.Field($$[$0]);
950 | break;
951 |
952 | case 107:
953 | this.$ = new yy.Field($$[$0 - 2], $$[$0]);
954 | break;
955 | }
956 | },
957 | table: [{
958 | 3: 1,
959 | 4: 2,
960 | 6: 3,
961 | 8: 4,
962 | 9: 5,
963 | 10: 6,
964 | 14: 7,
965 | 16: $V0
966 | }, {
967 | 1: [3]
968 | }, {
969 | 5: [1, 9]
970 | }, o($V1, [2, 2], {
971 | 7: 10,
972 | 13: 11,
973 | 30: 12,
974 | 31: $V2,
975 | 42: $V3
976 | }), o($V4, [2, 4]), o($V4, [2, 5]), o($V4, [2, 6], {
977 | 11: 15,
978 | 12: 16,
979 | 60: 18,
980 | 45: $V5,
981 | 62: [1, 19]
982 | }), o($V6, [2, 11], {
983 | 15: 20,
984 | 41: [1, 21]
985 | }), {
986 | 17: 22,
987 | 20: [1, 23],
988 | 22: 33,
989 | 24: $V7,
990 | 29: 34,
991 | 36: 26,
992 | 50: 28,
993 | 72: 30,
994 | 73: $V8,
995 | 74: 31,
996 | 75: 32,
997 | 76: $V9,
998 | 84: 35,
999 | 85: 36,
1000 | 86: 37,
1001 | 87: 38,
1002 | 88: 39,
1003 | 89: $Va,
1004 | 90: $Vb,
1005 | 91: $Vc,
1006 | 92: $Vd,
1007 | 93: $Ve,
1008 | 94: $Vf,
1009 | 96: $Vg,
1010 | 99: 24,
1011 | 100: $Vh
1012 | }, {
1013 | 1: [2, 1]
1014 | }, o($V1, [2, 3], {
1015 | 30: 48,
1016 | 31: $V2
1017 | }), o($V4, [2, 10]), o($Vi, [2, 24]), {
1018 | 29: 49,
1019 | 89: $Va
1020 | }, {
1021 | 6: 50,
1022 | 8: 4,
1023 | 9: 5,
1024 | 10: 6,
1025 | 14: 7,
1026 | 16: $V0,
1027 | 32: [1, 51]
1028 | }, o($V4, [2, 7]), o($V4, [2, 8], {
1029 | 11: 52,
1030 | 45: $V5
1031 | }), {
1032 | 46: [1, 53]
1033 | }, o($Vj, [2, 53], {
1034 | 61: 54,
1035 | 64: [1, 55]
1036 | }), {
1037 | 46: [1, 56]
1038 | }, o($V6, [2, 12]), {
1039 | 22: 33,
1040 | 24: $V7,
1041 | 29: 34,
1042 | 36: 57,
1043 | 50: 28,
1044 | 72: 30,
1045 | 73: $V8,
1046 | 74: 31,
1047 | 75: 32,
1048 | 76: $V9,
1049 | 84: 35,
1050 | 85: 36,
1051 | 86: 37,
1052 | 87: 38,
1053 | 88: 39,
1054 | 89: $Va,
1055 | 90: $Vb,
1056 | 91: $Vc,
1057 | 92: $Vd,
1058 | 93: $Ve,
1059 | 94: $Vf,
1060 | 96: $Vg
1061 | }, {
1062 | 18: [1, 58],
1063 | 43: $Vk
1064 | }, {
1065 | 17: 60,
1066 | 22: 33,
1067 | 24: $V7,
1068 | 29: 34,
1069 | 36: 26,
1070 | 50: 28,
1071 | 72: 30,
1072 | 73: $V8,
1073 | 74: 31,
1074 | 75: 32,
1075 | 76: $V9,
1076 | 84: 35,
1077 | 85: 36,
1078 | 86: 37,
1079 | 87: 38,
1080 | 88: 39,
1081 | 89: $Va,
1082 | 90: $Vb,
1083 | 91: $Vc,
1084 | 92: $Vd,
1085 | 93: $Ve,
1086 | 94: $Vf,
1087 | 96: $Vg,
1088 | 99: 24,
1089 | 100: $Vh
1090 | }, o($Vl, [2, 103]), o($Vl, [2, 105]), o($Vl, [2, 106], {
1091 | 23: [1, 61],
1092 | 65: $Vm,
1093 | 66: $Vn,
1094 | 67: $Vo,
1095 | 68: $Vp,
1096 | 70: $Vq
1097 | }), {
1098 | 4: 68,
1099 | 6: 3,
1100 | 8: 4,
1101 | 9: 5,
1102 | 10: 6,
1103 | 14: 7,
1104 | 16: $V0,
1105 | 22: 33,
1106 | 24: $V7,
1107 | 29: 34,
1108 | 36: 67,
1109 | 50: 28,
1110 | 72: 30,
1111 | 73: $V8,
1112 | 74: 31,
1113 | 75: 32,
1114 | 76: $V9,
1115 | 84: 35,
1116 | 85: 36,
1117 | 86: 37,
1118 | 87: 38,
1119 | 88: 39,
1120 | 89: $Va,
1121 | 90: $Vb,
1122 | 91: $Vc,
1123 | 92: $Vd,
1124 | 93: $Ve,
1125 | 94: $Vf,
1126 | 96: $Vg
1127 | }, o($Vr, [2, 69], {
1128 | 22: 33,
1129 | 29: 34,
1130 | 84: 35,
1131 | 85: 36,
1132 | 86: 37,
1133 | 87: 38,
1134 | 88: 39,
1135 | 50: 70,
1136 | 71: [1, 69],
1137 | 89: $Va,
1138 | 90: $Vb,
1139 | 91: $Vc,
1140 | 92: $Vd,
1141 | 93: $Ve,
1142 | 94: $Vf,
1143 | 96: $Vg
1144 | }), {
1145 | 24: [1, 72],
1146 | 72: 71
1147 | }, o($Vr, [2, 66]), o($Vr, [2, 67], {
1148 | 22: 33,
1149 | 29: 34,
1150 | 84: 35,
1151 | 85: 36,
1152 | 86: 37,
1153 | 87: 38,
1154 | 88: 39,
1155 | 50: 73,
1156 | 89: $Va,
1157 | 90: $Vb,
1158 | 91: $Vc,
1159 | 92: $Vd,
1160 | 93: $Ve,
1161 | 94: $Vf,
1162 | 96: $Vg
1163 | }), o($Vr, [2, 68]), o($Vs, [2, 78], {
1164 | 95: $Vt
1165 | }), o($Vs, [2, 79]), o($Vs, [2, 80]), o($Vs, [2, 81]), o($Vs, [2, 82]), o($Vs, [2, 83]), o($Vs, [2, 84]), {
1166 | 77: 75,
1167 | 80: 76,
1168 | 81: $Vu
1169 | }, o([5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 44, 45, 51, 62, 64, 65, 66, 67, 68, 70, 71, 78, 81, 82, 83, 89, 90, 91, 92, 93, 94, 95, 96], $Vv, {
1170 | 24: [1, 78]
1171 | }), o([5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 44, 45, 51, 54, 55, 62, 64, 65, 66, 67, 68, 70, 71, 78, 81, 82, 83, 89, 90, 91, 92, 93, 94, 96], [2, 88]), o($Vs, [2, 91]), o($Vs, [2, 92]), {
1172 | 24: [1, 79]
1173 | }, o($Vs, [2, 89]), o($Vs, [2, 90]), o($Vi, [2, 25]), o($V4, [2, 38], {
1174 | 43: [1, 80],
1175 | 44: [1, 81]
1176 | }), o($Vi, [2, 26], {
1177 | 13: 11,
1178 | 42: $V3
1179 | }), {
1180 | 6: 82,
1181 | 8: 4,
1182 | 9: 5,
1183 | 10: 6,
1184 | 14: 7,
1185 | 16: $V0
1186 | }, o($V4, [2, 9]), {
1187 | 22: 33,
1188 | 29: 34,
1189 | 47: 83,
1190 | 49: 84,
1191 | 50: 85,
1192 | 84: 35,
1193 | 85: 36,
1194 | 86: 37,
1195 | 87: 38,
1196 | 88: 39,
1197 | 89: $Va,
1198 | 90: $Vb,
1199 | 91: $Vc,
1200 | 92: $Vd,
1201 | 93: $Ve,
1202 | 94: $Vf,
1203 | 96: $Vg
1204 | }, o($Vj, [2, 54]), {
1205 | 22: 33,
1206 | 24: $V7,
1207 | 29: 34,
1208 | 36: 86,
1209 | 50: 28,
1210 | 72: 30,
1211 | 73: $V8,
1212 | 74: 31,
1213 | 75: 32,
1214 | 76: $V9,
1215 | 84: 35,
1216 | 85: 36,
1217 | 86: 37,
1218 | 87: 38,
1219 | 88: 39,
1220 | 89: $Va,
1221 | 90: $Vb,
1222 | 91: $Vc,
1223 | 92: $Vd,
1224 | 93: $Ve,
1225 | 94: $Vf,
1226 | 96: $Vg
1227 | }, {
1228 | 22: 33,
1229 | 24: $V7,
1230 | 29: 34,
1231 | 36: 88,
1232 | 50: 28,
1233 | 63: 87,
1234 | 72: 30,
1235 | 73: $V8,
1236 | 74: 31,
1237 | 75: 32,
1238 | 76: $V9,
1239 | 84: 35,
1240 | 85: 36,
1241 | 86: 37,
1242 | 87: 38,
1243 | 88: 39,
1244 | 89: $Va,
1245 | 90: $Vb,
1246 | 91: $Vc,
1247 | 92: $Vd,
1248 | 93: $Ve,
1249 | 94: $Vf,
1250 | 96: $Vg
1251 | }, o($V6, [2, 37], {
1252 | 65: $Vm,
1253 | 66: $Vn,
1254 | 67: $Vo,
1255 | 68: $Vp,
1256 | 70: $Vq
1257 | }), {
1258 | 19: 89,
1259 | 22: 90,
1260 | 24: $Vw,
1261 | 94: $Vx
1262 | }, {
1263 | 22: 33,
1264 | 24: $V7,
1265 | 29: 34,
1266 | 36: 26,
1267 | 50: 28,
1268 | 72: 30,
1269 | 73: $V8,
1270 | 74: 31,
1271 | 75: 32,
1272 | 76: $V9,
1273 | 84: 35,
1274 | 85: 36,
1275 | 86: 37,
1276 | 87: 38,
1277 | 88: 39,
1278 | 89: $Va,
1279 | 90: $Vb,
1280 | 91: $Vc,
1281 | 92: $Vd,
1282 | 93: $Ve,
1283 | 94: $Vf,
1284 | 96: $Vg,
1285 | 99: 93,
1286 | 100: $Vh
1287 | }, {
1288 | 18: [1, 94],
1289 | 43: $Vk
1290 | }, {
1291 | 22: 95,
1292 | 94: $Vx
1293 | }, {
1294 | 22: 33,
1295 | 24: $V7,
1296 | 29: 34,
1297 | 36: 96,
1298 | 50: 28,
1299 | 72: 30,
1300 | 73: $V8,
1301 | 74: 31,
1302 | 75: 32,
1303 | 76: $V9,
1304 | 84: 35,
1305 | 85: 36,
1306 | 86: 37,
1307 | 87: 38,
1308 | 88: 39,
1309 | 89: $Va,
1310 | 90: $Vb,
1311 | 91: $Vc,
1312 | 92: $Vd,
1313 | 93: $Ve,
1314 | 94: $Vf,
1315 | 96: $Vg
1316 | }, {
1317 | 22: 33,
1318 | 24: $V7,
1319 | 29: 34,
1320 | 36: 97,
1321 | 50: 28,
1322 | 72: 30,
1323 | 73: $V8,
1324 | 74: 31,
1325 | 75: 32,
1326 | 76: $V9,
1327 | 84: 35,
1328 | 85: 36,
1329 | 86: 37,
1330 | 87: 38,
1331 | 88: 39,
1332 | 89: $Va,
1333 | 90: $Vb,
1334 | 91: $Vc,
1335 | 92: $Vd,
1336 | 93: $Ve,
1337 | 94: $Vf,
1338 | 96: $Vg
1339 | }, {
1340 | 22: 33,
1341 | 24: $V7,
1342 | 29: 34,
1343 | 36: 98,
1344 | 50: 28,
1345 | 72: 30,
1346 | 73: $V8,
1347 | 74: 31,
1348 | 75: 32,
1349 | 76: $V9,
1350 | 84: 35,
1351 | 85: 36,
1352 | 86: 37,
1353 | 87: 38,
1354 | 88: 39,
1355 | 89: $Va,
1356 | 90: $Vb,
1357 | 91: $Vc,
1358 | 92: $Vd,
1359 | 93: $Ve,
1360 | 94: $Vf,
1361 | 96: $Vg
1362 | }, {
1363 | 22: 33,
1364 | 24: $V7,
1365 | 29: 34,
1366 | 36: 100,
1367 | 50: 28,
1368 | 69: 99,
1369 | 72: 30,
1370 | 73: $V8,
1371 | 74: 31,
1372 | 75: 32,
1373 | 76: $V9,
1374 | 84: 35,
1375 | 85: 36,
1376 | 86: 37,
1377 | 87: 38,
1378 | 88: 39,
1379 | 89: $Va,
1380 | 90: $Vb,
1381 | 91: $Vc,
1382 | 92: $Vd,
1383 | 93: $Ve,
1384 | 94: $Vf,
1385 | 96: $Vg
1386 | }, {
1387 | 22: 33,
1388 | 24: $V7,
1389 | 29: 34,
1390 | 36: 101,
1391 | 50: 28,
1392 | 72: 30,
1393 | 73: $V8,
1394 | 74: 31,
1395 | 75: 32,
1396 | 76: $V9,
1397 | 84: 35,
1398 | 85: 36,
1399 | 86: 37,
1400 | 87: 38,
1401 | 88: 39,
1402 | 89: $Va,
1403 | 90: $Vb,
1404 | 91: $Vc,
1405 | 92: $Vd,
1406 | 93: $Ve,
1407 | 94: $Vf,
1408 | 96: $Vg
1409 | }, {
1410 | 26: [1, 102],
1411 | 65: $Vm,
1412 | 66: $Vn,
1413 | 67: $Vo,
1414 | 68: $Vp,
1415 | 70: $Vq
1416 | }, {
1417 | 26: [1, 103]
1418 | }, {
1419 | 24: [1, 104],
1420 | 72: 105
1421 | }, o($Vy, [2, 85]), o($Vr, [2, 65]), {
1422 | 4: 68,
1423 | 6: 3,
1424 | 8: 4,
1425 | 9: 5,
1426 | 10: 6,
1427 | 14: 7,
1428 | 16: $V0
1429 | }, o($Vy, [2, 86]), {
1430 | 94: [1, 106]
1431 | }, {
1432 | 78: [1, 107],
1433 | 79: 108,
1434 | 80: 109,
1435 | 81: $Vu,
1436 | 83: [1, 110]
1437 | }, o($Vz, [2, 75]), {
1438 | 22: 33,
1439 | 24: $V7,
1440 | 29: 34,
1441 | 36: 111,
1442 | 50: 28,
1443 | 72: 30,
1444 | 73: $V8,
1445 | 74: 31,
1446 | 75: 32,
1447 | 76: $V9,
1448 | 84: 35,
1449 | 85: 36,
1450 | 86: 37,
1451 | 87: 38,
1452 | 88: 39,
1453 | 89: $Va,
1454 | 90: $Vb,
1455 | 91: $Vc,
1456 | 92: $Vd,
1457 | 93: $Ve,
1458 | 94: $Vf,
1459 | 96: $Vg
1460 | }, {
1461 | 20: $VA,
1462 | 22: 33,
1463 | 24: $V7,
1464 | 26: [1, 112],
1465 | 29: 34,
1466 | 36: 88,
1467 | 50: 28,
1468 | 63: 115,
1469 | 72: 30,
1470 | 73: $V8,
1471 | 74: 31,
1472 | 75: 32,
1473 | 76: $V9,
1474 | 84: 35,
1475 | 85: 36,
1476 | 86: 37,
1477 | 87: 38,
1478 | 88: 39,
1479 | 89: $Va,
1480 | 90: $Vb,
1481 | 91: $Vc,
1482 | 92: $Vd,
1483 | 93: $Ve,
1484 | 94: $Vf,
1485 | 96: $Vg,
1486 | 97: 113,
1487 | 98: [1, 114]
1488 | }, {
1489 | 20: $VA,
1490 | 22: 33,
1491 | 24: $V7,
1492 | 29: 34,
1493 | 36: 88,
1494 | 50: 28,
1495 | 63: 115,
1496 | 72: 30,
1497 | 73: $V8,
1498 | 74: 31,
1499 | 75: 32,
1500 | 76: $V9,
1501 | 84: 35,
1502 | 85: 36,
1503 | 86: 37,
1504 | 87: 38,
1505 | 88: 39,
1506 | 89: $Va,
1507 | 90: $Vb,
1508 | 91: $Vc,
1509 | 92: $Vd,
1510 | 93: $Ve,
1511 | 94: $Vf,
1512 | 96: $Vg,
1513 | 97: 117
1514 | }, {
1515 | 29: 118,
1516 | 89: $Va
1517 | }, {
1518 | 29: 119,
1519 | 89: $Va
1520 | }, o($Vi, [2, 27], {
1521 | 13: 11,
1522 | 42: $V3
1523 | }), o($V4, [2, 41], {
1524 | 48: 120,
1525 | 43: [1, 121],
1526 | 44: [1, 122]
1527 | }), o($VB, [2, 43]), o($VB, [2, 45], {
1528 | 51: [1, 123]
1529 | }), o($Vj, [2, 56], {
1530 | 65: $Vm,
1531 | 66: $Vn,
1532 | 67: $Vo,
1533 | 68: $Vp,
1534 | 70: $Vq
1535 | }), o([5, 26, 31, 42, 45, 64], [2, 55], {
1536 | 43: $VC
1537 | }), o($VD, [2, 101], {
1538 | 65: $Vm,
1539 | 66: $Vn,
1540 | 67: $Vo,
1541 | 68: $Vp,
1542 | 70: $Vq
1543 | }), o($VE, [2, 13], {
1544 | 21: 125,
1545 | 33: 126,
1546 | 34: $VF,
1547 | 37: $VG,
1548 | 38: $VH
1549 | }), o($VI, [2, 17], {
1550 | 22: 130,
1551 | 23: [1, 131],
1552 | 27: [1, 132],
1553 | 94: $Vx,
1554 | 95: $Vt
1555 | }), {
1556 | 4: 134,
1557 | 6: 3,
1558 | 8: 4,
1559 | 9: 5,
1560 | 10: 6,
1561 | 14: 7,
1562 | 16: $V0,
1563 | 22: 33,
1564 | 24: $V7,
1565 | 25: 133,
1566 | 29: 34,
1567 | 36: 88,
1568 | 50: 28,
1569 | 63: 135,
1570 | 72: 30,
1571 | 73: $V8,
1572 | 74: 31,
1573 | 75: 32,
1574 | 76: $V9,
1575 | 84: 35,
1576 | 85: 36,
1577 | 86: 37,
1578 | 87: 38,
1579 | 88: 39,
1580 | 89: $Va,
1581 | 90: $Vb,
1582 | 91: $Vc,
1583 | 92: $Vd,
1584 | 93: $Ve,
1585 | 94: $Vf,
1586 | 96: $Vg
1587 | }, o([5, 18, 23, 26, 27, 31, 34, 35, 37, 38, 41, 42, 43, 45, 62, 94, 95], $Vv), o($Vl, [2, 104]), {
1588 | 19: 136,
1589 | 22: 90,
1590 | 24: $Vw,
1591 | 94: $Vx
1592 | }, o($Vl, [2, 107], {
1593 | 95: $Vt
1594 | }), o([5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 45, 62, 64, 65, 67, 70, 78, 81, 82, 83], [2, 58], {
1595 | 66: $Vn,
1596 | 68: $Vp
1597 | }), o([5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 45, 62, 64, 65, 66, 67, 70, 78, 81, 82, 83], [2, 59], {
1598 | 68: $Vp
1599 | }), o([5, 18, 23, 26, 31, 34, 37, 38, 41, 42, 43, 45, 62, 64, 67, 70, 78, 81, 82, 83], [2, 60], {
1600 | 65: $Vm,
1601 | 66: $Vn,
1602 | 68: $Vp
1603 | }), o($Vr, [2, 61]), {
1604 | 65: $Vm,
1605 | 66: $Vn,
1606 | 67: $Vo,
1607 | 68: $Vp,
1608 | 70: [1, 137]
1609 | }, o($VJ, [2, 62], {
1610 | 65: $Vm,
1611 | 66: $Vn,
1612 | 67: $Vo,
1613 | 68: $Vp
1614 | }), o($Vr, [2, 57]), o($Vr, [2, 77]), {
1615 | 4: 68,
1616 | 6: 3,
1617 | 8: 4,
1618 | 9: 5,
1619 | 10: 6,
1620 | 14: 7,
1621 | 16: $V0,
1622 | 22: 33,
1623 | 24: $V7,
1624 | 25: 138,
1625 | 29: 34,
1626 | 36: 88,
1627 | 50: 28,
1628 | 63: 135,
1629 | 72: 30,
1630 | 73: $V8,
1631 | 74: 31,
1632 | 75: 32,
1633 | 76: $V9,
1634 | 84: 35,
1635 | 85: 36,
1636 | 86: 37,
1637 | 87: 38,
1638 | 88: 39,
1639 | 89: $Va,
1640 | 90: $Vb,
1641 | 91: $Vc,
1642 | 92: $Vd,
1643 | 93: $Ve,
1644 | 94: $Vf,
1645 | 96: $Vg
1646 | }, o($Vr, [2, 64]), o([5, 18, 23, 26, 27, 31, 34, 35, 37, 38, 41, 42, 43, 44, 45, 51, 62, 64, 65, 66, 67, 68, 70, 71, 78, 81, 82, 83, 89, 90, 91, 92, 93, 94, 95, 96], [2, 94]), o($Vr, [2, 71]), {
1647 | 78: [1, 139]
1648 | }, o($Vz, [2, 74]), {
1649 | 22: 33,
1650 | 24: $V7,
1651 | 29: 34,
1652 | 36: 140,
1653 | 50: 28,
1654 | 72: 30,
1655 | 73: $V8,
1656 | 74: 31,
1657 | 75: 32,
1658 | 76: $V9,
1659 | 84: 35,
1660 | 85: 36,
1661 | 86: 37,
1662 | 87: 38,
1663 | 88: 39,
1664 | 89: $Va,
1665 | 90: $Vb,
1666 | 91: $Vc,
1667 | 92: $Vd,
1668 | 93: $Ve,
1669 | 94: $Vf,
1670 | 96: $Vg
1671 | }, {
1672 | 65: $Vm,
1673 | 66: $Vn,
1674 | 67: $Vo,
1675 | 68: $Vp,
1676 | 70: $Vq,
1677 | 82: [1, 141]
1678 | }, o($Vs, [2, 96]), {
1679 | 26: [1, 142]
1680 | }, {
1681 | 26: [1, 143]
1682 | }, {
1683 | 26: [2, 99],
1684 | 43: $VC
1685 | }, {
1686 | 22: 33,
1687 | 24: $V7,
1688 | 29: 34,
1689 | 36: 88,
1690 | 50: 28,
1691 | 63: 144,
1692 | 72: 30,
1693 | 73: $V8,
1694 | 74: 31,
1695 | 75: 32,
1696 | 76: $V9,
1697 | 84: 35,
1698 | 85: 36,
1699 | 86: 37,
1700 | 87: 38,
1701 | 88: 39,
1702 | 89: $Va,
1703 | 90: $Vb,
1704 | 91: $Vc,
1705 | 92: $Vd,
1706 | 93: $Ve,
1707 | 94: $Vf,
1708 | 96: $Vg
1709 | }, {
1710 | 26: [1, 145]
1711 | }, o($V4, [2, 39]), o($V4, [2, 40]), o($V4, [2, 42]), {
1712 | 22: 33,
1713 | 29: 34,
1714 | 49: 146,
1715 | 50: 85,
1716 | 84: 35,
1717 | 85: 36,
1718 | 86: 37,
1719 | 87: 38,
1720 | 88: 39,
1721 | 89: $Va,
1722 | 90: $Vb,
1723 | 91: $Vc,
1724 | 92: $Vd,
1725 | 93: $Ve,
1726 | 94: $Vf,
1727 | 96: $Vg
1728 | }, {
1729 | 29: 148,
1730 | 52: 147,
1731 | 89: $Va
1732 | }, o($VB, [2, 46]), {
1733 | 22: 33,
1734 | 24: $V7,
1735 | 29: 34,
1736 | 36: 149,
1737 | 50: 28,
1738 | 72: 30,
1739 | 73: $V8,
1740 | 74: 31,
1741 | 75: 32,
1742 | 76: $V9,
1743 | 84: 35,
1744 | 85: 36,
1745 | 86: 37,
1746 | 87: 38,
1747 | 88: 39,
1748 | 89: $Va,
1749 | 90: $Vb,
1750 | 91: $Vc,
1751 | 92: $Vd,
1752 | 93: $Ve,
1753 | 94: $Vf,
1754 | 96: $Vg
1755 | }, o($VE, [2, 15], {
1756 | 33: 150,
1757 | 34: $VF,
1758 | 37: $VG,
1759 | 38: $VH
1760 | }), o($VK, [2, 28]), {
1761 | 19: 151,
1762 | 22: 90,
1763 | 24: $Vw,
1764 | 94: $Vx
1765 | }, {
1766 | 34: [1, 152],
1767 | 39: [1, 153],
1768 | 40: [1, 154]
1769 | }, {
1770 | 34: [1, 155],
1771 | 39: [1, 156],
1772 | 40: [1, 157]
1773 | }, o($VI, [2, 18], {
1774 | 95: $Vt
1775 | }), {
1776 | 22: 158,
1777 | 94: $Vx
1778 | }, {
1779 | 28: [1, 159]
1780 | }, {
1781 | 26: [1, 160]
1782 | }, {
1783 | 26: [1, 161]
1784 | }, {
1785 | 26: [2, 87],
1786 | 43: $VC
1787 | }, o($VE, [2, 14], {
1788 | 33: 126,
1789 | 21: 162,
1790 | 34: $VF,
1791 | 37: $VG,
1792 | 38: $VH
1793 | }), {
1794 | 22: 33,
1795 | 24: $V7,
1796 | 29: 34,
1797 | 36: 163,
1798 | 50: 28,
1799 | 72: 30,
1800 | 73: $V8,
1801 | 74: 31,
1802 | 75: 32,
1803 | 76: $V9,
1804 | 84: 35,
1805 | 85: 36,
1806 | 86: 37,
1807 | 87: 38,
1808 | 88: 39,
1809 | 89: $Va,
1810 | 90: $Vb,
1811 | 91: $Vc,
1812 | 92: $Vd,
1813 | 93: $Ve,
1814 | 94: $Vf,
1815 | 96: $Vg
1816 | }, {
1817 | 26: [1, 164]
1818 | }, o($Vr, [2, 72]), {
1819 | 65: $Vm,
1820 | 66: $Vn,
1821 | 67: $Vo,
1822 | 68: $Vp,
1823 | 70: $Vq,
1824 | 78: [2, 76]
1825 | }, {
1826 | 22: 33,
1827 | 24: $V7,
1828 | 29: 34,
1829 | 36: 165,
1830 | 50: 28,
1831 | 72: 30,
1832 | 73: $V8,
1833 | 74: 31,
1834 | 75: 32,
1835 | 76: $V9,
1836 | 84: 35,
1837 | 85: 36,
1838 | 86: 37,
1839 | 87: 38,
1840 | 88: 39,
1841 | 89: $Va,
1842 | 90: $Vb,
1843 | 91: $Vc,
1844 | 92: $Vd,
1845 | 93: $Ve,
1846 | 94: $Vf,
1847 | 96: $Vg
1848 | }, o($Vs, [2, 97]), o($Vs, [2, 98]), {
1849 | 26: [2, 100],
1850 | 43: $VC
1851 | }, o($Vs, [2, 95]), o($VB, [2, 44]), o($V4, [2, 47], {
1852 | 53: 166,
1853 | 56: [1, 167]
1854 | }), {
1855 | 54: [1, 168],
1856 | 55: [1, 169]
1857 | }, o($VD, [2, 102], {
1858 | 65: $Vm,
1859 | 66: $Vn,
1860 | 67: $Vo,
1861 | 68: $Vp,
1862 | 70: $Vq
1863 | }), o($VK, [2, 29]), {
1864 | 35: [1, 170]
1865 | }, {
1866 | 19: 171,
1867 | 22: 90,
1868 | 24: $Vw,
1869 | 94: $Vx
1870 | }, {
1871 | 34: [1, 172]
1872 | }, {
1873 | 34: [1, 173]
1874 | }, {
1875 | 19: 174,
1876 | 22: 90,
1877 | 24: $Vw,
1878 | 94: $Vx
1879 | }, {
1880 | 34: [1, 175]
1881 | }, {
1882 | 34: [1, 176]
1883 | }, o($VI, [2, 19], {
1884 | 95: $Vt
1885 | }), {
1886 | 24: [1, 177]
1887 | }, o($VI, [2, 20]), o($VI, [2, 21], {
1888 | 22: 178,
1889 | 94: $Vx
1890 | }), o($VE, [2, 16], {
1891 | 33: 150,
1892 | 34: $VF,
1893 | 37: $VG,
1894 | 38: $VH
1895 | }), o($VJ, [2, 70], {
1896 | 65: $Vm,
1897 | 66: $Vn,
1898 | 67: $Vo,
1899 | 68: $Vp
1900 | }), o($Vr, [2, 63]), o($Vz, [2, 73], {
1901 | 65: $Vm,
1902 | 66: $Vn,
1903 | 67: $Vo,
1904 | 68: $Vp,
1905 | 70: $Vq
1906 | }), o($V4, [2, 48]), {
1907 | 57: [1, 179],
1908 | 59: [1, 180]
1909 | }, o($VL, [2, 49]), o($VL, [2, 50]), {
1910 | 22: 33,
1911 | 24: $V7,
1912 | 29: 34,
1913 | 36: 181,
1914 | 50: 28,
1915 | 72: 30,
1916 | 73: $V8,
1917 | 74: 31,
1918 | 75: 32,
1919 | 76: $V9,
1920 | 84: 35,
1921 | 85: 36,
1922 | 86: 37,
1923 | 87: 38,
1924 | 88: 39,
1925 | 89: $Va,
1926 | 90: $Vb,
1927 | 91: $Vc,
1928 | 92: $Vd,
1929 | 93: $Ve,
1930 | 94: $Vf,
1931 | 96: $Vg
1932 | }, {
1933 | 35: [1, 182]
1934 | }, {
1935 | 19: 183,
1936 | 22: 90,
1937 | 24: $Vw,
1938 | 94: $Vx
1939 | }, {
1940 | 19: 184,
1941 | 22: 90,
1942 | 24: $Vw,
1943 | 94: $Vx
1944 | }, {
1945 | 35: [1, 185]
1946 | }, {
1947 | 19: 186,
1948 | 22: 90,
1949 | 24: $Vw,
1950 | 94: $Vx
1951 | }, {
1952 | 19: 187,
1953 | 22: 90,
1954 | 24: $Vw,
1955 | 94: $Vx
1956 | }, {
1957 | 29: 188,
1958 | 89: $Va
1959 | }, o($VI, [2, 22], {
1960 | 95: $Vt
1961 | }), {
1962 | 29: 148,
1963 | 52: 189,
1964 | 89: $Va
1965 | }, {
1966 | 29: 148,
1967 | 52: 190,
1968 | 89: $Va
1969 | }, o($VK, [2, 30], {
1970 | 65: $Vm,
1971 | 66: $Vn,
1972 | 67: $Vo,
1973 | 68: $Vp,
1974 | 70: $Vq
1975 | }), {
1976 | 22: 33,
1977 | 24: $V7,
1978 | 29: 34,
1979 | 36: 191,
1980 | 50: 28,
1981 | 72: 30,
1982 | 73: $V8,
1983 | 74: 31,
1984 | 75: 32,
1985 | 76: $V9,
1986 | 84: 35,
1987 | 85: 36,
1988 | 86: 37,
1989 | 87: 38,
1990 | 88: 39,
1991 | 89: $Va,
1992 | 90: $Vb,
1993 | 91: $Vc,
1994 | 92: $Vd,
1995 | 93: $Ve,
1996 | 94: $Vf,
1997 | 96: $Vg
1998 | }, {
1999 | 35: [1, 192]
2000 | }, {
2001 | 35: [1, 193]
2002 | }, {
2003 | 22: 33,
2004 | 24: $V7,
2005 | 29: 34,
2006 | 36: 194,
2007 | 50: 28,
2008 | 72: 30,
2009 | 73: $V8,
2010 | 74: 31,
2011 | 75: 32,
2012 | 76: $V9,
2013 | 84: 35,
2014 | 85: 36,
2015 | 86: 37,
2016 | 87: 38,
2017 | 88: 39,
2018 | 89: $Va,
2019 | 90: $Vb,
2020 | 91: $Vc,
2021 | 92: $Vd,
2022 | 93: $Ve,
2023 | 94: $Vf,
2024 | 96: $Vg
2025 | }, {
2026 | 35: [1, 195]
2027 | }, {
2028 | 35: [1, 196]
2029 | }, {
2030 | 26: [1, 197]
2031 | }, {
2032 | 58: [1, 198]
2033 | }, {
2034 | 58: [1, 199]
2035 | }, o($VK, [2, 31], {
2036 | 65: $Vm,
2037 | 66: $Vn,
2038 | 67: $Vo,
2039 | 68: $Vp,
2040 | 70: $Vq
2041 | }), {
2042 | 22: 33,
2043 | 24: $V7,
2044 | 29: 34,
2045 | 36: 200,
2046 | 50: 28,
2047 | 72: 30,
2048 | 73: $V8,
2049 | 74: 31,
2050 | 75: 32,
2051 | 76: $V9,
2052 | 84: 35,
2053 | 85: 36,
2054 | 86: 37,
2055 | 87: 38,
2056 | 88: 39,
2057 | 89: $Va,
2058 | 90: $Vb,
2059 | 91: $Vc,
2060 | 92: $Vd,
2061 | 93: $Ve,
2062 | 94: $Vf,
2063 | 96: $Vg
2064 | }, {
2065 | 22: 33,
2066 | 24: $V7,
2067 | 29: 34,
2068 | 36: 201,
2069 | 50: 28,
2070 | 72: 30,
2071 | 73: $V8,
2072 | 74: 31,
2073 | 75: 32,
2074 | 76: $V9,
2075 | 84: 35,
2076 | 85: 36,
2077 | 86: 37,
2078 | 87: 38,
2079 | 88: 39,
2080 | 89: $Va,
2081 | 90: $Vb,
2082 | 91: $Vc,
2083 | 92: $Vd,
2084 | 93: $Ve,
2085 | 94: $Vf,
2086 | 96: $Vg
2087 | }, o($VK, [2, 32], {
2088 | 65: $Vm,
2089 | 66: $Vn,
2090 | 67: $Vo,
2091 | 68: $Vp,
2092 | 70: $Vq
2093 | }), {
2094 | 22: 33,
2095 | 24: $V7,
2096 | 29: 34,
2097 | 36: 202,
2098 | 50: 28,
2099 | 72: 30,
2100 | 73: $V8,
2101 | 74: 31,
2102 | 75: 32,
2103 | 76: $V9,
2104 | 84: 35,
2105 | 85: 36,
2106 | 86: 37,
2107 | 87: 38,
2108 | 88: 39,
2109 | 89: $Va,
2110 | 90: $Vb,
2111 | 91: $Vc,
2112 | 92: $Vd,
2113 | 93: $Ve,
2114 | 94: $Vf,
2115 | 96: $Vg
2116 | }, {
2117 | 22: 33,
2118 | 24: $V7,
2119 | 29: 34,
2120 | 36: 203,
2121 | 50: 28,
2122 | 72: 30,
2123 | 73: $V8,
2124 | 74: 31,
2125 | 75: 32,
2126 | 76: $V9,
2127 | 84: 35,
2128 | 85: 36,
2129 | 86: 37,
2130 | 87: 38,
2131 | 88: 39,
2132 | 89: $Va,
2133 | 90: $Vb,
2134 | 91: $Vc,
2135 | 92: $Vd,
2136 | 93: $Ve,
2137 | 94: $Vf,
2138 | 96: $Vg
2139 | }, o($VI, [2, 23]), o($V4, [2, 51]), o($V4, [2, 52]), o($VK, [2, 33], {
2140 | 65: $Vm,
2141 | 66: $Vn,
2142 | 67: $Vo,
2143 | 68: $Vp,
2144 | 70: $Vq
2145 | }), o($VK, [2, 35], {
2146 | 65: $Vm,
2147 | 66: $Vn,
2148 | 67: $Vo,
2149 | 68: $Vp,
2150 | 70: $Vq
2151 | }), o($VK, [2, 34], {
2152 | 65: $Vm,
2153 | 66: $Vn,
2154 | 67: $Vo,
2155 | 68: $Vp,
2156 | 70: $Vq
2157 | }), o($VK, [2, 36], {
2158 | 65: $Vm,
2159 | 66: $Vn,
2160 | 67: $Vo,
2161 | 68: $Vp,
2162 | 70: $Vq
2163 | })],
2164 | defaultActions: {
2165 | 9: [2, 1]
2166 | },
2167 | parseError: function parseError(str, hash) {
2168 | if (hash.recoverable) {
2169 | this.trace(str);
2170 | } else {
2171 | var error = new Error(str);
2172 | error.hash = hash;
2173 | throw error;
2174 | }
2175 | },
2176 | parse: function parse(input) {
2177 | var self = this,
2178 | stack = [0],
2179 | vstack = [null],
2180 | lstack = [],
2181 | table = this.table,
2182 | yytext = '',
2183 | yylineno = 0,
2184 | yyleng = 0,
2185 | TERROR = 2,
2186 | EOF = 1;
2187 | var args = lstack.slice.call(arguments, 1);
2188 | var lexer = Object.create(this.lexer);
2189 | var sharedState = {
2190 | yy: {}
2191 | };
2192 |
2193 | for (var k in this.yy) {
2194 | if (Object.prototype.hasOwnProperty.call(this.yy, k)) {
2195 | sharedState.yy[k] = this.yy[k];
2196 | }
2197 | }
2198 |
2199 | lexer.setInput(input, sharedState.yy);
2200 | sharedState.yy.lexer = lexer;
2201 | sharedState.yy.parser = this;
2202 |
2203 | if (typeof lexer.yylloc == 'undefined') {
2204 | lexer.yylloc = {};
2205 | }
2206 |
2207 | var yyloc = lexer.yylloc;
2208 | lstack.push(yyloc);
2209 | var ranges = lexer.options && lexer.options.ranges;
2210 |
2211 | if (typeof sharedState.yy.parseError === 'function') {
2212 | this.parseError = sharedState.yy.parseError;
2213 | } else {
2214 | this.parseError = Object.getPrototypeOf(this).parseError;
2215 | }
2216 |
2217 | var lex = function lex() {
2218 | var token;
2219 | token = lexer.lex() || EOF;
2220 |
2221 | if (typeof token !== 'number') {
2222 | token = self.symbols_[token] || token;
2223 | }
2224 |
2225 | return token;
2226 | };
2227 |
2228 | var symbol,
2229 | preErrorSymbol,
2230 | state,
2231 | action,
2232 | r,
2233 | yyval = {},
2234 | p,
2235 | len,
2236 | newState,
2237 | expected;
2238 |
2239 | while (true) {
2240 | state = stack[stack.length - 1];
2241 |
2242 | if (this.defaultActions[state]) {
2243 | action = this.defaultActions[state];
2244 | } else {
2245 | if (symbol === null || typeof symbol == 'undefined') {
2246 | symbol = lex();
2247 | }
2248 |
2249 | action = table[state] && table[state][symbol];
2250 | }
2251 |
2252 | if (typeof action === 'undefined' || !action.length || !action[0]) {
2253 | var errStr = '';
2254 | expected = [];
2255 |
2256 | for (p in table[state]) {
2257 | if (this.terminals_[p] && p > TERROR) {
2258 | expected.push('\'' + this.terminals_[p] + '\'');
2259 | }
2260 | }
2261 |
2262 | if (lexer.showPosition) {
2263 | errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\'';
2264 | } else {
2265 | errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\'');
2266 | }
2267 |
2268 | this.parseError(errStr, {
2269 | text: lexer.match,
2270 | token: this.terminals_[symbol] || symbol,
2271 | line: lexer.yylineno,
2272 | loc: yyloc,
2273 | expected: expected
2274 | });
2275 | }
2276 |
2277 | if (action[0] instanceof Array && action.length > 1) {
2278 | throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol);
2279 | }
2280 |
2281 | switch (action[0]) {
2282 | case 1:
2283 | stack.push(symbol);
2284 | vstack.push(lexer.yytext);
2285 | lstack.push(lexer.yylloc);
2286 | stack.push(action[1]);
2287 | symbol = null;
2288 |
2289 | if (!preErrorSymbol) {
2290 | yyleng = lexer.yyleng;
2291 | yytext = lexer.yytext;
2292 | yylineno = lexer.yylineno;
2293 | yyloc = lexer.yylloc;
2294 | } else {
2295 | symbol = preErrorSymbol;
2296 | preErrorSymbol = null;
2297 | }
2298 |
2299 | break;
2300 |
2301 | case 2:
2302 | len = this.productions_[action[1]][1];
2303 | yyval.$ = vstack[vstack.length - len];
2304 | yyval._$ = {
2305 | first_line: lstack[lstack.length - (len || 1)].first_line,
2306 | last_line: lstack[lstack.length - 1].last_line,
2307 | first_column: lstack[lstack.length - (len || 1)].first_column,
2308 | last_column: lstack[lstack.length - 1].last_column
2309 | };
2310 |
2311 | if (ranges) {
2312 | yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
2313 | }
2314 |
2315 | r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, sharedState.yy, action[1], vstack, lstack].concat(args));
2316 |
2317 | if (typeof r !== 'undefined') {
2318 | return r;
2319 | }
2320 |
2321 | if (len) {
2322 | stack = stack.slice(0, -1 * len * 2);
2323 | vstack = vstack.slice(0, -1 * len);
2324 | lstack = lstack.slice(0, -1 * len);
2325 | }
2326 |
2327 | stack.push(this.productions_[action[1]][0]);
2328 | vstack.push(yyval.$);
2329 | lstack.push(yyval._$);
2330 | newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
2331 | stack.push(newState);
2332 | break;
2333 |
2334 | case 3:
2335 | return true;
2336 | }
2337 | }
2338 |
2339 | return true;
2340 | }
2341 | };
2342 |
2343 | function Parser() {
2344 | this.yy = {};
2345 | }
2346 |
2347 | Parser.prototype = parser;
2348 | parser.Parser = Parser;
2349 | return new Parser();
2350 | }();
2351 |
2352 | var parser_1 = parser;
2353 | var compiled_parser = {
2354 | parser: parser_1
2355 | };
2356 |
2357 | var nodes = createCommonjsModule(function (module, exports) {
2358 | function indent(str) {
2359 | return function () {
2360 | var ref = str.split('\n');
2361 | var results = [];
2362 |
2363 | for (var i = 0, len = ref.length; i < len; i++) {
2364 | results.push(" " + ref[i]);
2365 | }
2366 |
2367 | return results;
2368 | }().join('\n');
2369 | }
2370 |
2371 | exports.Select =
2372 | /*#__PURE__*/
2373 | function () {
2374 | function Select(fields, source, distinct, joins, unions) {
2375 | if (distinct === void 0) {
2376 | distinct = false;
2377 | }
2378 |
2379 | if (joins === void 0) {
2380 | joins = [];
2381 | }
2382 |
2383 | if (unions === void 0) {
2384 | unions = [];
2385 | }
2386 |
2387 | this.fields = fields;
2388 | this.source = source;
2389 | this.distinct = distinct;
2390 | this.joins = joins;
2391 | this.unions = unions;
2392 | this.order = null;
2393 | this.group = null;
2394 | this.where = null;
2395 | this.limit = null;
2396 | }
2397 |
2398 | var _proto = Select.prototype;
2399 |
2400 | _proto.toString = function toString() {
2401 | var ret = ["SELECT " + this.fields.join(', ')];
2402 | ret.push(indent("FROM " + this.source));
2403 |
2404 | for (var i = 0, len = this.joins.length; i < len; i++) {
2405 | ret.push(indent(this.joins[i].toString()));
2406 | }
2407 |
2408 | if (this.where) {
2409 | ret.push(indent(this.where.toString()));
2410 | }
2411 |
2412 | if (this.group) {
2413 | ret.push(indent(this.group.toString()));
2414 | }
2415 |
2416 | if (this.order) {
2417 | ret.push(indent(this.order.toString()));
2418 | }
2419 |
2420 | if (this.limit) {
2421 | ret.push(indent(this.limit.toString()));
2422 | }
2423 |
2424 | for (var j = 0, len1 = this.unions.length; j < len1; j++) {
2425 | ret.push(this.unions[j].toString());
2426 | }
2427 |
2428 | return ret.join('\n');
2429 | };
2430 |
2431 | return Select;
2432 | }();
2433 |
2434 | exports.SubSelect =
2435 | /*#__PURE__*/
2436 | function () {
2437 | function SubSelect(select, name) {
2438 | if (name === void 0) {
2439 | name = null;
2440 | }
2441 |
2442 | this.select = select;
2443 | this.name = name;
2444 | }
2445 |
2446 | var _proto2 = SubSelect.prototype;
2447 |
2448 | _proto2.toString = function toString() {
2449 | var ret = [];
2450 | ret.push('(');
2451 | ret.push(indent(this.select.toString()));
2452 | ret.push(this.name ? ") " + this.name.toString() : ')');
2453 | return ret.join('\n');
2454 | };
2455 |
2456 | return SubSelect;
2457 | }();
2458 |
2459 | exports.Join =
2460 | /*#__PURE__*/
2461 | function () {
2462 | function Join(right, conditions, side, mode) {
2463 | if (conditions === void 0) {
2464 | conditions = null;
2465 | }
2466 |
2467 | if (side === void 0) {
2468 | side = null;
2469 | }
2470 |
2471 | if (mode === void 0) {
2472 | mode = null;
2473 | }
2474 |
2475 | this.right = right;
2476 | this.conditions = conditions;
2477 | this.side = side;
2478 | this.mode = mode;
2479 | }
2480 |
2481 | var _proto3 = Join.prototype;
2482 |
2483 | _proto3.toString = function toString() {
2484 | var ret = '';
2485 |
2486 | if (this.side != null) {
2487 | ret += this.side + " ";
2488 | }
2489 |
2490 | if (this.mode != null) {
2491 | ret += this.mode + " ";
2492 | }
2493 |
2494 | return ret + ("JOIN " + this.right + "\n") + indent("ON " + this.conditions);
2495 | };
2496 |
2497 | return Join;
2498 | }();
2499 |
2500 | exports.Union =
2501 | /*#__PURE__*/
2502 | function () {
2503 | function Union(query, all1) {
2504 | if (all1 === void 0) {
2505 | all1 = false;
2506 | }
2507 |
2508 | this.query = query;
2509 | this.all = all1;
2510 | }
2511 |
2512 | var _proto4 = Union.prototype;
2513 |
2514 | _proto4.toString = function toString() {
2515 | var all = this.all ? ' ALL' : '';
2516 | return "UNION" + all + "\n" + this.query.toString();
2517 | };
2518 |
2519 | return Union;
2520 | }();
2521 |
2522 | exports.LiteralValue =
2523 | /*#__PURE__*/
2524 | function () {
2525 | function LiteralValue(value1, value2) {
2526 | if (value2 === void 0) {
2527 | value2 = null;
2528 | }
2529 |
2530 | this.value = value1;
2531 | this.value2 = value2;
2532 |
2533 | if (this.value2) {
2534 | this.nested = true;
2535 | this.values = this.value.values;
2536 | this.values.push(this.value2);
2537 | } else {
2538 | this.nested = false;
2539 | this.values = [this.value];
2540 | }
2541 | } // TODO: Backtick quotes only supports MySQL, Postgres uses double-quotes
2542 |
2543 |
2544 | var _proto5 = LiteralValue.prototype;
2545 |
2546 | _proto5.toString = function toString(quote) {
2547 | if (quote === void 0) {
2548 | quote = true;
2549 | }
2550 |
2551 | if (quote) {
2552 | return "`" + this.values.join('`.`') + "`";
2553 | } else {
2554 | return "" + this.values.join('.');
2555 | }
2556 | };
2557 |
2558 | return LiteralValue;
2559 | }();
2560 |
2561 | exports.StringValue =
2562 | /*#__PURE__*/
2563 | function () {
2564 | function StringValue(value1, quoteType) {
2565 | if (quoteType === void 0) {
2566 | quoteType = '\'\'';
2567 | }
2568 |
2569 | this.value = value1;
2570 | this.quoteType = quoteType;
2571 | }
2572 |
2573 | var _proto6 = StringValue.prototype;
2574 |
2575 | _proto6.toString = function toString() {
2576 | var escaped = this.quoteType === '\'' ? this.value.replace(/(^|[^\\])'/g, '$1\'\'') : this.value;
2577 | return "" + this.quoteType + escaped + this.quoteType;
2578 | };
2579 |
2580 | return StringValue;
2581 | }();
2582 |
2583 | exports.NumberValue =
2584 | /*#__PURE__*/
2585 | function () {
2586 | function NumberValue(value) {
2587 | this.value = Number(value);
2588 | }
2589 |
2590 | var _proto7 = NumberValue.prototype;
2591 |
2592 | _proto7.toString = function toString() {
2593 | return this.value.toString();
2594 | };
2595 |
2596 | return NumberValue;
2597 | }();
2598 |
2599 | exports.ListValue =
2600 | /*#__PURE__*/
2601 | function () {
2602 | function ListValue(value1) {
2603 | this.value = value1;
2604 | }
2605 |
2606 | var _proto8 = ListValue.prototype;
2607 |
2608 | _proto8.toString = function toString() {
2609 | return "(" + this.value.join(', ') + ")";
2610 | };
2611 |
2612 | return ListValue;
2613 | }();
2614 |
2615 | exports.WhitepaceList =
2616 | /*#__PURE__*/
2617 | function () {
2618 | function WhitepaceList(value1) {
2619 | this.value = value1;
2620 | }
2621 |
2622 | var _proto9 = WhitepaceList.prototype;
2623 |
2624 | _proto9.toString = function toString() {
2625 | // not backtick for literals
2626 | return this.value.map(function (value) {
2627 | if (value instanceof exports.LiteralValue) {
2628 | return value.toString(false);
2629 | } else {
2630 | return value.toString();
2631 | }
2632 | }).join(' ');
2633 | };
2634 |
2635 | return WhitepaceList;
2636 | }();
2637 |
2638 | exports.ParameterValue =
2639 | /*#__PURE__*/
2640 | function () {
2641 | function ParameterValue(value) {
2642 | this.value = value;
2643 | this.index = parseInt(value.substr(1), 10) - 1;
2644 | }
2645 |
2646 | var _proto10 = ParameterValue.prototype;
2647 |
2648 | _proto10.toString = function toString() {
2649 | return "$" + this.value;
2650 | };
2651 |
2652 | return ParameterValue;
2653 | }();
2654 |
2655 | exports.ArgumentListValue =
2656 | /*#__PURE__*/
2657 | function () {
2658 | function ArgumentListValue(value1, distinct) {
2659 | if (distinct === void 0) {
2660 | distinct = false;
2661 | }
2662 |
2663 | this.value = value1;
2664 | this.distinct = distinct;
2665 | }
2666 |
2667 | var _proto11 = ArgumentListValue.prototype;
2668 |
2669 | _proto11.toString = function toString() {
2670 | if (this.distinct) {
2671 | return "DISTINCT " + this.value.join(', ');
2672 | } else {
2673 | return "" + this.value.join(', ');
2674 | }
2675 | };
2676 |
2677 | return ArgumentListValue;
2678 | }();
2679 |
2680 | exports.BooleanValue =
2681 | /*#__PURE__*/
2682 | function () {
2683 | function LiteralValue(value) {
2684 | this.value = function () {
2685 | switch (value.toLowerCase()) {
2686 | case 'true':
2687 | return true;
2688 |
2689 | case 'false':
2690 | return false;
2691 |
2692 | default:
2693 | return null;
2694 | }
2695 | }();
2696 | }
2697 |
2698 | var _proto12 = LiteralValue.prototype;
2699 |
2700 | _proto12.toString = function toString() {
2701 | if (this.value != null) {
2702 | return this.value.toString().toUpperCase();
2703 | } else {
2704 | return 'NULL';
2705 | }
2706 | };
2707 |
2708 | return LiteralValue;
2709 | }();
2710 |
2711 | exports.FunctionValue =
2712 | /*#__PURE__*/
2713 | function () {
2714 | function FunctionValue(name, _arguments, udf) {
2715 | if (_arguments === void 0) {
2716 | _arguments = null;
2717 | }
2718 |
2719 | if (udf === void 0) {
2720 | udf = false;
2721 | }
2722 |
2723 | this.name = name;
2724 | this.arguments = _arguments;
2725 | this.udf = udf;
2726 | }
2727 |
2728 | var _proto13 = FunctionValue.prototype;
2729 |
2730 | _proto13.toString = function toString() {
2731 | if (this.arguments) {
2732 | return this.name.toUpperCase() + "(" + this.arguments.toString() + ")";
2733 | } else {
2734 | return this.name.toUpperCase() + "()";
2735 | }
2736 | };
2737 |
2738 | return FunctionValue;
2739 | }();
2740 |
2741 | exports.Case =
2742 | /*#__PURE__*/
2743 | function () {
2744 | function Case(whens, _else) {
2745 | this.whens = whens;
2746 | this["else"] = _else;
2747 | }
2748 |
2749 | var _proto14 = Case.prototype;
2750 |
2751 | _proto14.toString = function toString() {
2752 | var whensStr = this.whens.map(function (w) {
2753 | return w.toString();
2754 | }).join(' ');
2755 |
2756 | if (this["else"]) {
2757 | return "CASE " + whensStr + " " + this["else"].toString() + " END";
2758 | } else {
2759 | return "CASE " + whensStr + " END";
2760 | }
2761 | };
2762 |
2763 | return Case;
2764 | }();
2765 |
2766 | exports.CaseWhen =
2767 | /*#__PURE__*/
2768 | function () {
2769 | function CaseWhen(whenCondition, resCondition) {
2770 | this.whenCondition = whenCondition;
2771 | this.resCondition = resCondition;
2772 | }
2773 |
2774 | var _proto15 = CaseWhen.prototype;
2775 |
2776 | _proto15.toString = function toString() {
2777 | return "WHEN " + this.whenCondition + " THEN " + this.resCondition;
2778 | };
2779 |
2780 | return CaseWhen;
2781 | }();
2782 |
2783 | exports.CaseElse =
2784 | /*#__PURE__*/
2785 | function () {
2786 | function CaseElse(elseCondition) {
2787 | this.elseCondition = elseCondition;
2788 | }
2789 |
2790 | var _proto16 = CaseElse.prototype;
2791 |
2792 | _proto16.toString = function toString() {
2793 | return "ELSE " + this.elseCondition;
2794 | };
2795 |
2796 | return CaseElse;
2797 | }();
2798 |
2799 | exports.Order =
2800 | /*#__PURE__*/
2801 | function () {
2802 | function Order(orderings, offset) {
2803 | this.orderings = orderings;
2804 | this.offset = offset;
2805 | }
2806 |
2807 | var _proto17 = Order.prototype;
2808 |
2809 | _proto17.toString = function toString() {
2810 | return "ORDER BY " + this.orderings.join(', ') + (this.offset ? '\n' + this.offset.toString() : '');
2811 | };
2812 |
2813 | return Order;
2814 | }();
2815 |
2816 | exports.OrderArgument =
2817 | /*#__PURE__*/
2818 | function () {
2819 | function OrderArgument(value, direction) {
2820 | if (direction === void 0) {
2821 | direction = 'ASC';
2822 | }
2823 |
2824 | this.value = value;
2825 | this.direction = direction;
2826 | }
2827 |
2828 | var _proto18 = OrderArgument.prototype;
2829 |
2830 | _proto18.toString = function toString() {
2831 | return this.value + " " + this.direction;
2832 | };
2833 |
2834 | return OrderArgument;
2835 | }();
2836 |
2837 | exports.Offset =
2838 | /*#__PURE__*/
2839 | function () {
2840 | function Offset(row_count, limit) {
2841 | this.row_count = row_count;
2842 | this.limit = limit;
2843 | }
2844 |
2845 | var _proto19 = Offset.prototype;
2846 |
2847 | _proto19.toString = function toString() {
2848 | return "OFFSET " + this.row_count + " ROWS" + (this.limit ? "\nFETCH NEXT " + this.limit + " ROWS ONLY" : '');
2849 | };
2850 |
2851 | return Offset;
2852 | }();
2853 |
2854 | exports.Limit =
2855 | /*#__PURE__*/
2856 | function () {
2857 | function Limit(value1, offset) {
2858 | this.value = value1;
2859 | this.offset = offset;
2860 | }
2861 |
2862 | var _proto20 = Limit.prototype;
2863 |
2864 | _proto20.toString = function toString() {
2865 | return "LIMIT " + this.value + (this.offset ? "\nOFFSET " + this.offset : '');
2866 | };
2867 |
2868 | return Limit;
2869 | }();
2870 |
2871 | exports.Table =
2872 | /*#__PURE__*/
2873 | function () {
2874 | function Table(name, alias, win, winFn, winArg) {
2875 | if (alias === void 0) {
2876 | alias = null;
2877 | }
2878 |
2879 | if (win === void 0) {
2880 | win = null;
2881 | }
2882 |
2883 | if (winFn === void 0) {
2884 | winFn = null;
2885 | }
2886 |
2887 | if (winArg === void 0) {
2888 | winArg = null;
2889 | }
2890 |
2891 | this.name = name;
2892 | this.alias = alias;
2893 | this.win = win;
2894 | this.winFn = winFn;
2895 | this.winArg = winArg;
2896 | }
2897 |
2898 | var _proto21 = Table.prototype;
2899 |
2900 | _proto21.toString = function toString() {
2901 | if (this.win) {
2902 | return this.name + "." + this.win + ":" + this.winFn + "(" + this.winArg + ")";
2903 | } else if (this.alias) {
2904 | return this.name + " AS " + this.alias;
2905 | } else {
2906 | return this.name.toString();
2907 | }
2908 | };
2909 |
2910 | return Table;
2911 | }();
2912 |
2913 | exports.Group =
2914 | /*#__PURE__*/
2915 | function () {
2916 | function Group(fields) {
2917 | this.fields = fields;
2918 | this.having = null;
2919 | }
2920 |
2921 | var _proto22 = Group.prototype;
2922 |
2923 | _proto22.toString = function toString() {
2924 | var ret = ["GROUP BY " + this.fields.join(', ')];
2925 |
2926 | if (this.having) {
2927 | ret.push(this.having.toString());
2928 | }
2929 |
2930 | return ret.join('\n');
2931 | };
2932 |
2933 | return Group;
2934 | }();
2935 |
2936 | exports.Where =
2937 | /*#__PURE__*/
2938 | function () {
2939 | function Where(conditions) {
2940 | this.conditions = conditions;
2941 | }
2942 |
2943 | var _proto23 = Where.prototype;
2944 |
2945 | _proto23.toString = function toString() {
2946 | return "WHERE " + this.conditions;
2947 | };
2948 |
2949 | return Where;
2950 | }();
2951 |
2952 | exports.Having =
2953 | /*#__PURE__*/
2954 | function () {
2955 | function Having(conditions) {
2956 | this.conditions = conditions;
2957 | }
2958 |
2959 | var _proto24 = Having.prototype;
2960 |
2961 | _proto24.toString = function toString() {
2962 | return "HAVING " + this.conditions;
2963 | };
2964 |
2965 | return Having;
2966 | }();
2967 |
2968 | exports.Op =
2969 | /*#__PURE__*/
2970 | function () {
2971 | function Op(operation, left, right) {
2972 | this.operation = operation;
2973 | this.left = left;
2974 | this.right = right;
2975 | }
2976 |
2977 | var _proto25 = Op.prototype;
2978 |
2979 | _proto25.toString = function toString() {
2980 | return "(" + this.left + " " + this.operation.toUpperCase() + " " + this.right + ")";
2981 | };
2982 |
2983 | return Op;
2984 | }();
2985 |
2986 | exports.UnaryOp =
2987 | /*#__PURE__*/
2988 | function () {
2989 | function UnaryOp(operator, operand) {
2990 | this.operator = operator;
2991 | this.operand = operand;
2992 | }
2993 |
2994 | var _proto26 = UnaryOp.prototype;
2995 |
2996 | _proto26.toString = function toString() {
2997 | return "(" + this.operator.toUpperCase() + " " + this.operand + ")";
2998 | };
2999 |
3000 | return UnaryOp;
3001 | }();
3002 |
3003 | exports.BetweenOp =
3004 | /*#__PURE__*/
3005 | function () {
3006 | function BetweenOp(value) {
3007 | this.value = value;
3008 | }
3009 |
3010 | var _proto27 = BetweenOp.prototype;
3011 |
3012 | _proto27.toString = function toString() {
3013 | return "" + this.value.join(' AND ');
3014 | };
3015 |
3016 | return BetweenOp;
3017 | }();
3018 |
3019 | exports.Field =
3020 | /*#__PURE__*/
3021 | function () {
3022 | function Field(field, name) {
3023 | if (name === void 0) {
3024 | name = null;
3025 | }
3026 |
3027 | this.field = field;
3028 | this.name = name;
3029 | }
3030 |
3031 | var _proto28 = Field.prototype;
3032 |
3033 | _proto28.toString = function toString() {
3034 | if (this.name) {
3035 | return this.field + " AS " + this.name;
3036 | } else {
3037 | return this.field.toString();
3038 | }
3039 | };
3040 |
3041 | return Field;
3042 | }();
3043 |
3044 | exports.Star =
3045 | /*#__PURE__*/
3046 | function () {
3047 | function Star() {}
3048 |
3049 | var _proto29 = Star.prototype;
3050 |
3051 | _proto29.toString = function toString() {
3052 | return '*';
3053 | };
3054 |
3055 | return Star;
3056 | }();
3057 | });
3058 | var nodes_1 = nodes.Select;
3059 | var nodes_2 = nodes.SubSelect;
3060 | var nodes_3 = nodes.Join;
3061 | var nodes_4 = nodes.Union;
3062 | var nodes_5 = nodes.LiteralValue;
3063 | var nodes_6 = nodes.StringValue;
3064 | var nodes_7 = nodes.NumberValue;
3065 | var nodes_8 = nodes.ListValue;
3066 | var nodes_9 = nodes.WhitepaceList;
3067 | var nodes_10 = nodes.ParameterValue;
3068 | var nodes_11 = nodes.ArgumentListValue;
3069 | var nodes_12 = nodes.BooleanValue;
3070 | var nodes_13 = nodes.FunctionValue;
3071 | var nodes_14 = nodes.Case;
3072 | var nodes_15 = nodes.CaseWhen;
3073 | var nodes_16 = nodes.CaseElse;
3074 | var nodes_17 = nodes.Order;
3075 | var nodes_18 = nodes.OrderArgument;
3076 | var nodes_19 = nodes.Offset;
3077 | var nodes_20 = nodes.Limit;
3078 | var nodes_21 = nodes.Table;
3079 | var nodes_22 = nodes.Group;
3080 | var nodes_23 = nodes.Where;
3081 | var nodes_24 = nodes.Having;
3082 | var nodes_25 = nodes.Op;
3083 | var nodes_26 = nodes.UnaryOp;
3084 | var nodes_27 = nodes.BetweenOp;
3085 | var nodes_28 = nodes.Field;
3086 | var nodes_29 = nodes.Star;
3087 |
3088 | var parser$1 = compiled_parser.parser;
3089 | parser$1.lexer = {
3090 | lex: function lex() {
3091 | var tag;
3092 |
3093 | var _ref = this.tokens[this.pos++] || [''];
3094 |
3095 | tag = _ref[0];
3096 | this.yytext = _ref[1];
3097 | this.yylineno = _ref[2];
3098 | return tag;
3099 | },
3100 | setInput: function setInput(tokens) {
3101 | this.tokens = tokens;
3102 | return this.pos = 0;
3103 | },
3104 | upcomingInput: function upcomingInput() {
3105 | return '';
3106 | }
3107 | };
3108 | parser$1.yy = nodes;
3109 | var parser_2 = parser$1;
3110 |
3111 | var parse = function parse(str) {
3112 | return parser$1.parse(str);
3113 | };
3114 |
3115 | var parser_1$1 = {
3116 | parser: parser_2,
3117 | parse: parse
3118 | };
3119 |
3120 | var sql_parser = createCommonjsModule(function (module, exports) {
3121 | exports.lexer = lexer;
3122 | exports.parser = parser_1$1;
3123 | exports.nodes = nodes;
3124 |
3125 | exports.parse = function (sql) {
3126 | return exports.parser.parse(exports.lexer.tokenize(sql));
3127 | };
3128 | });
3129 | var sql_parser_1 = sql_parser.lexer;
3130 | var sql_parser_2 = sql_parser.parser;
3131 | var sql_parser_3 = sql_parser.nodes;
3132 | var sql_parser_4 = sql_parser.parse;
3133 |
3134 | exports.default = sql_parser;
3135 | exports.lexer = sql_parser_1;
3136 | exports.nodes = sql_parser_3;
3137 | exports.parse = sql_parser_4;
3138 | exports.parser = sql_parser_2;
3139 |
3140 | Object.defineProperty(exports, '__esModule', { value: true });
3141 |
3142 | })));
3143 | //# sourceMappingURL=sql-parser.js.map
3144 |
--------------------------------------------------------------------------------