documents.js 1.63.0 → 1.64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -20
- package/dist/convert/convert.cjs +3 -3
- package/dist/convert/convert.d.cts +5 -2
- package/dist/convert/convert.d.ts +4 -1
- package/dist/convert/convert.js +3 -3
- package/dist/edit/docx/content.d.cts +1 -1
- package/dist/edit/docx/content.d.ts +1 -1
- package/dist/edit/docx/paragraph.d.cts +3 -3
- package/dist/edit/docx/paragraph.d.ts +3 -3
- package/dist/edit/ods/address.cjs +42 -24
- package/dist/edit/ods/address.d.cts +12 -2
- package/dist/edit/ods/address.d.ts +12 -2
- package/dist/edit/ods/address.js +39 -25
- package/dist/edit/ods/column-row.cjs +68 -6
- package/dist/edit/ods/column-row.d.cts +5 -1
- package/dist/edit/ods/column-row.d.ts +5 -1
- package/dist/edit/ods/column-row.js +68 -10
- package/dist/edit/ods/content.cjs +10 -2
- package/dist/edit/ods/content.js +10 -2
- package/dist/edit/ods/floating.cjs +90 -0
- package/dist/edit/ods/floating.d.cts +7 -0
- package/dist/edit/ods/floating.d.ts +7 -0
- package/dist/edit/ods/floating.js +88 -0
- package/dist/edit/ods/print-settings.cjs +158 -2
- package/dist/edit/ods/print-settings.js +159 -3
- package/dist/edit/ods/sheet.cjs +13 -0
- package/dist/edit/ods/sheet.d.cts +5 -1
- package/dist/edit/ods/sheet.d.ts +5 -1
- package/dist/edit/ods/sheet.js +14 -1
- package/dist/edit/odt/content.cjs +8 -4
- package/dist/edit/odt/content.js +8 -4
- package/dist/edit/odt/editor.cjs +7 -0
- package/dist/edit/odt/editor.d.cts +3 -0
- package/dist/edit/odt/editor.d.ts +3 -0
- package/dist/edit/odt/editor.js +7 -0
- package/dist/edit/odt/formula.cjs +19 -0
- package/dist/edit/odt/formula.d.cts +8 -0
- package/dist/edit/odt/formula.d.ts +8 -0
- package/dist/edit/odt/formula.js +17 -0
- package/dist/evaluate-BU5N1Jk1.d.ts +11 -0
- package/dist/evaluate-BhMXY6DM.d.cts +11 -0
- package/dist/firebird/backup.d.cts +1 -1
- package/dist/firebird/backup.d.ts +1 -1
- package/dist/firebird/data.cjs +30 -16
- package/dist/firebird/data.d.cts +3 -2
- package/dist/firebird/data.d.ts +3 -2
- package/dist/firebird/data.js +30 -17
- package/dist/fonts/ooxml.d.cts +1 -1
- package/dist/fonts/registry.d.cts +1 -1
- package/dist/formula-CgydMiTt.d.ts +10 -0
- package/dist/formula-CiwPw8nY.d.cts +10 -0
- package/dist/hsqldb/binary-script.d.cts +1 -1
- package/dist/hsqldb/binary-script.d.ts +1 -1
- package/dist/hsqldb/cache.d.cts +1 -1
- package/dist/hsqldb/cache.d.ts +1 -1
- package/dist/hsqldb/rowformat.cjs +22 -13
- package/dist/hsqldb/rowformat.js +22 -13
- package/dist/hsqldb/script.d.cts +1 -18
- package/dist/hsqldb/script.d.ts +1 -18
- package/dist/index.cjs +56 -0
- package/dist/index.d.cts +22 -8
- package/dist/index.d.ts +21 -7
- package/dist/index.js +15 -2
- package/dist/layout/sheets.cjs +30 -24
- package/dist/layout/sheets.js +31 -25
- package/dist/layout/slides.cjs +6 -4
- package/dist/layout/slides.js +7 -5
- package/dist/lexer-DGPWx_f2.d.cts +42 -0
- package/dist/lexer-DGPWx_f2.d.ts +42 -0
- package/dist/mathml/layout.d.cts +1 -1
- package/dist/mathml/layout.d.ts +1 -1
- package/dist/mathml/variant.d.cts +1 -6
- package/dist/mathml/variant.d.ts +1 -6
- package/dist/odb/csv.d.cts +1 -1
- package/dist/odb/csv.d.ts +1 -1
- package/dist/odb/formula/definition.cjs +49 -0
- package/dist/odb/formula/definition.d.cts +8 -0
- package/dist/odb/formula/definition.d.ts +8 -0
- package/dist/odb/formula/definition.js +46 -0
- package/dist/odb/formula/errors.cjs +47 -0
- package/dist/odb/formula/errors.d.cts +21 -0
- package/dist/odb/formula/errors.d.ts +21 -0
- package/dist/odb/formula/errors.js +43 -0
- package/dist/odb/formula/evaluate.cjs +283 -0
- package/dist/odb/formula/evaluate.d.cts +43 -0
- package/dist/odb/formula/evaluate.d.ts +43 -0
- package/dist/odb/formula/evaluate.js +281 -0
- package/dist/odb/formula/parser.cjs +198 -0
- package/dist/odb/formula/parser.d.cts +29 -0
- package/dist/odb/formula/parser.d.ts +29 -0
- package/dist/odb/formula/parser.js +197 -0
- package/dist/odb/read.d.cts +1 -1
- package/dist/odb/read.d.ts +1 -1
- package/dist/odb/report/content.cjs +27 -0
- package/dist/odb/report/content.d.cts +14 -0
- package/dist/odb/report/content.d.ts +14 -0
- package/dist/odb/report/content.js +25 -0
- package/dist/odb/report/render.cjs +106 -0
- package/dist/odb/report/render.d.cts +7 -0
- package/dist/odb/report/render.d.ts +7 -0
- package/dist/odb/report/render.js +106 -0
- package/dist/odb/report/source.cjs +45 -0
- package/dist/odb/report/source.d.cts +14 -0
- package/dist/odb/report/source.d.ts +14 -0
- package/dist/odb/report/source.js +42 -0
- package/dist/odb/spreadsheet.d.cts +1 -1
- package/dist/odb/spreadsheet.d.ts +1 -1
- package/dist/odb/sql/errors.cjs +38 -0
- package/dist/odb/sql/errors.d.cts +17 -0
- package/dist/odb/sql/errors.d.ts +17 -0
- package/dist/odb/sql/errors.js +35 -0
- package/dist/odb/sql/evaluate.cjs +312 -0
- package/dist/odb/sql/evaluate.d.cts +2 -0
- package/dist/odb/sql/evaluate.d.ts +2 -0
- package/dist/odb/sql/evaluate.js +311 -0
- package/dist/odb/sql/lexer.cjs +282 -0
- package/dist/odb/sql/lexer.d.cts +2 -0
- package/dist/odb/sql/lexer.d.ts +2 -0
- package/dist/odb/sql/lexer.js +281 -0
- package/dist/odb/sql/parser.cjs +479 -0
- package/dist/odb/sql/parser.d.cts +2 -0
- package/dist/odb/sql/parser.d.ts +2 -0
- package/dist/odb/sql/parser.js +478 -0
- package/dist/odb/values.cjs +75 -0
- package/dist/odb/values.d.cts +2 -0
- package/dist/odb/values.d.ts +2 -0
- package/dist/odb/values.js +69 -0
- package/dist/odf/odt/read.cjs +43 -21
- package/dist/odf/odt/read.js +43 -21
- package/dist/odf-package/formula.cjs +59 -0
- package/dist/odf-package/formula.d.cts +11 -0
- package/dist/odf-package/formula.d.ts +11 -0
- package/dist/odf-package/formula.js +58 -0
- package/dist/odf-package/manifest.cjs +29 -0
- package/dist/odf-package/manifest.d.cts +5 -2
- package/dist/odf-package/manifest.d.ts +5 -2
- package/dist/odf-package/manifest.js +30 -2
- package/dist/odf-package/media.cjs +2 -1
- package/dist/odf-package/media.js +2 -2
- package/dist/omml/read.cjs +265 -0
- package/dist/omml/read.d.cts +12 -0
- package/dist/omml/read.d.ts +12 -0
- package/dist/omml/read.js +263 -0
- package/dist/omml/shared.cjs +67 -0
- package/dist/omml/shared.d.cts +2 -0
- package/dist/omml/shared.d.ts +2 -0
- package/dist/omml/shared.js +64 -0
- package/dist/omml/write.cjs +3 -51
- package/dist/omml/write.d.cts +2 -2
- package/dist/omml/write.d.ts +2 -2
- package/dist/omml/write.js +1 -49
- package/dist/ooxml/docx/extras.cjs +15 -0
- package/dist/ooxml/docx/extras.d.cts +12 -0
- package/dist/ooxml/docx/extras.d.ts +12 -0
- package/dist/ooxml/docx/extras.js +14 -0
- package/dist/ooxml/docx/formula.cjs +109 -0
- package/dist/ooxml/docx/formula.d.cts +2 -0
- package/dist/ooxml/docx/formula.d.ts +2 -0
- package/dist/ooxml/docx/formula.js +108 -0
- package/dist/ooxml/docx/read.cjs +10 -2
- package/dist/ooxml/docx/read.d.cts +6 -2
- package/dist/ooxml/docx/read.d.ts +6 -2
- package/dist/ooxml/docx/read.js +11 -3
- package/dist/parser-B9vC1T6T.d.cts +101 -0
- package/dist/parser-DQSgYJzQ.d.ts +101 -0
- package/dist/{registry-CtPhMD0f.d.cts → registry-lqJej0Jr.d.cts} +1 -1
- package/dist/script-DsGGIzGU.d.cts +19 -0
- package/dist/script-DsGGIzGU.d.ts +19 -0
- package/dist/shared-DLZ3IQUl.d.cts +15 -0
- package/dist/shared-DUOzjwcL.d.ts +15 -0
- package/dist/values-BetetbaH.d.cts +23 -0
- package/dist/values-BetetbaH.d.ts +23 -0
- package/dist/variant-BMrebjMw.d.cts +7 -0
- package/dist/variant-BMrebjMw.d.ts +7 -0
- package/dist/{write-DuyfnbL_.d.cts → write-BQ6SK8r8.d.cts} +2 -6
- package/dist/{write-Zqwx6pka.d.ts → write-THs7ipBq.d.ts} +2 -6
- package/package.json +1 -1
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_odb_sql_errors = require("./errors.cjs");
|
|
3
|
+
const require_odb_sql_lexer = require("./lexer.cjs");
|
|
4
|
+
//#region src/odb/sql/parser.ts
|
|
5
|
+
const AGGREGATE_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
6
|
+
"COUNT",
|
|
7
|
+
"SUM",
|
|
8
|
+
"AVG",
|
|
9
|
+
"MIN",
|
|
10
|
+
"MAX"
|
|
11
|
+
]);
|
|
12
|
+
function isAggregateFunction(keyword) {
|
|
13
|
+
return AGGREGATE_FUNCTIONS.has(keyword);
|
|
14
|
+
}
|
|
15
|
+
const OUT_OF_SCOPE_KEYWORDS = /* @__PURE__ */ new Map([
|
|
16
|
+
["JOIN", "a JOIN"],
|
|
17
|
+
["INNER", "a JOIN"],
|
|
18
|
+
["OUTER", "a JOIN"],
|
|
19
|
+
["LEFT", "a JOIN"],
|
|
20
|
+
["RIGHT", "a JOIN"],
|
|
21
|
+
["FULL", "a JOIN"],
|
|
22
|
+
["CROSS", "a JOIN"],
|
|
23
|
+
["NATURAL", "a JOIN"],
|
|
24
|
+
["ON", "a JOIN"],
|
|
25
|
+
["USING", "a JOIN"],
|
|
26
|
+
["UNION", "UNION"],
|
|
27
|
+
["INTERSECT", "INTERSECT"],
|
|
28
|
+
["EXCEPT", "EXCEPT"],
|
|
29
|
+
["MINUS", "EXCEPT (MINUS)"],
|
|
30
|
+
["DISTINCT", "DISTINCT"],
|
|
31
|
+
["ALL", "the ALL quantifier"],
|
|
32
|
+
["HAVING", "HAVING"],
|
|
33
|
+
["LIMIT", "a row-limit clause (LIMIT)"],
|
|
34
|
+
["OFFSET", "a row-limit clause (OFFSET)"],
|
|
35
|
+
["FETCH", "a row-limit clause (FETCH)"],
|
|
36
|
+
["TOP", "a row-limit clause (TOP)"],
|
|
37
|
+
["AS", "a column or table alias (AS)"],
|
|
38
|
+
["CASE", "a CASE expression"],
|
|
39
|
+
["WHEN", "a CASE expression"],
|
|
40
|
+
["THEN", "a CASE expression"],
|
|
41
|
+
["ELSE", "a CASE expression"],
|
|
42
|
+
["END", "a CASE expression"],
|
|
43
|
+
["EXISTS", "an EXISTS subquery"],
|
|
44
|
+
["ANY", "a quantified subquery predicate (ANY)"],
|
|
45
|
+
["SOME", "a quantified subquery predicate (SOME)"],
|
|
46
|
+
["WITH", "a common table expression (WITH)"],
|
|
47
|
+
["INTO", "a SELECT ... INTO clause"],
|
|
48
|
+
["INSERT", "a non-SELECT statement (INSERT)"],
|
|
49
|
+
["UPDATE", "a non-SELECT statement (UPDATE)"],
|
|
50
|
+
["DELETE", "a non-SELECT statement (DELETE)"],
|
|
51
|
+
["CREATE", "a non-SELECT statement (CREATE)"],
|
|
52
|
+
["DROP", "a non-SELECT statement (DROP)"],
|
|
53
|
+
["ALTER", "a non-SELECT statement (ALTER)"],
|
|
54
|
+
["ESCAPE", "a LIKE ... ESCAPE clause"],
|
|
55
|
+
["COLLATE", "a COLLATE clause"],
|
|
56
|
+
["NULLS", "an ORDER BY NULLS FIRST/LAST clause"]
|
|
57
|
+
]);
|
|
58
|
+
function describeToken(token) {
|
|
59
|
+
switch (token.kind) {
|
|
60
|
+
case "keyword": return `keyword "${token.keyword}"`;
|
|
61
|
+
case "identifier": return `identifier "${token.text}"`;
|
|
62
|
+
case "string": return `string literal ${token.text}`;
|
|
63
|
+
case "number": return `numeric literal ${token.text}`;
|
|
64
|
+
case "operator": return `operator "${token.operator}"`;
|
|
65
|
+
case "punctuation": return `"${token.punctuation}"`;
|
|
66
|
+
case "end": return "end of statement";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function rejectOutOfScopeConstructs(tokens, sql) {
|
|
70
|
+
tokens.forEach((token, index) => {
|
|
71
|
+
if (token.kind === "keyword") {
|
|
72
|
+
const construct = OUT_OF_SCOPE_KEYWORDS.get(token.keyword);
|
|
73
|
+
if (construct !== void 0) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError(construct, sql);
|
|
74
|
+
if (token.keyword === "SELECT" && index > 0) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a subquery", sql);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (token.kind === "identifier") {
|
|
78
|
+
const next = tokens[index + 1];
|
|
79
|
+
if (next?.kind === "punctuation" && next.punctuation === "(") throw new require_odb_sql_errors.HsqldbSqlUnsupportedError(`a scalar function (${token.text})`, sql);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
var SqlParser = class {
|
|
84
|
+
tokens;
|
|
85
|
+
sql;
|
|
86
|
+
index = 0;
|
|
87
|
+
constructor(sql) {
|
|
88
|
+
this.sql = sql;
|
|
89
|
+
this.tokens = require_odb_sql_lexer.tokenizeSql(sql);
|
|
90
|
+
rejectOutOfScopeConstructs(this.tokens, sql);
|
|
91
|
+
}
|
|
92
|
+
peek() {
|
|
93
|
+
const token = this.tokens[this.index];
|
|
94
|
+
if (token === void 0) throw new require_odb_sql_errors.HsqldbSqlParseError("unexpected end of statement", this.sql, this.sql.length);
|
|
95
|
+
return token;
|
|
96
|
+
}
|
|
97
|
+
advance() {
|
|
98
|
+
const token = this.peek();
|
|
99
|
+
if (token.kind !== "end") this.index += 1;
|
|
100
|
+
return token;
|
|
101
|
+
}
|
|
102
|
+
fail(expected) {
|
|
103
|
+
const token = this.peek();
|
|
104
|
+
throw new require_odb_sql_errors.HsqldbSqlParseError(`expected ${expected}, found ${describeToken(token)}`, this.sql, token.start);
|
|
105
|
+
}
|
|
106
|
+
atKeyword(keyword) {
|
|
107
|
+
const token = this.peek();
|
|
108
|
+
return token.kind === "keyword" && token.keyword === keyword;
|
|
109
|
+
}
|
|
110
|
+
atPunctuation(punctuation) {
|
|
111
|
+
const token = this.peek();
|
|
112
|
+
return token.kind === "punctuation" && token.punctuation === punctuation;
|
|
113
|
+
}
|
|
114
|
+
takeKeyword(keyword) {
|
|
115
|
+
if (!this.atKeyword(keyword)) this.fail(`keyword ${keyword}`);
|
|
116
|
+
this.advance();
|
|
117
|
+
}
|
|
118
|
+
takePunctuation(punctuation) {
|
|
119
|
+
if (!this.atPunctuation(punctuation)) this.fail(`"${punctuation}"`);
|
|
120
|
+
this.advance();
|
|
121
|
+
}
|
|
122
|
+
takeName(what) {
|
|
123
|
+
const token = this.peek();
|
|
124
|
+
if (token.kind !== "identifier") this.fail(what);
|
|
125
|
+
this.advance();
|
|
126
|
+
return {
|
|
127
|
+
name: token.name,
|
|
128
|
+
quoted: token.quoted
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
parseColumnRef() {
|
|
132
|
+
const start = this.peek().start;
|
|
133
|
+
const first = this.takeName("a column name");
|
|
134
|
+
if (this.atPunctuation(".")) {
|
|
135
|
+
this.advance();
|
|
136
|
+
return {
|
|
137
|
+
qualifier: first,
|
|
138
|
+
column: this.takeName("a column name after \".\""),
|
|
139
|
+
text: this.sql.slice(start, this.previousEnd())
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
qualifier: void 0,
|
|
144
|
+
column: first,
|
|
145
|
+
text: this.sql.slice(start, this.previousEnd())
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
previousEnd() {
|
|
149
|
+
const previous = this.tokens[this.index - 1];
|
|
150
|
+
if (previous === void 0) throw new require_odb_sql_errors.HsqldbSqlParseError("unexpected end of statement", this.sql, this.sql.length);
|
|
151
|
+
return previous.start + previous.text.length;
|
|
152
|
+
}
|
|
153
|
+
parseAggregate(aggregate) {
|
|
154
|
+
this.advance();
|
|
155
|
+
this.takePunctuation("(");
|
|
156
|
+
if (this.atPunctuation("*")) {
|
|
157
|
+
if (aggregate !== "COUNT") this.fail(`a column name -- ${aggregate}(*) is not valid SQL, only COUNT(*) is`);
|
|
158
|
+
this.advance();
|
|
159
|
+
this.takePunctuation(")");
|
|
160
|
+
return {
|
|
161
|
+
kind: "aggregate",
|
|
162
|
+
aggregate,
|
|
163
|
+
argument: { kind: "star" },
|
|
164
|
+
outputName: "COUNT(*)"
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const column = this.parseColumnRef();
|
|
168
|
+
this.takePunctuation(")");
|
|
169
|
+
return {
|
|
170
|
+
kind: "aggregate",
|
|
171
|
+
aggregate,
|
|
172
|
+
argument: {
|
|
173
|
+
kind: "column",
|
|
174
|
+
column
|
|
175
|
+
},
|
|
176
|
+
outputName: `${aggregate}(${column.column.name})`
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
parseSelectItem() {
|
|
180
|
+
const token = this.peek();
|
|
181
|
+
if (token.kind === "keyword" && isAggregateFunction(token.keyword)) return this.parseAggregate(token.keyword);
|
|
182
|
+
return {
|
|
183
|
+
kind: "column",
|
|
184
|
+
column: this.parseColumnRef()
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
parseSelectList() {
|
|
188
|
+
if (this.atPunctuation("*")) {
|
|
189
|
+
this.advance();
|
|
190
|
+
if (this.atPunctuation(",")) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a select list mixing \"*\" with named columns", this.sql);
|
|
191
|
+
return [{ kind: "star" }];
|
|
192
|
+
}
|
|
193
|
+
const items = [this.parseSelectItem()];
|
|
194
|
+
while (this.atPunctuation(",")) {
|
|
195
|
+
this.advance();
|
|
196
|
+
if (this.atPunctuation("*")) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a select list mixing \"*\" with named columns", this.sql);
|
|
197
|
+
items.push(this.parseSelectItem());
|
|
198
|
+
}
|
|
199
|
+
return items;
|
|
200
|
+
}
|
|
201
|
+
parseLiteral() {
|
|
202
|
+
const token = this.peek();
|
|
203
|
+
if (token.kind === "punctuation" && token.punctuation === "-") {
|
|
204
|
+
this.advance();
|
|
205
|
+
const number = this.peek();
|
|
206
|
+
if (number.kind !== "number") throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("an arithmetic expression", this.sql);
|
|
207
|
+
this.advance();
|
|
208
|
+
return {
|
|
209
|
+
kind: "number",
|
|
210
|
+
value: -number.value
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (token.kind === "number") {
|
|
214
|
+
this.advance();
|
|
215
|
+
return {
|
|
216
|
+
kind: "number",
|
|
217
|
+
value: token.value
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (token.kind === "string") {
|
|
221
|
+
this.advance();
|
|
222
|
+
return {
|
|
223
|
+
kind: "string",
|
|
224
|
+
value: token.value
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (token.kind === "keyword" && (token.keyword === "TRUE" || token.keyword === "FALSE")) {
|
|
228
|
+
this.advance();
|
|
229
|
+
return {
|
|
230
|
+
kind: "boolean",
|
|
231
|
+
value: token.keyword === "TRUE"
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (token.kind === "keyword" && token.keyword === "NULL") {
|
|
235
|
+
this.advance();
|
|
236
|
+
return { kind: "null" };
|
|
237
|
+
}
|
|
238
|
+
this.fail("a literal value");
|
|
239
|
+
}
|
|
240
|
+
parseOperand() {
|
|
241
|
+
const token = this.peek();
|
|
242
|
+
if (token.kind === "identifier") return {
|
|
243
|
+
kind: "column",
|
|
244
|
+
column: this.parseColumnRef()
|
|
245
|
+
};
|
|
246
|
+
if (token.kind === "punctuation" && token.punctuation === "(") throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a parenthesised value expression", this.sql);
|
|
247
|
+
return {
|
|
248
|
+
kind: "literal",
|
|
249
|
+
literal: this.parseLiteral()
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
parseInList(operand, negated) {
|
|
253
|
+
this.takePunctuation("(");
|
|
254
|
+
const values = [];
|
|
255
|
+
for (;;) {
|
|
256
|
+
if (this.peek().kind === "identifier") throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a column reference inside an IN list", this.sql);
|
|
257
|
+
values.push(this.parseLiteral());
|
|
258
|
+
if (this.atPunctuation(",")) {
|
|
259
|
+
this.advance();
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
this.takePunctuation(")");
|
|
265
|
+
return {
|
|
266
|
+
kind: "in",
|
|
267
|
+
operand,
|
|
268
|
+
values,
|
|
269
|
+
negated
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
parseLike(operand, negated) {
|
|
273
|
+
const token = this.peek();
|
|
274
|
+
if (token.kind !== "string") {
|
|
275
|
+
if (token.kind === "identifier") throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a non-literal LIKE pattern", this.sql);
|
|
276
|
+
this.fail("a string literal LIKE pattern");
|
|
277
|
+
}
|
|
278
|
+
this.advance();
|
|
279
|
+
return {
|
|
280
|
+
kind: "like",
|
|
281
|
+
operand,
|
|
282
|
+
pattern: token.value,
|
|
283
|
+
negated
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
parseBetween(operand, negated) {
|
|
287
|
+
const lower = this.parseOperand();
|
|
288
|
+
this.takeKeyword("AND");
|
|
289
|
+
return {
|
|
290
|
+
kind: "between",
|
|
291
|
+
operand,
|
|
292
|
+
lower,
|
|
293
|
+
upper: this.parseOperand(),
|
|
294
|
+
negated
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
parseNegatedPostfix(operand) {
|
|
298
|
+
this.advance();
|
|
299
|
+
if (this.atKeyword("LIKE")) {
|
|
300
|
+
this.advance();
|
|
301
|
+
return this.parseLike(operand, true);
|
|
302
|
+
}
|
|
303
|
+
if (this.atKeyword("IN")) {
|
|
304
|
+
this.advance();
|
|
305
|
+
return this.parseInList(operand, true);
|
|
306
|
+
}
|
|
307
|
+
if (this.atKeyword("BETWEEN")) {
|
|
308
|
+
this.advance();
|
|
309
|
+
return this.parseBetween(operand, true);
|
|
310
|
+
}
|
|
311
|
+
this.fail("keyword LIKE, IN or BETWEEN after NOT");
|
|
312
|
+
}
|
|
313
|
+
parsePostfix(operand) {
|
|
314
|
+
const token = this.peek();
|
|
315
|
+
if (token.kind === "operator") {
|
|
316
|
+
this.advance();
|
|
317
|
+
return {
|
|
318
|
+
kind: "comparison",
|
|
319
|
+
operator: token.operator,
|
|
320
|
+
left: operand,
|
|
321
|
+
right: this.parseOperand()
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
if (token.kind === "punctuation" && (token.punctuation === "*" || token.punctuation === "-")) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("an arithmetic expression", this.sql);
|
|
325
|
+
if (token.kind === "keyword") {
|
|
326
|
+
if (token.keyword === "IS") {
|
|
327
|
+
this.advance();
|
|
328
|
+
const negated = this.atKeyword("NOT");
|
|
329
|
+
if (negated) this.advance();
|
|
330
|
+
this.takeKeyword("NULL");
|
|
331
|
+
return {
|
|
332
|
+
kind: "isNull",
|
|
333
|
+
operand,
|
|
334
|
+
negated
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
if (token.keyword === "LIKE") {
|
|
338
|
+
this.advance();
|
|
339
|
+
return this.parseLike(operand, false);
|
|
340
|
+
}
|
|
341
|
+
if (token.keyword === "IN") {
|
|
342
|
+
this.advance();
|
|
343
|
+
return this.parseInList(operand, false);
|
|
344
|
+
}
|
|
345
|
+
if (token.keyword === "BETWEEN") {
|
|
346
|
+
this.advance();
|
|
347
|
+
return this.parseBetween(operand, false);
|
|
348
|
+
}
|
|
349
|
+
if (token.keyword === "NOT") return this.parseNegatedPostfix(operand);
|
|
350
|
+
}
|
|
351
|
+
this.fail("a comparison operator, or keyword IS, LIKE, IN or BETWEEN");
|
|
352
|
+
}
|
|
353
|
+
parsePrimary() {
|
|
354
|
+
if (this.atPunctuation("(")) {
|
|
355
|
+
this.advance();
|
|
356
|
+
const predicate = this.parsePredicate();
|
|
357
|
+
this.takePunctuation(")");
|
|
358
|
+
return predicate;
|
|
359
|
+
}
|
|
360
|
+
return this.parsePostfix(this.parseOperand());
|
|
361
|
+
}
|
|
362
|
+
parseNot() {
|
|
363
|
+
if (this.atKeyword("NOT")) {
|
|
364
|
+
this.advance();
|
|
365
|
+
return {
|
|
366
|
+
kind: "not",
|
|
367
|
+
predicate: this.parseNot()
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return this.parsePrimary();
|
|
371
|
+
}
|
|
372
|
+
parseAnd() {
|
|
373
|
+
let predicate = this.parseNot();
|
|
374
|
+
while (this.atKeyword("AND")) {
|
|
375
|
+
this.advance();
|
|
376
|
+
predicate = {
|
|
377
|
+
kind: "and",
|
|
378
|
+
left: predicate,
|
|
379
|
+
right: this.parseNot()
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
return predicate;
|
|
383
|
+
}
|
|
384
|
+
parsePredicate() {
|
|
385
|
+
let predicate = this.parseAnd();
|
|
386
|
+
while (this.atKeyword("OR")) {
|
|
387
|
+
this.advance();
|
|
388
|
+
predicate = {
|
|
389
|
+
kind: "or",
|
|
390
|
+
left: predicate,
|
|
391
|
+
right: this.parseAnd()
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
return predicate;
|
|
395
|
+
}
|
|
396
|
+
parseGroupBy() {
|
|
397
|
+
this.takeKeyword("GROUP");
|
|
398
|
+
this.takeKeyword("BY");
|
|
399
|
+
const columns = [this.parseGroupByColumn()];
|
|
400
|
+
while (this.atPunctuation(",")) {
|
|
401
|
+
this.advance();
|
|
402
|
+
columns.push(this.parseGroupByColumn());
|
|
403
|
+
}
|
|
404
|
+
return columns;
|
|
405
|
+
}
|
|
406
|
+
parseGroupByColumn() {
|
|
407
|
+
const token = this.peek();
|
|
408
|
+
if (token.kind === "keyword" && isAggregateFunction(token.keyword)) this.fail("a column name -- an aggregate function is not valid in GROUP BY");
|
|
409
|
+
return this.parseColumnRef();
|
|
410
|
+
}
|
|
411
|
+
parseOrderBy() {
|
|
412
|
+
this.takeKeyword("ORDER");
|
|
413
|
+
this.takeKeyword("BY");
|
|
414
|
+
const terms = [this.parseOrderByTerm()];
|
|
415
|
+
while (this.atPunctuation(",")) {
|
|
416
|
+
this.advance();
|
|
417
|
+
terms.push(this.parseOrderByTerm());
|
|
418
|
+
}
|
|
419
|
+
return terms;
|
|
420
|
+
}
|
|
421
|
+
parseOrderByTerm() {
|
|
422
|
+
const token = this.peek();
|
|
423
|
+
if (token.kind === "keyword" && isAggregateFunction(token.keyword)) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("an aggregate function in ORDER BY", this.sql);
|
|
424
|
+
if (token.kind === "number") throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("an ordinal column reference in ORDER BY (ORDER BY 1)", this.sql);
|
|
425
|
+
const column = this.parseColumnRef();
|
|
426
|
+
if (this.atKeyword("ASC")) {
|
|
427
|
+
this.advance();
|
|
428
|
+
return {
|
|
429
|
+
column,
|
|
430
|
+
direction: "asc"
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
if (this.atKeyword("DESC")) {
|
|
434
|
+
this.advance();
|
|
435
|
+
return {
|
|
436
|
+
column,
|
|
437
|
+
direction: "desc"
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
column,
|
|
442
|
+
direction: "asc"
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
parseStatement() {
|
|
446
|
+
const first = this.peek();
|
|
447
|
+
if (!(first.kind === "keyword" && first.keyword === "SELECT")) this.fail("keyword SELECT");
|
|
448
|
+
this.advance();
|
|
449
|
+
const items = this.parseSelectList();
|
|
450
|
+
this.takeKeyword("FROM");
|
|
451
|
+
if (this.atPunctuation("(")) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a derived table in FROM", this.sql);
|
|
452
|
+
const from = this.takeName("a table name");
|
|
453
|
+
if (this.atPunctuation(".")) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a schema-qualified table name", this.sql);
|
|
454
|
+
if (this.atPunctuation(",")) throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a JOIN", this.sql);
|
|
455
|
+
if (this.peek().kind === "identifier") throw new require_odb_sql_errors.HsqldbSqlUnsupportedError("a table alias", this.sql);
|
|
456
|
+
let where;
|
|
457
|
+
if (this.atKeyword("WHERE")) {
|
|
458
|
+
this.advance();
|
|
459
|
+
where = this.parsePredicate();
|
|
460
|
+
}
|
|
461
|
+
const groupBy = this.atKeyword("GROUP") ? this.parseGroupBy() : [];
|
|
462
|
+
const orderBy = this.atKeyword("ORDER") ? this.parseOrderBy() : [];
|
|
463
|
+
if (this.atPunctuation(";")) this.advance();
|
|
464
|
+
if (this.peek().kind !== "end") this.fail("end of statement");
|
|
465
|
+
return {
|
|
466
|
+
sql: this.sql,
|
|
467
|
+
items,
|
|
468
|
+
from,
|
|
469
|
+
where,
|
|
470
|
+
groupBy,
|
|
471
|
+
orderBy
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
function parseSelect(sql) {
|
|
476
|
+
return new SqlParser(sql).parseStatement();
|
|
477
|
+
}
|
|
478
|
+
//#endregion
|
|
479
|
+
exports.parseSelect = parseSelect;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SqlNameRef, c as SqlPredicate, d as SqlSortDirection, f as parseSelect, i as SqlLiteral, l as SqlSelectItem, n as SqlAggregateFunction, o as SqlOperand, r as SqlColumnRef, s as SqlOrderByTerm, t as SqlAggregateArgument, u as SqlSelectStatement } from "../../parser-B9vC1T6T.cjs";
|
|
2
|
+
export { SqlAggregateArgument, SqlAggregateFunction, SqlColumnRef, SqlLiteral, SqlNameRef, SqlOperand, SqlOrderByTerm, SqlPredicate, SqlSelectItem, SqlSelectStatement, SqlSortDirection, parseSelect };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as SqlNameRef, c as SqlPredicate, d as SqlSortDirection, f as parseSelect, i as SqlLiteral, l as SqlSelectItem, n as SqlAggregateFunction, o as SqlOperand, r as SqlColumnRef, s as SqlOrderByTerm, t as SqlAggregateArgument, u as SqlSelectStatement } from "../../parser-DQSgYJzQ.js";
|
|
2
|
+
export { SqlAggregateArgument, SqlAggregateFunction, SqlColumnRef, SqlLiteral, SqlNameRef, SqlOperand, SqlOrderByTerm, SqlPredicate, SqlSelectItem, SqlSelectStatement, SqlSortDirection, parseSelect };
|