dt-sql-parser 4.1.0-beta.6 → 4.1.0-beta.7
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/dist/lib/flink/FlinkSqlParser.d.ts +3 -3
- package/dist/lib/flink/FlinkSqlParser.js +2179 -2147
- package/dist/parser/common/basicSQL.d.ts +17 -0
- package/dist/parser/common/basicSQL.js +53 -22
- package/dist/parser/common/parseErrorListener.d.ts +5 -3
- package/dist/parser/common/parseErrorListener.js +6 -2
- package/dist/parser/flink/flinkErrorListener.d.ts +1 -4
- package/dist/parser/flink/flinkErrorListener.js +14 -5
- package/dist/parser/flink/index.js +2 -1
- package/dist/parser/hive/hiveErrorListener.d.ts +1 -4
- package/dist/parser/hive/hiveErrorListener.js +14 -5
- package/dist/parser/hive/index.js +2 -1
- package/dist/parser/impala/ImpalaErrorListener.d.ts +1 -4
- package/dist/parser/impala/ImpalaErrorListener.js +14 -5
- package/dist/parser/impala/index.js +2 -1
- package/dist/parser/mysql/index.js +2 -1
- package/dist/parser/mysql/mysqlErrorListener.d.ts +1 -4
- package/dist/parser/mysql/mysqlErrorListener.js +14 -5
- package/dist/parser/postgresql/index.js +2 -1
- package/dist/parser/postgresql/postgreErrorListener.d.ts +1 -4
- package/dist/parser/postgresql/postgreErrorListener.js +14 -5
- package/dist/parser/spark/index.js +2 -1
- package/dist/parser/spark/sparkErrorListener.d.ts +1 -4
- package/dist/parser/spark/sparkErrorListener.js +14 -5
- package/dist/parser/trino/index.js +2 -1
- package/dist/parser/trino/trinoErrorListener.d.ts +1 -4
- package/dist/parser/trino/trinoErrorListener.js +14 -5
- package/package.json +1 -1
|
@@ -94,6 +94,10 @@ export declare abstract class BasicSQL<L extends Lexer = Lexer, PRC extends Pars
|
|
|
94
94
|
* @returns syntax errors
|
|
95
95
|
*/
|
|
96
96
|
validate(input: string): ParseError[];
|
|
97
|
+
/**
|
|
98
|
+
* Get the input string that has been parsed.
|
|
99
|
+
*/
|
|
100
|
+
getParsedInput(): string;
|
|
97
101
|
/**
|
|
98
102
|
* Get all Tokens of input string,'<EOF>' is not included.
|
|
99
103
|
* @param input source string
|
|
@@ -111,6 +115,19 @@ export declare abstract class BasicSQL<L extends Lexer = Lexer, PRC extends Pars
|
|
|
111
115
|
* @param input source string
|
|
112
116
|
*/
|
|
113
117
|
splitSQLByStatement(input: string): TextSlice[] | null;
|
|
118
|
+
/**
|
|
119
|
+
* Get a minimum boundary parser near tokenIndex.
|
|
120
|
+
* @param input source string.
|
|
121
|
+
* @param tokenIndex start from which index to minimize the boundary.
|
|
122
|
+
* @param originParseTree the parse tree need to be minimized, default value is the result of parsing `input`.
|
|
123
|
+
* @returns minimum parser info
|
|
124
|
+
*/
|
|
125
|
+
getMinimumParserInfo(input: string, tokenIndex: number, originParseTree?: ParserRuleContext | null): {
|
|
126
|
+
parser: P;
|
|
127
|
+
parseTree: ParserRuleContext;
|
|
128
|
+
tokenIndexOffset: number;
|
|
129
|
+
newTokenIndex: number;
|
|
130
|
+
} | null;
|
|
114
131
|
/**
|
|
115
132
|
* Get suggestions of syntax and token at caretPosition
|
|
116
133
|
* @param input source string
|
|
@@ -109,6 +109,12 @@ export class BasicSQL {
|
|
|
109
109
|
this.parseWithCache(input);
|
|
110
110
|
return this._parseErrors;
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Get the input string that has been parsed.
|
|
114
|
+
*/
|
|
115
|
+
getParsedInput() {
|
|
116
|
+
return this._parsedInput;
|
|
117
|
+
}
|
|
112
118
|
/**
|
|
113
119
|
* Get all Tokens of input string,'<EOF>' is not included.
|
|
114
120
|
* @param input source string
|
|
@@ -149,31 +155,31 @@ export class BasicSQL {
|
|
|
149
155
|
return res;
|
|
150
156
|
}
|
|
151
157
|
/**
|
|
152
|
-
* Get
|
|
153
|
-
* @param input source string
|
|
154
|
-
* @param
|
|
155
|
-
* @
|
|
158
|
+
* Get a minimum boundary parser near tokenIndex.
|
|
159
|
+
* @param input source string.
|
|
160
|
+
* @param tokenIndex start from which index to minimize the boundary.
|
|
161
|
+
* @param originParseTree the parse tree need to be minimized, default value is the result of parsing `input`.
|
|
162
|
+
* @returns minimum parser info
|
|
156
163
|
*/
|
|
157
|
-
|
|
164
|
+
getMinimumParserInfo(input, tokenIndex, originParseTree) {
|
|
158
165
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const allTokens = this.getAllTokens(input);
|
|
165
|
-
let caretTokenIndex = findCaretTokenIndex(caretPosition, allTokens);
|
|
166
|
-
let c3Context = this._parseTree;
|
|
167
|
-
let tokenIndexOffset = 0;
|
|
168
|
-
if (!caretTokenIndex && caretTokenIndex !== 0)
|
|
166
|
+
if (arguments.length <= 2) {
|
|
167
|
+
this.parseWithCache(input);
|
|
168
|
+
originParseTree = this._parseTree;
|
|
169
|
+
}
|
|
170
|
+
if (!originParseTree || !(input === null || input === void 0 ? void 0 : input.length))
|
|
169
171
|
return null;
|
|
172
|
+
const splitListener = this.splitListener;
|
|
170
173
|
/**
|
|
171
174
|
* Split sql by statement.
|
|
172
175
|
* Try to collect candidates in as small a range as possible.
|
|
173
176
|
*/
|
|
174
|
-
this.listen(splitListener,
|
|
177
|
+
this.listen(splitListener, originParseTree);
|
|
175
178
|
const statementCount = (_a = splitListener.statementsContext) === null || _a === void 0 ? void 0 : _a.length;
|
|
176
179
|
const statementsContext = splitListener.statementsContext;
|
|
180
|
+
let tokenIndexOffset = 0;
|
|
181
|
+
let sqlParserIns = this._parser;
|
|
182
|
+
let parseTree = originParseTree;
|
|
177
183
|
// If there are multiple statements.
|
|
178
184
|
if (statementCount > 1) {
|
|
179
185
|
/**
|
|
@@ -194,12 +200,12 @@ export class BasicSQL {
|
|
|
194
200
|
*/
|
|
195
201
|
const isPrevCtxValid = index === 0 || !((_b = statementsContext[index - 1]) === null || _b === void 0 ? void 0 : _b.exception);
|
|
196
202
|
const isNextCtxValid = index === statementCount - 1 || !((_c = statementsContext[index + 1]) === null || _c === void 0 ? void 0 : _c.exception);
|
|
197
|
-
if (ctx.stop && ctx.stop.tokenIndex <
|
|
203
|
+
if (ctx.stop && ctx.stop.tokenIndex < tokenIndex && isPrevCtxValid) {
|
|
198
204
|
startStatement = ctx;
|
|
199
205
|
}
|
|
200
206
|
if (ctx.start &&
|
|
201
207
|
!stopStatement &&
|
|
202
|
-
ctx.start.tokenIndex >
|
|
208
|
+
ctx.start.tokenIndex > tokenIndex &&
|
|
203
209
|
isNextCtxValid) {
|
|
204
210
|
stopStatement = ctx;
|
|
205
211
|
break;
|
|
@@ -213,7 +219,7 @@ export class BasicSQL {
|
|
|
213
219
|
* compared to the tokenIndex in the whole input
|
|
214
220
|
*/
|
|
215
221
|
tokenIndexOffset = (_j = (_h = startStatement === null || startStatement === void 0 ? void 0 : startStatement.start) === null || _h === void 0 ? void 0 : _h.tokenIndex) !== null && _j !== void 0 ? _j : 0;
|
|
216
|
-
|
|
222
|
+
tokenIndex = tokenIndex - tokenIndexOffset;
|
|
217
223
|
/**
|
|
218
224
|
* Reparse the input fragment,
|
|
219
225
|
* and c3 will collect candidates in the newly generated parseTree.
|
|
@@ -229,12 +235,37 @@ export class BasicSQL {
|
|
|
229
235
|
parser.buildParseTrees = true;
|
|
230
236
|
parser.errorHandler = new ErrorStrategy();
|
|
231
237
|
sqlParserIns = parser;
|
|
232
|
-
|
|
238
|
+
parseTree = parser.program();
|
|
233
239
|
}
|
|
240
|
+
return {
|
|
241
|
+
parser: sqlParserIns,
|
|
242
|
+
parseTree,
|
|
243
|
+
tokenIndexOffset,
|
|
244
|
+
newTokenIndex: tokenIndex,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get suggestions of syntax and token at caretPosition
|
|
249
|
+
* @param input source string
|
|
250
|
+
* @param caretPosition caret position, such as cursor position
|
|
251
|
+
* @returns suggestion
|
|
252
|
+
*/
|
|
253
|
+
getSuggestionAtCaretPosition(input, caretPosition) {
|
|
254
|
+
this.parseWithCache(input);
|
|
255
|
+
if (!this._parseTree)
|
|
256
|
+
return null;
|
|
257
|
+
const allTokens = this.getAllTokens(input);
|
|
258
|
+
let caretTokenIndex = findCaretTokenIndex(caretPosition, allTokens);
|
|
259
|
+
if (!caretTokenIndex && caretTokenIndex !== 0)
|
|
260
|
+
return null;
|
|
261
|
+
const minimumParser = this.getMinimumParserInfo(input, caretTokenIndex);
|
|
262
|
+
if (!minimumParser)
|
|
263
|
+
return null;
|
|
264
|
+
const { parser: sqlParserIns, tokenIndexOffset, newTokenIndex, parseTree: c3Context, } = minimumParser;
|
|
234
265
|
const core = new CodeCompletionCore(sqlParserIns);
|
|
235
266
|
core.preferredRules = this.preferredRules;
|
|
236
|
-
const candidates = core.collectCandidates(
|
|
237
|
-
const originalSuggestions = this.processCandidates(candidates, allTokens,
|
|
267
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
268
|
+
const originalSuggestions = this.processCandidates(candidates, allTokens, newTokenIndex, tokenIndexOffset);
|
|
238
269
|
const syntaxSuggestions = originalSuggestions.syntax.map((syntaxCtx) => {
|
|
239
270
|
const wordRanges = syntaxCtx.wordRanges.map((token) => {
|
|
240
271
|
return tokenToWord(token, this._parsedInput);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Token, Recognizer, ANTLRErrorListener, RecognitionException, ATNSimulator, Parser } from 'antlr4ng';
|
|
2
|
-
import {
|
|
2
|
+
import { BasicSQL } from './basicSQL';
|
|
3
3
|
/**
|
|
4
4
|
* Converted from {@link SyntaxError}.
|
|
5
5
|
*/
|
|
@@ -32,8 +32,10 @@ export interface SyntaxError {
|
|
|
32
32
|
export type ErrorListener = (parseError: ParseError, originalError: SyntaxError) => void;
|
|
33
33
|
export declare abstract class ParseErrorListener implements ANTLRErrorListener {
|
|
34
34
|
private _errorListener;
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
protected preferredRules: Set<number>;
|
|
36
|
+
protected get locale(): import("./types").LOCALE_TYPE;
|
|
37
|
+
protected parserContext: BasicSQL;
|
|
38
|
+
constructor(errorListener: ErrorListener, parserContext: BasicSQL, preferredRules: Set<number>);
|
|
37
39
|
reportAmbiguity(): void;
|
|
38
40
|
reportAttemptingFullContext(): void;
|
|
39
41
|
reportContextSensitivity(): void;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Token, LexerNoViableAltException, InputMismatchException, NoViableAltException, } from 'antlr4ng';
|
|
2
2
|
import { transform } from './transform';
|
|
3
3
|
export class ParseErrorListener {
|
|
4
|
-
|
|
5
|
-
this.locale
|
|
4
|
+
get locale() {
|
|
5
|
+
return this.parserContext.locale;
|
|
6
|
+
}
|
|
7
|
+
constructor(errorListener, parserContext, preferredRules) {
|
|
8
|
+
this.parserContext = parserContext;
|
|
9
|
+
this.preferredRules = preferredRules;
|
|
6
10
|
this._errorListener = errorListener;
|
|
7
11
|
}
|
|
8
12
|
reportAmbiguity() { }
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
2
2
|
import { Parser, Token } from 'antlr4ng';
|
|
3
|
-
import { LOCALE_TYPE } from '../common/types';
|
|
4
3
|
export declare class FlinkErrorListener extends ParseErrorListener {
|
|
5
|
-
private preferredRules;
|
|
6
4
|
private objectNames;
|
|
7
|
-
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
5
|
getExpectedText(parser: Parser, token: Token): string;
|
|
9
6
|
}
|
|
@@ -2,8 +2,8 @@ import { CodeCompletionCore } from 'antlr4-c3';
|
|
|
2
2
|
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
3
|
import { FlinkSqlParser } from '../../lib/flink/FlinkSqlParser';
|
|
4
4
|
export class FlinkErrorListener extends ParseErrorListener {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.objectNames = new Map([
|
|
8
8
|
[FlinkSqlParser.RULE_catalogPath, 'catalog'],
|
|
9
9
|
[FlinkSqlParser.RULE_catalogPathCreate, 'catalog'],
|
|
@@ -18,18 +18,27 @@ export class FlinkErrorListener extends ParseErrorListener {
|
|
|
18
18
|
[FlinkSqlParser.RULE_columnName, 'column'],
|
|
19
19
|
[FlinkSqlParser.RULE_columnNameCreate, 'column'],
|
|
20
20
|
]);
|
|
21
|
-
this.preferredRules = preferredRules;
|
|
22
21
|
}
|
|
23
22
|
getExpectedText(parser, token) {
|
|
24
23
|
var _a;
|
|
25
24
|
let expectedText = '';
|
|
25
|
+
const input = this.parserContext.getParsedInput();
|
|
26
|
+
/**
|
|
27
|
+
* Get the program context.
|
|
28
|
+
* When called error listener, `this._parseTree` is still `undefined`,
|
|
29
|
+
* so we can't use cached parseTree in `getMinimumParserInfo`
|
|
30
|
+
*/
|
|
26
31
|
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
27
32
|
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
28
33
|
currentContext = currentContext.parent;
|
|
29
34
|
}
|
|
30
|
-
const
|
|
35
|
+
const parserInfo = this.parserContext.getMinimumParserInfo(input, token.tokenIndex, currentContext);
|
|
36
|
+
if (!parserInfo)
|
|
37
|
+
return '';
|
|
38
|
+
const { parser: c3Parser, newTokenIndex, parseTree: c3Context } = parserInfo;
|
|
39
|
+
const core = new CodeCompletionCore(c3Parser);
|
|
31
40
|
core.preferredRules = this.preferredRules;
|
|
32
|
-
const candidates = core.collectCandidates(
|
|
41
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
33
42
|
if (candidates.rules.size) {
|
|
34
43
|
const result = [];
|
|
35
44
|
// get expectedText as collect rules first
|
|
@@ -33,7 +33,8 @@ export class FlinkSQL extends BasicSQL {
|
|
|
33
33
|
return new FlinkSqlSplitListener();
|
|
34
34
|
}
|
|
35
35
|
createErrorListener(_errorListener) {
|
|
36
|
-
|
|
36
|
+
const parserContext = this;
|
|
37
|
+
return new FlinkErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
37
38
|
}
|
|
38
39
|
createEntityCollector(input, caretTokenIndex) {
|
|
39
40
|
return new FlinkEntityCollector(input, caretTokenIndex);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
2
2
|
import { Parser, Token } from 'antlr4ng';
|
|
3
|
-
import { LOCALE_TYPE } from '../common/types';
|
|
4
3
|
export declare class HiveErrorListener extends ParseErrorListener {
|
|
5
|
-
private preferredRules;
|
|
6
4
|
private objectNames;
|
|
7
|
-
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
5
|
getExpectedText(parser: Parser, token: Token): string;
|
|
9
6
|
}
|
|
@@ -2,8 +2,8 @@ import { CodeCompletionCore } from 'antlr4-c3';
|
|
|
2
2
|
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
3
|
import { HiveSqlParser } from '../../lib/hive/HiveSqlParser';
|
|
4
4
|
export class HiveErrorListener extends ParseErrorListener {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.objectNames = new Map([
|
|
8
8
|
[HiveSqlParser.RULE_dbSchemaName, 'database'],
|
|
9
9
|
[HiveSqlParser.RULE_dbSchemaNameCreate, 'database'],
|
|
@@ -17,18 +17,27 @@ export class HiveErrorListener extends ParseErrorListener {
|
|
|
17
17
|
[HiveSqlParser.RULE_columnName, 'column'],
|
|
18
18
|
[HiveSqlParser.RULE_columnNameCreate, 'column'],
|
|
19
19
|
]);
|
|
20
|
-
this.preferredRules = preferredRules;
|
|
21
20
|
}
|
|
22
21
|
getExpectedText(parser, token) {
|
|
23
22
|
var _a;
|
|
24
23
|
let expectedText = '';
|
|
24
|
+
const input = this.parserContext.getParsedInput();
|
|
25
|
+
/**
|
|
26
|
+
* Get the program context.
|
|
27
|
+
* When called error listener, `this._parseTree` is still `undefined`,
|
|
28
|
+
* so we can't use cached parseTree in `getMinimumParserInfo`
|
|
29
|
+
*/
|
|
25
30
|
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
26
31
|
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
27
32
|
currentContext = currentContext.parent;
|
|
28
33
|
}
|
|
29
|
-
const
|
|
34
|
+
const parserInfo = this.parserContext.getMinimumParserInfo(input, token.tokenIndex, currentContext);
|
|
35
|
+
if (!parserInfo)
|
|
36
|
+
return '';
|
|
37
|
+
const { parser: c3Parser, newTokenIndex, parseTree: c3Context } = parserInfo;
|
|
38
|
+
const core = new CodeCompletionCore(c3Parser);
|
|
30
39
|
core.preferredRules = this.preferredRules;
|
|
31
|
-
const candidates = core.collectCandidates(
|
|
40
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
32
41
|
if (candidates.rules.size) {
|
|
33
42
|
const result = [];
|
|
34
43
|
// get expectedText as collect rules first
|
|
@@ -33,7 +33,8 @@ export class HiveSQL extends BasicSQL {
|
|
|
33
33
|
return new HiveSqlSplitListener();
|
|
34
34
|
}
|
|
35
35
|
createErrorListener(_errorListener) {
|
|
36
|
-
|
|
36
|
+
const parserContext = this;
|
|
37
|
+
return new HiveErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
37
38
|
}
|
|
38
39
|
createEntityCollector(input, caretTokenIndex) {
|
|
39
40
|
return new HiveEntityCollector(input, caretTokenIndex);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
2
2
|
import { Parser, Token } from 'antlr4ng';
|
|
3
|
-
import { LOCALE_TYPE } from '../common/types';
|
|
4
3
|
export declare class ImpalaErrorListener extends ParseErrorListener {
|
|
5
|
-
private preferredRules;
|
|
6
4
|
private objectNames;
|
|
7
|
-
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
5
|
getExpectedText(parser: Parser, token: Token): string;
|
|
9
6
|
}
|
|
@@ -2,8 +2,8 @@ import { CodeCompletionCore } from 'antlr4-c3';
|
|
|
2
2
|
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
3
|
import { ImpalaSqlParser } from '../../lib/impala/ImpalaSqlParser';
|
|
4
4
|
export class ImpalaErrorListener extends ParseErrorListener {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.objectNames = new Map([
|
|
8
8
|
[ImpalaSqlParser.RULE_databaseNamePath, 'database'],
|
|
9
9
|
[ImpalaSqlParser.RULE_databaseNameCreate, 'database'],
|
|
@@ -16,18 +16,27 @@ export class ImpalaErrorListener extends ParseErrorListener {
|
|
|
16
16
|
[ImpalaSqlParser.RULE_columnNamePath, 'column'],
|
|
17
17
|
[ImpalaSqlParser.RULE_columnNamePathCreate, 'column'],
|
|
18
18
|
]);
|
|
19
|
-
this.preferredRules = preferredRules;
|
|
20
19
|
}
|
|
21
20
|
getExpectedText(parser, token) {
|
|
22
21
|
var _a;
|
|
23
22
|
let expectedText = '';
|
|
23
|
+
const input = this.parserContext.getParsedInput();
|
|
24
|
+
/**
|
|
25
|
+
* Get the program context.
|
|
26
|
+
* When called error listener, `this._parseTree` is still `undefined`,
|
|
27
|
+
* so we can't use cached parseTree in `getMinimumParserInfo`
|
|
28
|
+
*/
|
|
24
29
|
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
25
30
|
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
26
31
|
currentContext = currentContext.parent;
|
|
27
32
|
}
|
|
28
|
-
const
|
|
33
|
+
const parserInfo = this.parserContext.getMinimumParserInfo(input, token.tokenIndex, currentContext);
|
|
34
|
+
if (!parserInfo)
|
|
35
|
+
return '';
|
|
36
|
+
const { parser: c3Parser, newTokenIndex, parseTree: c3Context } = parserInfo;
|
|
37
|
+
const core = new CodeCompletionCore(c3Parser);
|
|
29
38
|
core.preferredRules = this.preferredRules;
|
|
30
|
-
const candidates = core.collectCandidates(
|
|
39
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
31
40
|
if (candidates.rules.size) {
|
|
32
41
|
const result = [];
|
|
33
42
|
// get expectedText as collect rules first
|
|
@@ -32,7 +32,8 @@ export class ImpalaSQL extends BasicSQL {
|
|
|
32
32
|
return new ImpalaSqlSplitListener();
|
|
33
33
|
}
|
|
34
34
|
createErrorListener(_errorListener) {
|
|
35
|
-
|
|
35
|
+
const parserContext = this;
|
|
36
|
+
return new ImpalaErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
36
37
|
}
|
|
37
38
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
39
|
return new ImpalaEntityCollector(input, caretTokenIndex);
|
|
@@ -32,7 +32,8 @@ export class MySQL extends BasicSQL {
|
|
|
32
32
|
return new MysqlSplitListener();
|
|
33
33
|
}
|
|
34
34
|
createErrorListener(_errorListener) {
|
|
35
|
-
|
|
35
|
+
const parserContext = this;
|
|
36
|
+
return new MysqlErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
36
37
|
}
|
|
37
38
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
39
|
return new MySqlEntityCollector(input, caretTokenIndex);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
2
2
|
import { Parser, Token } from 'antlr4ng';
|
|
3
|
-
import { LOCALE_TYPE } from '../common/types';
|
|
4
3
|
export declare class MysqlErrorListener extends ParseErrorListener {
|
|
5
|
-
private preferredRules;
|
|
6
4
|
private objectNames;
|
|
7
|
-
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
5
|
getExpectedText(parser: Parser, token: Token): string;
|
|
9
6
|
}
|
|
@@ -2,8 +2,8 @@ import { CodeCompletionCore } from 'antlr4-c3';
|
|
|
2
2
|
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
3
|
import { MySqlParser } from '../../lib/mysql/MySqlParser';
|
|
4
4
|
export class MysqlErrorListener extends ParseErrorListener {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.objectNames = new Map([
|
|
8
8
|
[MySqlParser.RULE_databaseName, 'database'],
|
|
9
9
|
[MySqlParser.RULE_databaseNameCreate, 'database'],
|
|
@@ -16,18 +16,27 @@ export class MysqlErrorListener extends ParseErrorListener {
|
|
|
16
16
|
[MySqlParser.RULE_columnName, 'column'],
|
|
17
17
|
[MySqlParser.RULE_columnNameCreate, 'column'],
|
|
18
18
|
]);
|
|
19
|
-
this.preferredRules = preferredRules;
|
|
20
19
|
}
|
|
21
20
|
getExpectedText(parser, token) {
|
|
22
21
|
var _a;
|
|
23
22
|
let expectedText = '';
|
|
23
|
+
const input = this.parserContext.getParsedInput();
|
|
24
|
+
/**
|
|
25
|
+
* Get the program context.
|
|
26
|
+
* When called error listener, `this._parseTree` is still `undefined`,
|
|
27
|
+
* so we can't use cached parseTree in `getMinimumParserInfo`
|
|
28
|
+
*/
|
|
24
29
|
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
25
30
|
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
26
31
|
currentContext = currentContext.parent;
|
|
27
32
|
}
|
|
28
|
-
const
|
|
33
|
+
const parserInfo = this.parserContext.getMinimumParserInfo(input, token.tokenIndex, currentContext);
|
|
34
|
+
if (!parserInfo)
|
|
35
|
+
return '';
|
|
36
|
+
const { parser: c3Parser, newTokenIndex, parseTree: c3Context } = parserInfo;
|
|
37
|
+
const core = new CodeCompletionCore(c3Parser);
|
|
29
38
|
core.preferredRules = this.preferredRules;
|
|
30
|
-
const candidates = core.collectCandidates(
|
|
39
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
31
40
|
if (candidates.rules.size) {
|
|
32
41
|
const result = [];
|
|
33
42
|
// get expectedText as collect rules first
|
|
@@ -36,7 +36,8 @@ export class PostgreSQL extends BasicSQL {
|
|
|
36
36
|
return new PostgreSqlSplitListener();
|
|
37
37
|
}
|
|
38
38
|
createErrorListener(_errorListener) {
|
|
39
|
-
|
|
39
|
+
const parserContext = this;
|
|
40
|
+
return new PostgreSqlErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
40
41
|
}
|
|
41
42
|
createEntityCollector(input, caretTokenIndex) {
|
|
42
43
|
return new PostgreSqlEntityCollector(input, caretTokenIndex);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
2
2
|
import { Parser, Token } from 'antlr4ng';
|
|
3
|
-
import { LOCALE_TYPE } from '../common/types';
|
|
4
3
|
export declare class PostgreSqlErrorListener extends ParseErrorListener {
|
|
5
|
-
private preferredRules;
|
|
6
4
|
private objectNames;
|
|
7
|
-
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
5
|
getExpectedText(parser: Parser, token: Token): string;
|
|
9
6
|
}
|
|
@@ -2,8 +2,8 @@ import { CodeCompletionCore } from 'antlr4-c3';
|
|
|
2
2
|
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
3
|
import { PostgreSqlParser } from '../../lib/postgresql/PostgreSqlParser';
|
|
4
4
|
export class PostgreSqlErrorListener extends ParseErrorListener {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.objectNames = new Map([
|
|
8
8
|
[PostgreSqlParser.RULE_database_name, 'database'],
|
|
9
9
|
[PostgreSqlParser.RULE_database_name_create, 'database'],
|
|
@@ -20,18 +20,27 @@ export class PostgreSqlErrorListener extends ParseErrorListener {
|
|
|
20
20
|
[PostgreSqlParser.RULE_procedure_name_create, 'procedure'],
|
|
21
21
|
[PostgreSqlParser.RULE_procedure_name, 'procedure'],
|
|
22
22
|
]);
|
|
23
|
-
this.preferredRules = preferredRules;
|
|
24
23
|
}
|
|
25
24
|
getExpectedText(parser, token) {
|
|
26
25
|
var _a;
|
|
27
26
|
let expectedText = '';
|
|
27
|
+
const input = this.parserContext.getParsedInput();
|
|
28
|
+
/**
|
|
29
|
+
* Get the program context.
|
|
30
|
+
* When called error listener, `this._parseTree` is still `undefined`,
|
|
31
|
+
* so we can't use cached parseTree in `getMinimumParserInfo`
|
|
32
|
+
*/
|
|
28
33
|
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
29
34
|
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
30
35
|
currentContext = currentContext.parent;
|
|
31
36
|
}
|
|
32
|
-
const
|
|
37
|
+
const parserInfo = this.parserContext.getMinimumParserInfo(input, token.tokenIndex, currentContext);
|
|
38
|
+
if (!parserInfo)
|
|
39
|
+
return '';
|
|
40
|
+
const { parser: c3Parser, newTokenIndex, parseTree: c3Context } = parserInfo;
|
|
41
|
+
const core = new CodeCompletionCore(c3Parser);
|
|
33
42
|
core.preferredRules = this.preferredRules;
|
|
34
|
-
const candidates = core.collectCandidates(
|
|
43
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
35
44
|
if (candidates.rules.size) {
|
|
36
45
|
const result = [];
|
|
37
46
|
// get expectedText as collect rules first
|
|
@@ -32,7 +32,8 @@ export class SparkSQL extends BasicSQL {
|
|
|
32
32
|
return new SparkSqlSplitListener();
|
|
33
33
|
}
|
|
34
34
|
createErrorListener(_errorListener) {
|
|
35
|
-
|
|
35
|
+
const parserContext = this;
|
|
36
|
+
return new SparkErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
36
37
|
}
|
|
37
38
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
39
|
return new SparkEntityCollector(input, caretTokenIndex);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
2
2
|
import { Parser, Token } from 'antlr4ng';
|
|
3
|
-
import { LOCALE_TYPE } from '../common/types';
|
|
4
3
|
export declare class SparkErrorListener extends ParseErrorListener {
|
|
5
|
-
private preferredRules;
|
|
6
4
|
private objectNames;
|
|
7
|
-
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
5
|
getExpectedText(parser: Parser, token: Token): string;
|
|
9
6
|
}
|
|
@@ -2,8 +2,8 @@ import { CodeCompletionCore } from 'antlr4-c3';
|
|
|
2
2
|
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
3
|
import { SparkSqlParser } from '../../lib/spark/SparkSqlParser';
|
|
4
4
|
export class SparkErrorListener extends ParseErrorListener {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.objectNames = new Map([
|
|
8
8
|
[SparkSqlParser.RULE_namespaceName, 'namespace'],
|
|
9
9
|
[SparkSqlParser.RULE_namespaceNameCreate, 'namespace'],
|
|
@@ -16,18 +16,27 @@ export class SparkErrorListener extends ParseErrorListener {
|
|
|
16
16
|
[SparkSqlParser.RULE_columnName, 'column'],
|
|
17
17
|
[SparkSqlParser.RULE_columnNameCreate, 'column'],
|
|
18
18
|
]);
|
|
19
|
-
this.preferredRules = preferredRules;
|
|
20
19
|
}
|
|
21
20
|
getExpectedText(parser, token) {
|
|
22
21
|
var _a;
|
|
23
22
|
let expectedText = '';
|
|
23
|
+
const input = this.parserContext.getParsedInput();
|
|
24
|
+
/**
|
|
25
|
+
* Get the program context.
|
|
26
|
+
* When called error listener, `this._parseTree` is still `undefined`,
|
|
27
|
+
* so we can't use cached parseTree in `getMinimumParserInfo`
|
|
28
|
+
*/
|
|
24
29
|
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
25
30
|
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
26
31
|
currentContext = currentContext.parent;
|
|
27
32
|
}
|
|
28
|
-
const
|
|
33
|
+
const parserInfo = this.parserContext.getMinimumParserInfo(input, token.tokenIndex, currentContext);
|
|
34
|
+
if (!parserInfo)
|
|
35
|
+
return '';
|
|
36
|
+
const { parser: c3Parser, newTokenIndex, parseTree: c3Context } = parserInfo;
|
|
37
|
+
const core = new CodeCompletionCore(c3Parser);
|
|
29
38
|
core.preferredRules = this.preferredRules;
|
|
30
|
-
const candidates = core.collectCandidates(
|
|
39
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
31
40
|
if (candidates.rules.size) {
|
|
32
41
|
const result = [];
|
|
33
42
|
// get expectedText as collect rules first
|
|
@@ -34,7 +34,8 @@ export class TrinoSQL extends BasicSQL {
|
|
|
34
34
|
return new TrinoSqlSplitListener();
|
|
35
35
|
}
|
|
36
36
|
createErrorListener(_errorListener) {
|
|
37
|
-
|
|
37
|
+
const parserContext = this;
|
|
38
|
+
return new TrinoErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
38
39
|
}
|
|
39
40
|
createEntityCollector(input, caretTokenIndex) {
|
|
40
41
|
return new TrinoEntityCollector(input, caretTokenIndex);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Parser, Token } from 'antlr4ng';
|
|
2
|
-
import {
|
|
3
|
-
import { LOCALE_TYPE } from '../common/types';
|
|
2
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
4
3
|
export declare class TrinoErrorListener extends ParseErrorListener {
|
|
5
|
-
private preferredRules;
|
|
6
4
|
private objectNames;
|
|
7
|
-
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
5
|
getExpectedText(parser: Parser, token: Token): string;
|
|
9
6
|
}
|