dt-sql-parser 4.1.0-beta.7 → 4.1.0-beta.8

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.
Files changed (38) hide show
  1. package/README.md +51 -0
  2. package/dist/lib/flink/FlinkSqlParser.d.ts +2 -6
  3. package/dist/lib/flink/FlinkSqlParser.js +2122 -2211
  4. package/dist/parser/common/basicSQL.d.ts +14 -1
  5. package/dist/parser/common/basicSQL.js +14 -0
  6. package/dist/parser/common/semanticContextCollector.d.ts +51 -0
  7. package/dist/parser/common/semanticContextCollector.js +202 -0
  8. package/dist/parser/common/types.d.ts +25 -0
  9. package/dist/parser/common/types.js +7 -0
  10. package/dist/parser/flink/flinkSemanticContextCollector.d.ts +9 -0
  11. package/dist/parser/flink/flinkSemanticContextCollector.js +14 -0
  12. package/dist/parser/flink/index.d.ts +3 -1
  13. package/dist/parser/flink/index.js +5 -1
  14. package/dist/parser/hive/hiveSemanticContextCollector.d.ts +9 -0
  15. package/dist/parser/hive/hiveSemanticContextCollector.js +14 -0
  16. package/dist/parser/hive/index.d.ts +3 -1
  17. package/dist/parser/hive/index.js +5 -1
  18. package/dist/parser/impala/impalaSemanticContextCollector.d.ts +9 -0
  19. package/dist/parser/impala/impalaSemanticContextCollector.js +14 -0
  20. package/dist/parser/impala/index.d.ts +3 -1
  21. package/dist/parser/impala/index.js +5 -1
  22. package/dist/parser/mysql/index.d.ts +3 -1
  23. package/dist/parser/mysql/index.js +5 -1
  24. package/dist/parser/mysql/mysqlSemanticContextCollector.d.ts +9 -0
  25. package/dist/parser/mysql/mysqlSemanticContextCollector.js +14 -0
  26. package/dist/parser/postgresql/index.d.ts +3 -1
  27. package/dist/parser/postgresql/index.js +5 -1
  28. package/dist/parser/postgresql/postgreSemanticContextCollector.d.ts +9 -0
  29. package/dist/parser/postgresql/postgreSemanticContextCollector.js +14 -0
  30. package/dist/parser/spark/index.d.ts +3 -1
  31. package/dist/parser/spark/index.js +5 -1
  32. package/dist/parser/spark/sparkSemanticContextCollector.d.ts +9 -0
  33. package/dist/parser/spark/sparkSemanticContextCollector.js +14 -0
  34. package/dist/parser/trino/index.d.ts +3 -1
  35. package/dist/parser/trino/index.js +5 -1
  36. package/dist/parser/trino/trinoSemanticContextCollector.d.ts +9 -0
  37. package/dist/parser/trino/trinoSemanticContextCollector.js +14 -0
  38. package/package.json +1 -1
@@ -2,11 +2,12 @@ import { Lexer, Token, CommonTokenStream, CharStream, ParserRuleContext, ParseTr
2
2
  import { CandidatesCollection } from 'antlr4-c3';
3
3
  import { SQLParserBase } from '../../lib/SQLParserBase';
4
4
  import { TextSlice } from './textAndWord';
5
- import { CaretPosition, LOCALE_TYPE, Suggestions } from './types';
5
+ import { CaretPosition, LOCALE_TYPE, SemanticCollectOptions, Suggestions } from './types';
6
6
  import { ParseError, ErrorListener } from './parseErrorListener';
7
7
  import type { SplitListener } from './splitListener';
8
8
  import type { EntityCollector } from './entityCollector';
9
9
  import { EntityContext } from './entityCollector';
10
+ import SemanticContextCollector from './semanticContextCollector';
10
11
  /**
11
12
  * Basic SQL class, every sql needs extends it.
12
13
  */
@@ -56,6 +57,10 @@ export declare abstract class BasicSQL<L extends Lexer = Lexer, PRC extends Pars
56
57
  */
57
58
  protected abstract createEntityCollector(input: string, caretTokenIndex?: number): EntityCollector;
58
59
  locale: LOCALE_TYPE;
60
+ /**
61
+ * Get a new semanticContextCollector instance.
62
+ */
63
+ protected abstract createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): SemanticContextCollector;
59
64
  /**
60
65
  * Create an antlr4 lexer from input.
61
66
  * @param input string
@@ -136,4 +141,12 @@ export declare abstract class BasicSQL<L extends Lexer = Lexer, PRC extends Pars
136
141
  */
137
142
  getSuggestionAtCaretPosition(input: string, caretPosition: CaretPosition): Suggestions | null;
138
143
  getAllEntities(input: string, caretPosition?: CaretPosition): EntityContext[] | null;
144
+ /**
145
+ * Get semantic context infos
146
+ * @param input source string
147
+ * @param caretPosition caret position, such as cursor position
148
+ * @param options semantic context options
149
+ * @returns analyzed semantic context
150
+ */
151
+ getSemanticContextAtCaretPosition(input: string, caretPosition: CaretPosition, options?: SemanticCollectOptions): import("./types").SemanticContext;
139
152
  }
@@ -300,4 +300,18 @@ export class BasicSQL {
300
300
  // parser.entityCollecting = false;
301
301
  return collectListener.getEntities();
302
302
  }
303
+ /**
304
+ * Get semantic context infos
305
+ * @param input source string
306
+ * @param caretPosition caret position, such as cursor position
307
+ * @param options semantic context options
308
+ * @returns analyzed semantic context
309
+ */
310
+ getSemanticContextAtCaretPosition(input, caretPosition, options) {
311
+ const allTokens = this.getAllTokens(input);
312
+ const parseTree = this.parseWithCache(input);
313
+ const statementContextListener = this.createSemanticContextCollector(input, caretPosition, allTokens, options);
314
+ this.listen(statementContextListener, parseTree);
315
+ return statementContextListener.semanticContext;
316
+ }
303
317
  }
@@ -0,0 +1,51 @@
1
+ import { ErrorNode, ParserRuleContext, TerminalNode, Token } from 'antlr4ng';
2
+ import { CaretPosition, SemanticCollectOptions, SemanticContext } from '../common/types';
3
+ export declare const SQL_SPLIT_SYMBOL_TEXT = ";";
4
+ declare abstract class SemanticContextCollector {
5
+ constructor(_input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions);
6
+ readonly options: SemanticCollectOptions;
7
+ private _tokenIndex;
8
+ private _allTokens;
9
+ /**
10
+ * If current caret position is in a beginning of statement semantics, it needs to follow some cases:
11
+ * @case1 there is no statement node with an error before the current statement in the parse tree;
12
+ *
13
+ * @case2 if it is an uncomplete keyword, it will be parsed as an `ErrorNode`
14
+ * and need be a direct child node of `program`;
15
+ *
16
+ * @case3 if it is a complete keyword, the parsed TerminalNode or ErrorNode should be
17
+ * the first leaf node of current statement rule;
18
+ *
19
+ * @case4 if it is whiteSpace in caret position, we can't visit it in antlr4 listener,
20
+ * so we find the first unhidden token before the whiteSpace token, and the unhidden token
21
+ * should be the last leaf node of statement its belongs to;
22
+ *
23
+ * @case5 if the previous token is split symbol like `;`, ignore case1 and forcefully judged as beginning of statement.
24
+ */
25
+ private _isStatementBeginning;
26
+ /**
27
+ * Prev tokenIndex that not white space before current tokenIndex or caret position
28
+ */
29
+ private _prevTokenIndex;
30
+ get semanticContext(): SemanticContext;
31
+ abstract getWhiteSpaceRuleType(): number;
32
+ abstract getStatementRuleType(): number;
33
+ private prevStatementHasError;
34
+ /**
35
+ * Most root rule is `program`.
36
+ */
37
+ private isRootRule;
38
+ /**
39
+ * link to @case4
40
+ * It should be called in each language's own `enterStatement`.
41
+ */
42
+ protected visitStatement(ctx: ParserRuleContext): void;
43
+ /**
44
+ * Uncomplete keyword will be error node
45
+ */
46
+ visitErrorNode(node: ErrorNode): void;
47
+ visitTerminal(node: TerminalNode): void;
48
+ enterEveryRule(_node: ParserRuleContext): void;
49
+ exitEveryRule(_node: ParserRuleContext): void;
50
+ }
51
+ export default SemanticContextCollector;
@@ -0,0 +1,202 @@
1
+ import { ErrorNode, ParserRuleContext, Token } from 'antlr4ng';
2
+ import { findCaretTokenIndex } from '../common/findCaretTokenIndex';
3
+ import { SqlSplitStrategy, } from '../common/types';
4
+ export const SQL_SPLIT_SYMBOL_TEXT = ';';
5
+ class SemanticContextCollector {
6
+ constructor(_input, caretPosition, allTokens, options) {
7
+ this.options = {
8
+ sqlSplitStrategy: SqlSplitStrategy.STRICT,
9
+ };
10
+ this._allTokens = [];
11
+ /**
12
+ * If current caret position is in a beginning of statement semantics, it needs to follow some cases:
13
+ * @case1 there is no statement node with an error before the current statement in the parse tree;
14
+ *
15
+ * @case2 if it is an uncomplete keyword, it will be parsed as an `ErrorNode`
16
+ * and need be a direct child node of `program`;
17
+ *
18
+ * @case3 if it is a complete keyword, the parsed TerminalNode or ErrorNode should be
19
+ * the first leaf node of current statement rule;
20
+ *
21
+ * @case4 if it is whiteSpace in caret position, we can't visit it in antlr4 listener,
22
+ * so we find the first unhidden token before the whiteSpace token, and the unhidden token
23
+ * should be the last leaf node of statement its belongs to;
24
+ *
25
+ * @case5 if the previous token is split symbol like `;`, ignore case1 and forcefully judged as beginning of statement.
26
+ */
27
+ this._isStatementBeginning = false;
28
+ // If caretPosition token is whiteSpace, tokenIndex may be undefined.
29
+ const tokenIndex = findCaretTokenIndex(caretPosition, allTokens);
30
+ if (tokenIndex !== undefined) {
31
+ this._tokenIndex = tokenIndex;
32
+ }
33
+ this._allTokens = allTokens;
34
+ this.options = Object.assign(Object.assign({}, this.options), options);
35
+ if (allTokens === null || allTokens === void 0 ? void 0 : allTokens.length) {
36
+ let i = tokenIndex ? tokenIndex - 1 : allTokens.length - 1;
37
+ /**
38
+ * Link to @case4 and @case5
39
+ * Find the previous unhidden token.
40
+ * If can't find tokenIndex or current token is whiteSpace at caretPosition,
41
+ * prevTokenIndex is useful to help us determine if it is beginning of statement.
42
+ */
43
+ while (i >= 0) {
44
+ if (allTokens[i].channel !== Token.HIDDEN_CHANNEL &&
45
+ (allTokens[i].line < caretPosition.lineNumber ||
46
+ (allTokens[i].line === caretPosition.lineNumber &&
47
+ allTokens[i].column < caretPosition.column))) {
48
+ this._prevTokenIndex = allTokens[i].tokenIndex;
49
+ break;
50
+ }
51
+ i--;
52
+ }
53
+ /**
54
+ * We can directly conclude beginning of statement semantics when current token is
55
+ * the first token of tokenStream or the previous token is semicolon
56
+ */
57
+ if (tokenIndex === 0 ||
58
+ i === -1 ||
59
+ (this._prevTokenIndex &&
60
+ this._allTokens[this._prevTokenIndex].text === SQL_SPLIT_SYMBOL_TEXT)) {
61
+ this._isStatementBeginning = true;
62
+ }
63
+ }
64
+ }
65
+ get semanticContext() {
66
+ return {
67
+ isStatementBeginning: this._isStatementBeginning,
68
+ };
69
+ }
70
+ prevStatementHasError(node) {
71
+ let parent = node.parent;
72
+ if (!parent)
73
+ return false;
74
+ const currentNodeIndex = parent.children.findIndex((child) => child === node);
75
+ if (currentNodeIndex <= 0)
76
+ return false;
77
+ for (let i = currentNodeIndex - 1; i >= 0; i--) {
78
+ const prevNode = parent.children[i];
79
+ if (prevNode instanceof ErrorNode ||
80
+ (prevNode instanceof ParserRuleContext && prevNode.exception !== null))
81
+ return true;
82
+ }
83
+ return false;
84
+ }
85
+ /**
86
+ * Most root rule is `program`.
87
+ */
88
+ isRootRule(node) {
89
+ return node instanceof ParserRuleContext && (node === null || node === void 0 ? void 0 : node.parent) === null;
90
+ }
91
+ /**
92
+ * link to @case4
93
+ * It should be called in each language's own `enterStatement`.
94
+ */
95
+ visitStatement(ctx) {
96
+ var _a, _b, _c;
97
+ if (this.options.sqlSplitStrategy === SqlSplitStrategy.STRICT)
98
+ return;
99
+ const isWhiteSpaceToken = this._tokenIndex === undefined ||
100
+ ((_a = this._allTokens[this._tokenIndex]) === null || _a === void 0 ? void 0 : _a.type) === this.getWhiteSpaceRuleType() ||
101
+ // PostgreSQL whiteSpace not inlcudes '\n' symbol
102
+ ((_b = this._allTokens[this._tokenIndex]) === null || _b === void 0 ? void 0 : _b.text) === '\n';
103
+ const isPrevTokenEndOfStatement = this._prevTokenIndex && ((_c = ctx.stop) === null || _c === void 0 ? void 0 : _c.tokenIndex) === this._prevTokenIndex;
104
+ if (isWhiteSpaceToken && isPrevTokenEndOfStatement && ctx.exception === null) {
105
+ this._isStatementBeginning = !this.prevStatementHasError(ctx)
106
+ ? true
107
+ : this._isStatementBeginning;
108
+ }
109
+ }
110
+ /**
111
+ * Uncomplete keyword will be error node
112
+ */
113
+ visitErrorNode(node) {
114
+ var _a, _b, _c, _d;
115
+ if (node.symbol.tokenIndex !== this._tokenIndex ||
116
+ this._isStatementBeginning ||
117
+ this.options.sqlSplitStrategy === SqlSplitStrategy.STRICT)
118
+ return;
119
+ let parent = node.parent;
120
+ let currentNode = node;
121
+ /**
122
+ * Link to @case2
123
+ * The error node is a direct child node of the program node
124
+ */
125
+ if (this.isRootRule(parent)) {
126
+ this._isStatementBeginning = !this.prevStatementHasError(currentNode);
127
+ return;
128
+ }
129
+ /**
130
+ * Link to @case3
131
+ * Error node must be the first leaf node of the statement parse tree.
132
+ **/
133
+ while (parent !== null && parent.ruleIndex !== this.getStatementRuleType()) {
134
+ if (((_a = parent.children) === null || _a === void 0 ? void 0 : _a[0]) !== currentNode) {
135
+ this._isStatementBeginning = false;
136
+ return;
137
+ }
138
+ currentNode = parent;
139
+ parent = currentNode.parent;
140
+ }
141
+ let isStatementBeginning = true;
142
+ /**
143
+ * Link to @case1
144
+ * Previous statement must have no exception
145
+ */
146
+ if ((parent === null || parent === void 0 ? void 0 : parent.ruleIndex) === this.getStatementRuleType()) {
147
+ const programRule = parent.parent;
148
+ const currentStatementRuleIndex = ((_b = programRule === null || programRule === void 0 ? void 0 : programRule.children) === null || _b === void 0 ? void 0 : _b.findIndex((node) => node === parent)) || -1;
149
+ if (currentStatementRuleIndex > 0) {
150
+ /**
151
+ * When you typed a keyword and doesn't match any rule, you will get a EOF error,
152
+ * For example, just typed 'CREATE', 'INSERT'.
153
+ */
154
+ const isStatementEOF = ((_d = (_c = parent.exception) === null || _c === void 0 ? void 0 : _c.offendingToken) === null || _d === void 0 ? void 0 : _d.text) === '<EOF>';
155
+ isStatementBeginning =
156
+ this.prevStatementHasError(parent) && !isStatementEOF
157
+ ? false
158
+ : isStatementBeginning;
159
+ }
160
+ }
161
+ this._isStatementBeginning = isStatementBeginning;
162
+ }
163
+ visitTerminal(node) {
164
+ var _a, _b;
165
+ if (node.symbol.tokenIndex !== this._tokenIndex ||
166
+ this._isStatementBeginning ||
167
+ this.options.sqlSplitStrategy === SqlSplitStrategy.STRICT)
168
+ return;
169
+ let currentNode = node;
170
+ let parent = node.parent;
171
+ /**
172
+ * Link to @case3
173
+ * Current terminal node must be the first leaf node of the statement parse tree.
174
+ **/
175
+ while (parent !== null && parent.ruleIndex !== this.getStatementRuleType()) {
176
+ if (((_a = parent.children) === null || _a === void 0 ? void 0 : _a[0]) !== currentNode) {
177
+ this._isStatementBeginning = false;
178
+ return;
179
+ }
180
+ currentNode = parent;
181
+ parent = currentNode.parent;
182
+ }
183
+ let isStatementBeginning = true;
184
+ /**
185
+ * Link to @case1
186
+ * Previous statement must have no exception
187
+ */
188
+ if ((parent === null || parent === void 0 ? void 0 : parent.ruleIndex) === this.getStatementRuleType()) {
189
+ const programRule = parent.parent;
190
+ const currentStatementRuleIndex = ((_b = programRule === null || programRule === void 0 ? void 0 : programRule.children) === null || _b === void 0 ? void 0 : _b.findIndex((node) => node === parent)) || -1;
191
+ if (currentStatementRuleIndex > 0) {
192
+ isStatementBeginning = this.prevStatementHasError(parent)
193
+ ? false
194
+ : isStatementBeginning;
195
+ }
196
+ }
197
+ this._isStatementBeginning = isStatementBeginning;
198
+ }
199
+ enterEveryRule(_node) { }
200
+ exitEveryRule(_node) { }
201
+ }
202
+ export default SemanticContextCollector;
@@ -64,3 +64,28 @@ export interface Suggestions<T = WordRange> {
64
64
  readonly keywords: string[];
65
65
  }
66
66
  export type LOCALE_TYPE = 'zh_CN' | 'en_US';
67
+ export interface SemanticContext {
68
+ isStatementBeginning: boolean;
69
+ }
70
+ export declare enum SqlSplitStrategy {
71
+ /** Only end the statement with semicolon symbol */
72
+ STRICT = 0,
73
+ /** Based on parse tree to split statements */
74
+ LOOSE = 1
75
+ }
76
+ export interface SemanticCollectOptions {
77
+ /**
78
+ * `sqlSplitStrategy` will affects the result of `isStatementBeginning`;
79
+ *
80
+ * For example:
81
+ *
82
+ * The sql is "select id from t1 create\<cart_position\>"
83
+ *
84
+ * - `SqlSplitStrategy.STRICT`: split symbol `;` is missing after select statement so that it considerd as one statement, and `isStatementBeginning` is false
85
+ *
86
+ * - `SqlSplitStrategy.LOOSE`: in parse tree, it will parse to "select id from t1" and "create" two single statement, so `isStatementBeginning` is true
87
+ *
88
+ * @default SqlSplitStrategy.STRICT
89
+ */
90
+ sqlSplitStrategy?: SqlSplitStrategy;
91
+ }
@@ -32,3 +32,10 @@ export var EntityContextType;
32
32
  /** column name that will be created */
33
33
  EntityContextType["COLUMN_CREATE"] = "columnCreate";
34
34
  })(EntityContextType || (EntityContextType = {}));
35
+ export var SqlSplitStrategy;
36
+ (function (SqlSplitStrategy) {
37
+ /** Only end the statement with semicolon symbol */
38
+ SqlSplitStrategy[SqlSplitStrategy["STRICT"] = 0] = "STRICT";
39
+ /** Based on parse tree to split statements */
40
+ SqlSplitStrategy[SqlSplitStrategy["LOOSE"] = 1] = "LOOSE";
41
+ })(SqlSplitStrategy || (SqlSplitStrategy = {}));
@@ -0,0 +1,9 @@
1
+ import { FlinkSqlParserListener } from '../../lib';
2
+ import { SingleStatementContext } from '../../lib/flink/FlinkSqlParser';
3
+ import SemanticContextCollector from '../common/semanticContextCollector';
4
+ declare class FlinkSemanticContextCollector extends SemanticContextCollector implements FlinkSqlParserListener {
5
+ getWhiteSpaceRuleType(): number;
6
+ getStatementRuleType(): number;
7
+ enterSingleStatement(ctx: SingleStatementContext): void;
8
+ }
9
+ export { FlinkSemanticContextCollector };
@@ -0,0 +1,14 @@
1
+ import { FlinkSqlParser } from '../../lib/flink/FlinkSqlParser';
2
+ import SemanticContextCollector from '../common/semanticContextCollector';
3
+ class FlinkSemanticContextCollector extends SemanticContextCollector {
4
+ getWhiteSpaceRuleType() {
5
+ return FlinkSqlParser.SPACE;
6
+ }
7
+ getStatementRuleType() {
8
+ return FlinkSqlParser.RULE_singleStatement;
9
+ }
10
+ enterSingleStatement(ctx) {
11
+ this.visitStatement(ctx);
12
+ }
13
+ }
14
+ export { FlinkSemanticContextCollector };
@@ -2,12 +2,13 @@ import { CharStream, CommonTokenStream, Token } from 'antlr4ng';
2
2
  import { CandidatesCollection } from 'antlr4-c3';
3
3
  import { FlinkSqlLexer } from '../../lib/flink/FlinkSqlLexer';
4
4
  import { FlinkSqlParser, ProgramContext } from '../../lib/flink/FlinkSqlParser';
5
- import { Suggestions } from '../common/types';
5
+ import { CaretPosition, SemanticCollectOptions, Suggestions } from '../common/types';
6
6
  import { BasicSQL } from '../common/basicSQL';
7
7
  import { FlinkSqlSplitListener } from './flinkSplitListener';
8
8
  import { FlinkEntityCollector } from './flinkEntityCollector';
9
9
  import { ErrorListener } from '../common/parseErrorListener';
10
10
  import { FlinkErrorListener } from './flinkErrorListener';
11
+ import { FlinkSemanticContextCollector } from './flinkSemanticContextCollector';
11
12
  export { FlinkSqlSplitListener, FlinkEntityCollector };
12
13
  export declare class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, FlinkSqlParser> {
13
14
  protected createLexerFromCharStream(charStreams: CharStream): FlinkSqlLexer;
@@ -16,5 +17,6 @@ export declare class FlinkSQL extends BasicSQL<FlinkSqlLexer, ProgramContext, Fl
16
17
  protected get splitListener(): FlinkSqlSplitListener;
17
18
  protected createErrorListener(_errorListener: ErrorListener): FlinkErrorListener;
18
19
  protected createEntityCollector(input: string, caretTokenIndex?: number): FlinkEntityCollector;
20
+ protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): FlinkSemanticContextCollector;
19
21
  protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
20
22
  }
@@ -1,10 +1,11 @@
1
1
  import { FlinkSqlLexer } from '../../lib/flink/FlinkSqlLexer';
2
2
  import { FlinkSqlParser } from '../../lib/flink/FlinkSqlParser';
3
- import { EntityContextType } from '../common/types';
3
+ import { EntityContextType, } from '../common/types';
4
4
  import { BasicSQL } from '../common/basicSQL';
5
5
  import { FlinkSqlSplitListener } from './flinkSplitListener';
6
6
  import { FlinkEntityCollector } from './flinkEntityCollector';
7
7
  import { FlinkErrorListener } from './flinkErrorListener';
8
+ import { FlinkSemanticContextCollector } from './flinkSemanticContextCollector';
8
9
  export { FlinkSqlSplitListener, FlinkEntityCollector };
9
10
  export class FlinkSQL extends BasicSQL {
10
11
  constructor() {
@@ -39,6 +40,9 @@ export class FlinkSQL extends BasicSQL {
39
40
  createEntityCollector(input, caretTokenIndex) {
40
41
  return new FlinkEntityCollector(input, caretTokenIndex);
41
42
  }
43
+ createSemanticContextCollector(input, caretPosition, allTokens, options) {
44
+ return new FlinkSemanticContextCollector(input, caretPosition, allTokens, options);
45
+ }
42
46
  processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
43
47
  const originalSyntaxSuggestions = [];
44
48
  const keywords = [];
@@ -0,0 +1,9 @@
1
+ import { HiveSqlParserListener } from '../../lib';
2
+ import { StatementContext } from '../../lib/hive/HiveSqlParser';
3
+ import SemanticContextCollector from '../common/semanticContextCollector';
4
+ declare class HiveSemanticContextCollector extends SemanticContextCollector implements HiveSqlParserListener {
5
+ getWhiteSpaceRuleType(): number;
6
+ getStatementRuleType(): number;
7
+ enterStatement(ctx: StatementContext): void;
8
+ }
9
+ export { HiveSemanticContextCollector };
@@ -0,0 +1,14 @@
1
+ import { HiveSqlParser } from '../../lib/hive/HiveSqlParser';
2
+ import SemanticContextCollector from '../common/semanticContextCollector';
3
+ class HiveSemanticContextCollector extends SemanticContextCollector {
4
+ getWhiteSpaceRuleType() {
5
+ return HiveSqlParser.WHITE_SPACE;
6
+ }
7
+ getStatementRuleType() {
8
+ return HiveSqlParser.RULE_statement;
9
+ }
10
+ enterStatement(ctx) {
11
+ this.visitStatement(ctx);
12
+ }
13
+ }
14
+ export { HiveSemanticContextCollector };
@@ -3,11 +3,12 @@ import { CandidatesCollection } from 'antlr4-c3';
3
3
  import { HiveSqlLexer } from '../../lib/hive/HiveSqlLexer';
4
4
  import { HiveSqlParser, ProgramContext } from '../../lib/hive/HiveSqlParser';
5
5
  import { BasicSQL } from '../common/basicSQL';
6
- import { Suggestions } from '../common/types';
6
+ import { CaretPosition, SemanticCollectOptions, Suggestions } from '../common/types';
7
7
  import { HiveSqlSplitListener } from './hiveSplitListener';
8
8
  import { HiveEntityCollector } from './hiveEntityCollector';
9
9
  import { ErrorListener } from '../common/parseErrorListener';
10
10
  import { HiveErrorListener } from './hiveErrorListener';
11
+ import { HiveSemanticContextCollector } from './hiveSemanticContextCollector';
11
12
  export { HiveEntityCollector, HiveSqlSplitListener };
12
13
  export declare class HiveSQL extends BasicSQL<HiveSqlLexer, ProgramContext, HiveSqlParser> {
13
14
  protected createLexerFromCharStream(charStreams: CharStream): HiveSqlLexer;
@@ -16,5 +17,6 @@ export declare class HiveSQL extends BasicSQL<HiveSqlLexer, ProgramContext, Hive
16
17
  protected get splitListener(): HiveSqlSplitListener;
17
18
  protected createErrorListener(_errorListener: ErrorListener): HiveErrorListener;
18
19
  protected createEntityCollector(input: string, caretTokenIndex?: number): HiveEntityCollector;
20
+ protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): HiveSemanticContextCollector;
19
21
  protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
20
22
  }
@@ -1,10 +1,11 @@
1
1
  import { HiveSqlLexer } from '../../lib/hive/HiveSqlLexer';
2
2
  import { HiveSqlParser } from '../../lib/hive/HiveSqlParser';
3
3
  import { BasicSQL } from '../common/basicSQL';
4
- import { EntityContextType } from '../common/types';
4
+ import { EntityContextType, } from '../common/types';
5
5
  import { HiveSqlSplitListener } from './hiveSplitListener';
6
6
  import { HiveEntityCollector } from './hiveEntityCollector';
7
7
  import { HiveErrorListener } from './hiveErrorListener';
8
+ import { HiveSemanticContextCollector } from './hiveSemanticContextCollector';
8
9
  export { HiveEntityCollector, HiveSqlSplitListener };
9
10
  export class HiveSQL extends BasicSQL {
10
11
  constructor() {
@@ -39,6 +40,9 @@ export class HiveSQL extends BasicSQL {
39
40
  createEntityCollector(input, caretTokenIndex) {
40
41
  return new HiveEntityCollector(input, caretTokenIndex);
41
42
  }
43
+ createSemanticContextCollector(input, caretPosition, allTokens, options) {
44
+ return new HiveSemanticContextCollector(input, caretPosition, allTokens, options);
45
+ }
42
46
  processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
43
47
  const originalSyntaxSuggestions = [];
44
48
  const keywords = [];
@@ -0,0 +1,9 @@
1
+ import { ImpalaSqlParserListener } from '../../lib';
2
+ import { SingleStatementContext } from '../../lib/impala/ImpalaSqlParser';
3
+ import SemanticContextCollector from '../common/semanticContextCollector';
4
+ declare class ImpalaSemanticContextCollector extends SemanticContextCollector implements ImpalaSqlParserListener {
5
+ getWhiteSpaceRuleType(): number;
6
+ getStatementRuleType(): number;
7
+ enterSingleStatement(ctx: SingleStatementContext): void;
8
+ }
9
+ export { ImpalaSemanticContextCollector };
@@ -0,0 +1,14 @@
1
+ import { ImpalaSqlParser } from '../../lib/impala/ImpalaSqlParser';
2
+ import SemanticContextCollector from '../common/semanticContextCollector';
3
+ class ImpalaSemanticContextCollector extends SemanticContextCollector {
4
+ getWhiteSpaceRuleType() {
5
+ return ImpalaSqlParser.WS;
6
+ }
7
+ getStatementRuleType() {
8
+ return ImpalaSqlParser.RULE_singleStatement;
9
+ }
10
+ enterSingleStatement(ctx) {
11
+ this.visitStatement(ctx);
12
+ }
13
+ }
14
+ export { ImpalaSemanticContextCollector };
@@ -3,11 +3,12 @@ import { CandidatesCollection } from 'antlr4-c3';
3
3
  import { ImpalaSqlLexer } from '../../lib/impala/ImpalaSqlLexer';
4
4
  import { ImpalaSqlParser, ProgramContext } from '../../lib/impala/ImpalaSqlParser';
5
5
  import { BasicSQL } from '../common/basicSQL';
6
- import { Suggestions } from '../common/types';
6
+ import { CaretPosition, SemanticCollectOptions, Suggestions } from '../common/types';
7
7
  import { ImpalaSqlSplitListener } from './impalaSplitListener';
8
8
  import { ImpalaEntityCollector } from './impalaEntityCollector';
9
9
  import { ErrorListener } from '../common/parseErrorListener';
10
10
  import { ImpalaErrorListener } from './ImpalaErrorListener';
11
+ import { ImpalaSemanticContextCollector } from './impalaSemanticContextCollector';
11
12
  export { ImpalaEntityCollector, ImpalaSqlSplitListener };
12
13
  export declare class ImpalaSQL extends BasicSQL<ImpalaSqlLexer, ProgramContext, ImpalaSqlParser> {
13
14
  protected createLexerFromCharStream(charStreams: CharStream): ImpalaSqlLexer;
@@ -16,5 +17,6 @@ export declare class ImpalaSQL extends BasicSQL<ImpalaSqlLexer, ProgramContext,
16
17
  protected get splitListener(): ImpalaSqlSplitListener;
17
18
  protected createErrorListener(_errorListener: ErrorListener): ImpalaErrorListener;
18
19
  protected createEntityCollector(input: string, caretTokenIndex?: number): ImpalaEntityCollector;
20
+ protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): ImpalaSemanticContextCollector;
19
21
  protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
20
22
  }
@@ -1,10 +1,11 @@
1
1
  import { ImpalaSqlLexer } from '../../lib/impala/ImpalaSqlLexer';
2
2
  import { ImpalaSqlParser } from '../../lib/impala/ImpalaSqlParser';
3
3
  import { BasicSQL } from '../common/basicSQL';
4
- import { EntityContextType } from '../common/types';
4
+ import { EntityContextType, } from '../common/types';
5
5
  import { ImpalaSqlSplitListener } from './impalaSplitListener';
6
6
  import { ImpalaEntityCollector } from './impalaEntityCollector';
7
7
  import { ImpalaErrorListener } from './ImpalaErrorListener';
8
+ import { ImpalaSemanticContextCollector } from './impalaSemanticContextCollector';
8
9
  export { ImpalaEntityCollector, ImpalaSqlSplitListener };
9
10
  export class ImpalaSQL extends BasicSQL {
10
11
  constructor() {
@@ -38,6 +39,9 @@ export class ImpalaSQL extends BasicSQL {
38
39
  createEntityCollector(input, caretTokenIndex) {
39
40
  return new ImpalaEntityCollector(input, caretTokenIndex);
40
41
  }
42
+ createSemanticContextCollector(input, caretPosition, allTokens, options) {
43
+ return new ImpalaSemanticContextCollector(input, caretPosition, allTokens, options);
44
+ }
41
45
  processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
42
46
  const originalSyntaxSuggestions = [];
43
47
  const keywords = [];
@@ -3,11 +3,12 @@ import { CandidatesCollection } from 'antlr4-c3';
3
3
  import { MySqlLexer } from '../../lib/mysql/MySqlLexer';
4
4
  import { MySqlParser, ProgramContext } from '../../lib/mysql/MySqlParser';
5
5
  import { BasicSQL } from '../common/basicSQL';
6
- import { Suggestions } from '../common/types';
6
+ import { Suggestions, CaretPosition, SemanticCollectOptions } from '../common/types';
7
7
  import { MysqlSplitListener } from './mysqlSplitListener';
8
8
  import { MySqlEntityCollector } from './mysqlEntityCollector';
9
9
  import { MysqlErrorListener } from './mysqlErrorListener';
10
10
  import { ErrorListener } from '../common/parseErrorListener';
11
+ import { MySqlSemanticContextCollector } from '../mysql/mysqlSemanticContextCollector';
11
12
  export { MySqlEntityCollector, MysqlSplitListener };
12
13
  export declare class MySQL extends BasicSQL<MySqlLexer, ProgramContext, MySqlParser> {
13
14
  protected createLexerFromCharStream(charStreams: CharStream): MySqlLexer;
@@ -16,5 +17,6 @@ export declare class MySQL extends BasicSQL<MySqlLexer, ProgramContext, MySqlPar
16
17
  protected get splitListener(): MysqlSplitListener;
17
18
  protected createErrorListener(_errorListener: ErrorListener): MysqlErrorListener;
18
19
  protected createEntityCollector(input: string, caretTokenIndex?: number): MySqlEntityCollector;
20
+ protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): MySqlSemanticContextCollector;
19
21
  protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
20
22
  }
@@ -1,10 +1,11 @@
1
1
  import { MySqlLexer } from '../../lib/mysql/MySqlLexer';
2
2
  import { MySqlParser } from '../../lib/mysql/MySqlParser';
3
3
  import { BasicSQL } from '../common/basicSQL';
4
- import { EntityContextType } from '../common/types';
4
+ import { EntityContextType, } from '../common/types';
5
5
  import { MysqlSplitListener } from './mysqlSplitListener';
6
6
  import { MySqlEntityCollector } from './mysqlEntityCollector';
7
7
  import { MysqlErrorListener } from './mysqlErrorListener';
8
+ import { MySqlSemanticContextCollector } from '../mysql/mysqlSemanticContextCollector';
8
9
  export { MySqlEntityCollector, MysqlSplitListener };
9
10
  export class MySQL extends BasicSQL {
10
11
  constructor() {
@@ -38,6 +39,9 @@ export class MySQL extends BasicSQL {
38
39
  createEntityCollector(input, caretTokenIndex) {
39
40
  return new MySqlEntityCollector(input, caretTokenIndex);
40
41
  }
42
+ createSemanticContextCollector(input, caretPosition, allTokens, options) {
43
+ return new MySqlSemanticContextCollector(input, caretPosition, allTokens, options);
44
+ }
41
45
  processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
42
46
  const originalSyntaxSuggestions = [];
43
47
  const keywords = [];
@@ -0,0 +1,9 @@
1
+ import { MySqlParserListener } from '../../lib';
2
+ import { SingleStatementContext } from '../../lib/mysql/MySqlParser';
3
+ import SemanticContextCollector from '../common/semanticContextCollector';
4
+ declare class MySqlSemanticContextCollector extends SemanticContextCollector implements MySqlParserListener {
5
+ getWhiteSpaceRuleType(): number;
6
+ getStatementRuleType(): number;
7
+ enterSingleStatement(ctx: SingleStatementContext): void;
8
+ }
9
+ export { MySqlSemanticContextCollector };
@@ -0,0 +1,14 @@
1
+ import { MySqlParser } from '../../lib/mysql/MySqlParser';
2
+ import SemanticContextCollector from '../common/semanticContextCollector';
3
+ class MySqlSemanticContextCollector extends SemanticContextCollector {
4
+ getWhiteSpaceRuleType() {
5
+ return MySqlParser.SPACE;
6
+ }
7
+ getStatementRuleType() {
8
+ return MySqlParser.RULE_singleStatement;
9
+ }
10
+ enterSingleStatement(ctx) {
11
+ this.visitStatement(ctx);
12
+ }
13
+ }
14
+ export { MySqlSemanticContextCollector };