dt-sql-parser 4.1.0-beta.6 → 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.
- package/README.md +51 -0
- package/dist/lib/flink/FlinkSqlParser.d.ts +2 -6
- package/dist/lib/flink/FlinkSqlParser.js +1232 -1289
- package/dist/parser/common/basicSQL.d.ts +31 -1
- package/dist/parser/common/basicSQL.js +67 -22
- package/dist/parser/common/parseErrorListener.d.ts +5 -3
- package/dist/parser/common/parseErrorListener.js +6 -2
- package/dist/parser/common/semanticContextCollector.d.ts +51 -0
- package/dist/parser/common/semanticContextCollector.js +202 -0
- package/dist/parser/common/types.d.ts +25 -0
- package/dist/parser/common/types.js +7 -0
- package/dist/parser/flink/flinkErrorListener.d.ts +1 -4
- package/dist/parser/flink/flinkErrorListener.js +14 -5
- package/dist/parser/flink/flinkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/flink/flinkSemanticContextCollector.js +14 -0
- package/dist/parser/flink/index.d.ts +3 -1
- package/dist/parser/flink/index.js +7 -2
- package/dist/parser/hive/hiveErrorListener.d.ts +1 -4
- package/dist/parser/hive/hiveErrorListener.js +14 -5
- package/dist/parser/hive/hiveSemanticContextCollector.d.ts +9 -0
- package/dist/parser/hive/hiveSemanticContextCollector.js +14 -0
- package/dist/parser/hive/index.d.ts +3 -1
- package/dist/parser/hive/index.js +7 -2
- package/dist/parser/impala/ImpalaErrorListener.d.ts +1 -4
- package/dist/parser/impala/ImpalaErrorListener.js +14 -5
- package/dist/parser/impala/impalaSemanticContextCollector.d.ts +9 -0
- package/dist/parser/impala/impalaSemanticContextCollector.js +14 -0
- package/dist/parser/impala/index.d.ts +3 -1
- package/dist/parser/impala/index.js +7 -2
- package/dist/parser/mysql/index.d.ts +3 -1
- package/dist/parser/mysql/index.js +7 -2
- package/dist/parser/mysql/mysqlErrorListener.d.ts +1 -4
- package/dist/parser/mysql/mysqlErrorListener.js +14 -5
- package/dist/parser/mysql/mysqlSemanticContextCollector.d.ts +9 -0
- package/dist/parser/mysql/mysqlSemanticContextCollector.js +14 -0
- package/dist/parser/postgresql/index.d.ts +3 -1
- package/dist/parser/postgresql/index.js +7 -2
- package/dist/parser/postgresql/postgreErrorListener.d.ts +1 -4
- package/dist/parser/postgresql/postgreErrorListener.js +14 -5
- package/dist/parser/postgresql/postgreSemanticContextCollector.d.ts +9 -0
- package/dist/parser/postgresql/postgreSemanticContextCollector.js +14 -0
- package/dist/parser/spark/index.d.ts +3 -1
- package/dist/parser/spark/index.js +7 -2
- package/dist/parser/spark/sparkErrorListener.d.ts +1 -4
- package/dist/parser/spark/sparkErrorListener.js +14 -5
- package/dist/parser/spark/sparkSemanticContextCollector.d.ts +9 -0
- package/dist/parser/spark/sparkSemanticContextCollector.js +14 -0
- package/dist/parser/trino/index.d.ts +3 -1
- package/dist/parser/trino/index.js +7 -2
- package/dist/parser/trino/trinoErrorListener.d.ts +1 -4
- package/dist/parser/trino/trinoErrorListener.js +14 -5
- package/dist/parser/trino/trinoSemanticContextCollector.d.ts +9 -0
- package/dist/parser/trino/trinoSemanticContextCollector.js +14 -0
- package/package.json +1 -1
|
@@ -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() {
|
|
@@ -33,11 +34,15 @@ export class FlinkSQL extends BasicSQL {
|
|
|
33
34
|
return new FlinkSqlSplitListener();
|
|
34
35
|
}
|
|
35
36
|
createErrorListener(_errorListener) {
|
|
36
|
-
|
|
37
|
+
const parserContext = this;
|
|
38
|
+
return new FlinkErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
37
39
|
}
|
|
38
40
|
createEntityCollector(input, caretTokenIndex) {
|
|
39
41
|
return new FlinkEntityCollector(input, caretTokenIndex);
|
|
40
42
|
}
|
|
43
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
44
|
+
return new FlinkSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
45
|
+
}
|
|
41
46
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
42
47
|
const originalSyntaxSuggestions = [];
|
|
43
48
|
const keywords = [];
|
|
@@ -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
|
|
@@ -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() {
|
|
@@ -33,11 +34,15 @@ export class HiveSQL extends BasicSQL {
|
|
|
33
34
|
return new HiveSqlSplitListener();
|
|
34
35
|
}
|
|
35
36
|
createErrorListener(_errorListener) {
|
|
36
|
-
|
|
37
|
+
const parserContext = this;
|
|
38
|
+
return new HiveErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
37
39
|
}
|
|
38
40
|
createEntityCollector(input, caretTokenIndex) {
|
|
39
41
|
return new HiveEntityCollector(input, caretTokenIndex);
|
|
40
42
|
}
|
|
43
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
44
|
+
return new HiveSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
45
|
+
}
|
|
41
46
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
42
47
|
const originalSyntaxSuggestions = [];
|
|
43
48
|
const keywords = [];
|
|
@@ -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
|
|
@@ -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() {
|
|
@@ -32,11 +33,15 @@ export class ImpalaSQL extends BasicSQL {
|
|
|
32
33
|
return new ImpalaSqlSplitListener();
|
|
33
34
|
}
|
|
34
35
|
createErrorListener(_errorListener) {
|
|
35
|
-
|
|
36
|
+
const parserContext = this;
|
|
37
|
+
return new ImpalaErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
36
38
|
}
|
|
37
39
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
40
|
return new ImpalaEntityCollector(input, caretTokenIndex);
|
|
39
41
|
}
|
|
42
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
43
|
+
return new ImpalaSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
44
|
+
}
|
|
40
45
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
41
46
|
const originalSyntaxSuggestions = [];
|
|
42
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() {
|
|
@@ -32,11 +33,15 @@ export class MySQL extends BasicSQL {
|
|
|
32
33
|
return new MysqlSplitListener();
|
|
33
34
|
}
|
|
34
35
|
createErrorListener(_errorListener) {
|
|
35
|
-
|
|
36
|
+
const parserContext = this;
|
|
37
|
+
return new MysqlErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
36
38
|
}
|
|
37
39
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
40
|
return new MySqlEntityCollector(input, caretTokenIndex);
|
|
39
41
|
}
|
|
42
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
43
|
+
return new MySqlSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
44
|
+
}
|
|
40
45
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
41
46
|
const originalSyntaxSuggestions = [];
|
|
42
47
|
const keywords = [];
|
|
@@ -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
|
|
@@ -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 };
|
|
@@ -2,12 +2,13 @@ import { CandidatesCollection } from 'antlr4-c3';
|
|
|
2
2
|
import { CharStream, CommonTokenStream, Token } from 'antlr4ng';
|
|
3
3
|
import { PostgreSqlLexer } from '../../lib/postgresql/PostgreSqlLexer';
|
|
4
4
|
import { PostgreSqlParser, ProgramContext } from '../../lib/postgresql/PostgreSqlParser';
|
|
5
|
-
import { Suggestions } from '../common/types';
|
|
5
|
+
import { CaretPosition, SemanticCollectOptions, Suggestions } from '../common/types';
|
|
6
6
|
import { BasicSQL } from '../common/basicSQL';
|
|
7
7
|
import { PostgreSqlEntityCollector } from './postgreEntityCollector';
|
|
8
8
|
import { PostgreSqlSplitListener } from './postgreSplitListener';
|
|
9
9
|
import { ErrorListener } from '../common/parseErrorListener';
|
|
10
10
|
import { PostgreSqlErrorListener } from './postgreErrorListener';
|
|
11
|
+
import { PostgreSemanticContextCollector } from './postgreSemanticContextCollector';
|
|
11
12
|
export { PostgreSqlEntityCollector, PostgreSqlSplitListener };
|
|
12
13
|
export declare class PostgreSQL extends BasicSQL<PostgreSqlLexer, ProgramContext, PostgreSqlParser> {
|
|
13
14
|
protected createLexerFromCharStream(charStreams: CharStream): PostgreSqlLexer;
|
|
@@ -16,5 +17,6 @@ export declare class PostgreSQL extends BasicSQL<PostgreSqlLexer, ProgramContext
|
|
|
16
17
|
protected get splitListener(): PostgreSqlSplitListener;
|
|
17
18
|
protected createErrorListener(_errorListener: ErrorListener): PostgreSqlErrorListener;
|
|
18
19
|
protected createEntityCollector(input: string, caretTokenIndex?: number): PostgreSqlEntityCollector;
|
|
20
|
+
protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): PostgreSemanticContextCollector;
|
|
19
21
|
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
20
22
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PostgreSqlLexer } from '../../lib/postgresql/PostgreSqlLexer';
|
|
2
2
|
import { PostgreSqlParser } from '../../lib/postgresql/PostgreSqlParser';
|
|
3
|
-
import { EntityContextType } from '../common/types';
|
|
3
|
+
import { EntityContextType, } from '../common/types';
|
|
4
4
|
import { BasicSQL } from '../common/basicSQL';
|
|
5
5
|
import { PostgreSqlEntityCollector } from './postgreEntityCollector';
|
|
6
6
|
import { PostgreSqlSplitListener } from './postgreSplitListener';
|
|
7
7
|
import { PostgreSqlErrorListener } from './postgreErrorListener';
|
|
8
|
+
import { PostgreSemanticContextCollector } from './postgreSemanticContextCollector';
|
|
8
9
|
export { PostgreSqlEntityCollector, PostgreSqlSplitListener };
|
|
9
10
|
export class PostgreSQL extends BasicSQL {
|
|
10
11
|
constructor() {
|
|
@@ -36,11 +37,15 @@ export class PostgreSQL extends BasicSQL {
|
|
|
36
37
|
return new PostgreSqlSplitListener();
|
|
37
38
|
}
|
|
38
39
|
createErrorListener(_errorListener) {
|
|
39
|
-
|
|
40
|
+
const parserContext = this;
|
|
41
|
+
return new PostgreSqlErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
40
42
|
}
|
|
41
43
|
createEntityCollector(input, caretTokenIndex) {
|
|
42
44
|
return new PostgreSqlEntityCollector(input, caretTokenIndex);
|
|
43
45
|
}
|
|
46
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
47
|
+
return new PostgreSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
48
|
+
}
|
|
44
49
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
45
50
|
const originalSyntaxSuggestions = [];
|
|
46
51
|
const keywords = [];
|
|
@@ -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
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PostgreSqlParserListener } from '../../lib';
|
|
2
|
+
import { SingleStmtContext } from '../../lib/postgresql/PostgreSqlParser';
|
|
3
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
4
|
+
declare class PostgreSemanticContextCollector extends SemanticContextCollector implements PostgreSqlParserListener {
|
|
5
|
+
getWhiteSpaceRuleType(): number;
|
|
6
|
+
getStatementRuleType(): number;
|
|
7
|
+
enterSingleStmt(ctx: SingleStmtContext): void;
|
|
8
|
+
}
|
|
9
|
+
export { PostgreSemanticContextCollector };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PostgreSqlParser } from '../../lib/postgresql/PostgreSqlParser';
|
|
2
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
3
|
+
class PostgreSemanticContextCollector extends SemanticContextCollector {
|
|
4
|
+
getWhiteSpaceRuleType() {
|
|
5
|
+
return PostgreSqlParser.Whitespace;
|
|
6
|
+
}
|
|
7
|
+
getStatementRuleType() {
|
|
8
|
+
return PostgreSqlParser.RULE_singleStmt;
|
|
9
|
+
}
|
|
10
|
+
enterSingleStmt(ctx) {
|
|
11
|
+
this.visitStatement(ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { PostgreSemanticContextCollector };
|
|
@@ -3,11 +3,12 @@ import { CandidatesCollection } from 'antlr4-c3';
|
|
|
3
3
|
import { SparkSqlLexer } from '../../lib/spark/SparkSqlLexer';
|
|
4
4
|
import { SparkSqlParser, ProgramContext } from '../../lib/spark/SparkSqlParser';
|
|
5
5
|
import { BasicSQL } from '../common/basicSQL';
|
|
6
|
-
import { Suggestions } from '../common/types';
|
|
6
|
+
import { Suggestions, CaretPosition, SemanticCollectOptions } from '../common/types';
|
|
7
7
|
import { SparkSqlSplitListener } from './sparkSplitListener';
|
|
8
8
|
import { SparkEntityCollector } from './sparkEntityCollector';
|
|
9
9
|
import { SparkErrorListener } from './sparkErrorListener';
|
|
10
10
|
import { ErrorListener } from '../common/parseErrorListener';
|
|
11
|
+
import { SparkSemanticContextCollector } from './sparkSemanticContextCollector';
|
|
11
12
|
export { SparkSqlSplitListener, SparkEntityCollector };
|
|
12
13
|
export declare class SparkSQL extends BasicSQL<SparkSqlLexer, ProgramContext, SparkSqlParser> {
|
|
13
14
|
protected createLexerFromCharStream(charStreams: CharStream): SparkSqlLexer;
|
|
@@ -16,5 +17,6 @@ export declare class SparkSQL extends BasicSQL<SparkSqlLexer, ProgramContext, Sp
|
|
|
16
17
|
protected get splitListener(): SparkSqlSplitListener;
|
|
17
18
|
protected createErrorListener(_errorListener: ErrorListener): SparkErrorListener;
|
|
18
19
|
protected createEntityCollector(input: string, caretTokenIndex?: number): SparkEntityCollector;
|
|
20
|
+
protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): SparkSemanticContextCollector;
|
|
19
21
|
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
20
22
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { SparkSqlLexer } from '../../lib/spark/SparkSqlLexer';
|
|
2
2
|
import { SparkSqlParser } from '../../lib/spark/SparkSqlParser';
|
|
3
3
|
import { BasicSQL } from '../common/basicSQL';
|
|
4
|
-
import { EntityContextType } from '../common/types';
|
|
4
|
+
import { EntityContextType, } from '../common/types';
|
|
5
5
|
import { SparkSqlSplitListener } from './sparkSplitListener';
|
|
6
6
|
import { SparkEntityCollector } from './sparkEntityCollector';
|
|
7
7
|
import { SparkErrorListener } from './sparkErrorListener';
|
|
8
|
+
import { SparkSemanticContextCollector } from './sparkSemanticContextCollector';
|
|
8
9
|
export { SparkSqlSplitListener, SparkEntityCollector };
|
|
9
10
|
export class SparkSQL extends BasicSQL {
|
|
10
11
|
constructor() {
|
|
@@ -32,11 +33,15 @@ export class SparkSQL extends BasicSQL {
|
|
|
32
33
|
return new SparkSqlSplitListener();
|
|
33
34
|
}
|
|
34
35
|
createErrorListener(_errorListener) {
|
|
35
|
-
|
|
36
|
+
const parserContext = this;
|
|
37
|
+
return new SparkErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
36
38
|
}
|
|
37
39
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
40
|
return new SparkEntityCollector(input, caretTokenIndex);
|
|
39
41
|
}
|
|
42
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
43
|
+
return new SparkSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
44
|
+
}
|
|
40
45
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
41
46
|
const originalSyntaxSuggestions = [];
|
|
42
47
|
const keywords = [];
|
|
@@ -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
|
}
|