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
|
@@ -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
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SparkSqlParserListener } from '../../lib';
|
|
2
|
+
import { SingleStatementContext } from '../../lib/spark/SparkSqlParser';
|
|
3
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
4
|
+
declare class SparkSemanticContextCollector extends SemanticContextCollector implements SparkSqlParserListener {
|
|
5
|
+
getWhiteSpaceRuleType(): number;
|
|
6
|
+
getStatementRuleType(): number;
|
|
7
|
+
enterSingleStatement(ctx: SingleStatementContext): void;
|
|
8
|
+
}
|
|
9
|
+
export { SparkSemanticContextCollector };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SparkSqlParser } from '../../lib/spark/SparkSqlParser';
|
|
2
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
3
|
+
class SparkSemanticContextCollector extends SemanticContextCollector {
|
|
4
|
+
getWhiteSpaceRuleType() {
|
|
5
|
+
return SparkSqlParser.WS;
|
|
6
|
+
}
|
|
7
|
+
getStatementRuleType() {
|
|
8
|
+
return SparkSqlParser.RULE_singleStatement;
|
|
9
|
+
}
|
|
10
|
+
enterSingleStatement(ctx) {
|
|
11
|
+
this.visitStatement(ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { SparkSemanticContextCollector };
|
|
@@ -3,11 +3,12 @@ import { CandidatesCollection } from 'antlr4-c3';
|
|
|
3
3
|
import { TrinoSqlLexer } from '../../lib/trino/TrinoSqlLexer';
|
|
4
4
|
import { TrinoSqlParser, ProgramContext } from '../../lib/trino/TrinoSqlParser';
|
|
5
5
|
import { BasicSQL } from '../common/basicSQL';
|
|
6
|
-
import { Suggestions } from '../common/types';
|
|
6
|
+
import { Suggestions, CaretPosition, SemanticCollectOptions } from '../common/types';
|
|
7
7
|
import { TrinoSqlSplitListener } from './trinoSplitListener';
|
|
8
8
|
import { TrinoEntityCollector } from './trinoEntityCollector';
|
|
9
9
|
import { ErrorListener } from '../common/parseErrorListener';
|
|
10
10
|
import { TrinoErrorListener } from './trinoErrorListener';
|
|
11
|
+
import { TrinoSemanticContextCollector } from './trinoSemanticContextCollector';
|
|
11
12
|
export { TrinoSqlSplitListener, TrinoEntityCollector };
|
|
12
13
|
export declare class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, TrinoSqlParser> {
|
|
13
14
|
protected createLexerFromCharStream(charStreams: CharStream): TrinoSqlLexer;
|
|
@@ -15,6 +16,7 @@ export declare class TrinoSQL extends BasicSQL<TrinoSqlLexer, ProgramContext, Tr
|
|
|
15
16
|
protected get splitListener(): TrinoSqlSplitListener;
|
|
16
17
|
protected createErrorListener(_errorListener: ErrorListener): TrinoErrorListener;
|
|
17
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): TrinoEntityCollector;
|
|
19
|
+
protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): TrinoSemanticContextCollector;
|
|
18
20
|
protected preferredRules: Set<number>;
|
|
19
21
|
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number, tokenIndexOffset: number): Suggestions<Token>;
|
|
20
22
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { TrinoSqlLexer } from '../../lib/trino/TrinoSqlLexer';
|
|
2
2
|
import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
|
|
3
3
|
import { BasicSQL } from '../common/basicSQL';
|
|
4
|
-
import { EntityContextType } from '../common/types';
|
|
4
|
+
import { EntityContextType, } from '../common/types';
|
|
5
5
|
import { TrinoSqlSplitListener } from './trinoSplitListener';
|
|
6
6
|
import { TrinoEntityCollector } from './trinoEntityCollector';
|
|
7
7
|
import { TrinoErrorListener } from './trinoErrorListener';
|
|
8
|
+
import { TrinoSemanticContextCollector } from './trinoSemanticContextCollector';
|
|
8
9
|
export { TrinoSqlSplitListener, TrinoEntityCollector };
|
|
9
10
|
export class TrinoSQL extends BasicSQL {
|
|
10
11
|
constructor() {
|
|
@@ -34,11 +35,15 @@ export class TrinoSQL extends BasicSQL {
|
|
|
34
35
|
return new TrinoSqlSplitListener();
|
|
35
36
|
}
|
|
36
37
|
createErrorListener(_errorListener) {
|
|
37
|
-
|
|
38
|
+
const parserContext = this;
|
|
39
|
+
return new TrinoErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
38
40
|
}
|
|
39
41
|
createEntityCollector(input, caretTokenIndex) {
|
|
40
42
|
return new TrinoEntityCollector(input, caretTokenIndex);
|
|
41
43
|
}
|
|
44
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
45
|
+
return new TrinoSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
46
|
+
}
|
|
42
47
|
processCandidates(candidates, allTokens, caretTokenIndex, tokenIndexOffset) {
|
|
43
48
|
const originalSyntaxSuggestions = [];
|
|
44
49
|
const keywords = [];
|
|
@@ -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
|
}
|
|
@@ -2,8 +2,8 @@ import { CodeCompletionCore } from 'antlr4-c3';
|
|
|
2
2
|
import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
|
|
3
3
|
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
4
4
|
export class TrinoErrorListener extends ParseErrorListener {
|
|
5
|
-
constructor(
|
|
6
|
-
super(
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
7
|
this.objectNames = new Map([
|
|
8
8
|
[TrinoSqlParser.RULE_catalogRef, 'catalog'],
|
|
9
9
|
[TrinoSqlParser.RULE_catalogNameCreate, 'catalog'],
|
|
@@ -17,18 +17,27 @@ export class TrinoErrorListener extends ParseErrorListener {
|
|
|
17
17
|
[TrinoSqlParser.RULE_columnRef, 'column'],
|
|
18
18
|
[TrinoSqlParser.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 { TrinoSqlListener } from '../../lib';
|
|
2
|
+
import { StatementsContext } from '../../lib/trino/TrinoSqlParser';
|
|
3
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
4
|
+
declare class TrinoSemanticContextCollector extends SemanticContextCollector implements TrinoSqlListener {
|
|
5
|
+
getWhiteSpaceRuleType(): number;
|
|
6
|
+
getStatementRuleType(): number;
|
|
7
|
+
enterStatements(ctx: StatementsContext): void;
|
|
8
|
+
}
|
|
9
|
+
export { TrinoSemanticContextCollector };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TrinoSqlParser } from '../../lib/trino/TrinoSqlParser';
|
|
2
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
3
|
+
class TrinoSemanticContextCollector extends SemanticContextCollector {
|
|
4
|
+
getWhiteSpaceRuleType() {
|
|
5
|
+
return TrinoSqlParser.WS;
|
|
6
|
+
}
|
|
7
|
+
getStatementRuleType() {
|
|
8
|
+
return TrinoSqlParser.RULE_statements;
|
|
9
|
+
}
|
|
10
|
+
enterStatements(ctx) {
|
|
11
|
+
this.visitStatement(ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { TrinoSemanticContextCollector };
|