dt-sql-parser 4.0.2 → 4.1.0-beta.1
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 +6 -1
- package/dist/lib/flink/FlinkSqlLexer.js +1 -2
- package/dist/lib/flink/FlinkSqlParser.d.ts +175 -174
- package/dist/lib/flink/FlinkSqlParser.js +2315 -2388
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +5 -16
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +3 -10
- package/dist/lib/hive/HiveSqlLexer.js +1 -2
- package/dist/lib/hive/HiveSqlParser.d.ts +3 -1
- package/dist/lib/hive/HiveSqlParser.js +8 -9
- package/dist/lib/impala/ImpalaSqlLexer.js +1 -2
- package/dist/lib/impala/ImpalaSqlParser.d.ts +123 -107
- package/dist/lib/impala/ImpalaSqlParser.js +3223 -3155
- package/dist/lib/impala/ImpalaSqlParserListener.d.ts +22 -0
- package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +14 -0
- package/dist/lib/mysql/MySqlLexer.js +1 -2
- package/dist/lib/mysql/MySqlParser.d.ts +469 -422
- package/dist/lib/mysql/MySqlParser.js +11460 -10509
- package/dist/lib/mysql/MySqlParserListener.d.ts +33 -11
- package/dist/lib/mysql/MySqlParserVisitor.d.ts +21 -7
- package/dist/lib/postgresql/PostgreSqlLexer.js +1 -2
- package/dist/lib/postgresql/PostgreSqlParser.d.ts +2025 -6265
- package/dist/lib/postgresql/PostgreSqlParser.js +60092 -88368
- package/dist/lib/postgresql/PostgreSqlParserListener.d.ts +1688 -6083
- package/dist/lib/postgresql/PostgreSqlParserVisitor.d.ts +712 -3511
- package/dist/lib/spark/SparkSqlLexer.js +1 -2
- package/dist/lib/spark/SparkSqlParser.d.ts +16 -13
- package/dist/lib/spark/SparkSqlParser.js +50 -51
- package/dist/lib/spark/SparkSqlParserListener.d.ts +10 -10
- package/dist/lib/spark/SparkSqlParserVisitor.d.ts +6 -6
- package/dist/lib/trino/TrinoSqlLexer.d.ts +323 -260
- package/dist/lib/trino/TrinoSqlLexer.js +1610 -1264
- package/dist/lib/trino/TrinoSqlListener.d.ts +1311 -200
- package/dist/lib/trino/TrinoSqlParser.d.ts +1908 -562
- package/dist/lib/trino/TrinoSqlParser.js +22629 -13412
- package/dist/lib/trino/TrinoSqlVisitor.d.ts +761 -69
- package/dist/locale/locale.d.ts +41 -0
- package/dist/locale/locale.js +43 -0
- package/dist/parser/common/basicSQL.d.ts +9 -4
- package/dist/parser/common/basicSQL.js +64 -21
- package/dist/parser/common/entityCollector.d.ts +60 -12
- package/dist/parser/common/entityCollector.js +141 -17
- package/dist/parser/common/parseErrorListener.d.ts +6 -3
- package/dist/parser/common/parseErrorListener.js +83 -2
- package/dist/parser/common/textAndWord.d.ts +6 -9
- package/dist/parser/common/textAndWord.js +9 -20
- package/dist/parser/common/transform.d.ts +8 -0
- package/dist/parser/common/transform.js +11 -0
- package/dist/parser/common/types.d.ts +1 -0
- package/dist/parser/flink/flinkEntityCollector.js +40 -6
- package/dist/parser/flink/flinkErrorListener.d.ts +9 -0
- package/dist/parser/flink/flinkErrorListener.js +67 -0
- package/dist/parser/flink/index.d.ts +4 -1
- package/dist/parser/flink/index.js +16 -12
- package/dist/parser/hive/hiveEntityCollector.js +40 -6
- package/dist/parser/hive/hiveErrorListener.d.ts +9 -0
- package/dist/parser/hive/hiveErrorListener.js +65 -0
- package/dist/parser/hive/index.d.ts +4 -1
- package/dist/parser/hive/index.js +16 -12
- package/dist/parser/impala/ImpalaErrorListener.d.ts +9 -0
- package/dist/parser/impala/ImpalaErrorListener.js +63 -0
- package/dist/parser/impala/impalaEntityCollector.js +51 -6
- package/dist/parser/impala/index.d.ts +4 -1
- package/dist/parser/impala/index.js +7 -3
- package/dist/parser/mysql/index.d.ts +4 -1
- package/dist/parser/mysql/index.js +7 -3
- package/dist/parser/mysql/mysqlEntityCollector.d.ts +3 -1
- package/dist/parser/mysql/mysqlEntityCollector.js +40 -5
- package/dist/parser/mysql/mysqlErrorListener.d.ts +9 -0
- package/dist/parser/mysql/mysqlErrorListener.js +63 -0
- package/dist/parser/postgresql/index.d.ts +4 -1
- package/dist/parser/postgresql/index.js +20 -16
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +5 -1
- package/dist/parser/postgresql/postgreEntityCollector.js +44 -4
- package/dist/parser/postgresql/postgreErrorListener.d.ts +9 -0
- package/dist/parser/postgresql/postgreErrorListener.js +71 -0
- package/dist/parser/spark/index.d.ts +4 -1
- package/dist/parser/spark/index.js +7 -3
- package/dist/parser/spark/sparkEntityCollector.d.ts +1 -1
- package/dist/parser/spark/sparkEntityCollector.js +43 -6
- package/dist/parser/spark/sparkErrorListener.d.ts +9 -0
- package/dist/parser/spark/sparkErrorListener.js +63 -0
- package/dist/parser/trino/index.d.ts +4 -1
- package/dist/parser/trino/index.js +26 -13
- package/dist/parser/trino/trinoEntityCollector.d.ts +6 -4
- package/dist/parser/trino/trinoEntityCollector.js +44 -9
- package/dist/parser/trino/trinoErrorListener.d.ts +9 -0
- package/dist/parser/trino/trinoErrorListener.js +65 -0
- package/package.json +35 -11
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CodeCompletionCore } from 'antlr4-c3';
|
|
2
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
|
+
import { ImpalaSqlParser } from '../../lib/impala/ImpalaSqlParser';
|
|
4
|
+
export class ImpalaErrorListener extends ParseErrorListener {
|
|
5
|
+
constructor(errorListener, preferredRules, locale) {
|
|
6
|
+
super(errorListener, locale);
|
|
7
|
+
this.objectNames = new Map([
|
|
8
|
+
[ImpalaSqlParser.RULE_databaseNamePath, 'database'],
|
|
9
|
+
[ImpalaSqlParser.RULE_databaseNameCreate, 'database'],
|
|
10
|
+
[ImpalaSqlParser.RULE_tableNamePath, 'table'],
|
|
11
|
+
[ImpalaSqlParser.RULE_tableNameCreate, 'table'],
|
|
12
|
+
[ImpalaSqlParser.RULE_viewNamePath, 'view'],
|
|
13
|
+
[ImpalaSqlParser.RULE_viewNameCreate, 'view'],
|
|
14
|
+
[ImpalaSqlParser.RULE_functionNamePath, 'function'],
|
|
15
|
+
[ImpalaSqlParser.RULE_functionNameCreate, 'function'],
|
|
16
|
+
[ImpalaSqlParser.RULE_columnNamePath, 'column'],
|
|
17
|
+
[ImpalaSqlParser.RULE_columnNamePathCreate, 'column'],
|
|
18
|
+
]);
|
|
19
|
+
this.preferredRules = preferredRules;
|
|
20
|
+
}
|
|
21
|
+
getExpectedText(parser, token) {
|
|
22
|
+
var _a;
|
|
23
|
+
let expectedText = '';
|
|
24
|
+
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
25
|
+
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
26
|
+
currentContext = currentContext.parent;
|
|
27
|
+
}
|
|
28
|
+
const core = new CodeCompletionCore(parser);
|
|
29
|
+
core.preferredRules = this.preferredRules;
|
|
30
|
+
const candidates = core.collectCandidates(token.tokenIndex, currentContext);
|
|
31
|
+
if (candidates.rules.size) {
|
|
32
|
+
const result = [];
|
|
33
|
+
// get expectedText as collect rules first
|
|
34
|
+
for (const candidate of candidates.rules) {
|
|
35
|
+
const [ruleType] = candidate;
|
|
36
|
+
const name = this.objectNames.get(ruleType);
|
|
37
|
+
switch (ruleType) {
|
|
38
|
+
case ImpalaSqlParser.RULE_databaseNamePath:
|
|
39
|
+
case ImpalaSqlParser.RULE_tableNamePath:
|
|
40
|
+
case ImpalaSqlParser.RULE_functionNamePath:
|
|
41
|
+
case ImpalaSqlParser.RULE_viewNamePath:
|
|
42
|
+
case ImpalaSqlParser.RULE_columnNamePath: {
|
|
43
|
+
result.push(`{existing}${name}`);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case ImpalaSqlParser.RULE_databaseNameCreate:
|
|
47
|
+
case ImpalaSqlParser.RULE_tableNameCreate:
|
|
48
|
+
case ImpalaSqlParser.RULE_functionNameCreate:
|
|
49
|
+
case ImpalaSqlParser.RULE_viewNameCreate:
|
|
50
|
+
case ImpalaSqlParser.RULE_columnNamePathCreate: {
|
|
51
|
+
result.push(`{new}${name}`);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
expectedText = result.join(`{or}`);
|
|
57
|
+
}
|
|
58
|
+
if (candidates.tokens.size) {
|
|
59
|
+
expectedText += expectedText ? '{orKeyword}' : '{keyword}';
|
|
60
|
+
}
|
|
61
|
+
return expectedText;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,18 +1,58 @@
|
|
|
1
|
+
import { ColumnDefinitionContext, CreateKuduTableAsSelectContext, CreateSchemaContext, CreateTableSelectContext, CreateViewContext, KuduTableElementContext, SampledRelationContext, ViewColumnItemContext, } from '../../lib/impala/ImpalaSqlParser';
|
|
2
|
+
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
|
|
1
3
|
import { EntityContextType } from '../common/types';
|
|
2
|
-
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
4
|
export class ImpalaEntityCollector extends EntityCollector {
|
|
4
5
|
/** ===== Entity begin */
|
|
5
6
|
exitTableNameCreate(ctx) {
|
|
6
|
-
this.pushEntity(ctx, EntityContextType.TABLE_CREATE
|
|
7
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
|
|
8
|
+
{
|
|
9
|
+
attrName: AttrName.comment,
|
|
10
|
+
endContextList: [
|
|
11
|
+
CreateTableSelectContext.name,
|
|
12
|
+
CreateKuduTableAsSelectContext.name,
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
]);
|
|
7
16
|
}
|
|
8
17
|
exitTableNamePath(ctx) {
|
|
9
|
-
|
|
18
|
+
var _a;
|
|
19
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
20
|
+
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
|
|
21
|
+
? [
|
|
22
|
+
{
|
|
23
|
+
attrName: AttrName.alias,
|
|
24
|
+
endContextList: [SampledRelationContext.name],
|
|
25
|
+
},
|
|
26
|
+
]
|
|
27
|
+
: undefined);
|
|
10
28
|
}
|
|
11
29
|
exitColumnNamePathCreate(ctx) {
|
|
12
|
-
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE
|
|
30
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
31
|
+
{
|
|
32
|
+
attrName: AttrName.comment,
|
|
33
|
+
endContextList: [
|
|
34
|
+
ColumnDefinitionContext.name,
|
|
35
|
+
KuduTableElementContext.name,
|
|
36
|
+
ViewColumnItemContext.name,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
attrName: AttrName.colType,
|
|
41
|
+
endContextList: [
|
|
42
|
+
ColumnDefinitionContext.name,
|
|
43
|
+
KuduTableElementContext.name,
|
|
44
|
+
ViewColumnItemContext.name,
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
13
48
|
}
|
|
14
49
|
exitViewNameCreate(ctx) {
|
|
15
|
-
this.pushEntity(ctx, EntityContextType.VIEW_CREATE
|
|
50
|
+
this.pushEntity(ctx, EntityContextType.VIEW_CREATE, [
|
|
51
|
+
{
|
|
52
|
+
attrName: AttrName.comment,
|
|
53
|
+
endContextList: [CreateViewContext.name],
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
16
56
|
}
|
|
17
57
|
exitViewNamePath(ctx) {
|
|
18
58
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
@@ -21,7 +61,12 @@ export class ImpalaEntityCollector extends EntityCollector {
|
|
|
21
61
|
this.pushEntity(ctx, EntityContextType.DATABASE);
|
|
22
62
|
}
|
|
23
63
|
exitDatabaseNameCreate(ctx) {
|
|
24
|
-
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE
|
|
64
|
+
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE, [
|
|
65
|
+
{
|
|
66
|
+
attrName: AttrName.comment,
|
|
67
|
+
endContextList: [CreateSchemaContext.name],
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
25
70
|
}
|
|
26
71
|
exitFunctionNameCreate(ctx) {
|
|
27
72
|
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE);
|
|
@@ -6,12 +6,15 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
6
6
|
import { Suggestions } from '../common/types';
|
|
7
7
|
import { ImpalaSqlSplitListener } from './impalaSplitListener';
|
|
8
8
|
import { ImpalaEntityCollector } from './impalaEntityCollector';
|
|
9
|
+
import { ErrorListener } from '../common/parseErrorListener';
|
|
10
|
+
import { ImpalaErrorListener } from './ImpalaErrorListener';
|
|
9
11
|
export { ImpalaEntityCollector, ImpalaSqlSplitListener };
|
|
10
12
|
export declare class ImpalaSQL extends BasicSQL<ImpalaSqlLexer, ProgramContext, ImpalaSqlParser> {
|
|
11
13
|
protected createLexerFromCharStream(charStreams: CharStream): ImpalaSqlLexer;
|
|
12
14
|
protected createParserFromTokenStream(tokenStream: CommonTokenStream): ImpalaSqlParser;
|
|
13
15
|
protected preferredRules: Set<number>;
|
|
14
16
|
protected get splitListener(): ImpalaSqlSplitListener;
|
|
17
|
+
protected createErrorListener(_errorListener: ErrorListener): ImpalaErrorListener;
|
|
15
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): ImpalaEntityCollector;
|
|
16
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number
|
|
19
|
+
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number): Suggestions<Token>;
|
|
17
20
|
}
|
|
@@ -4,6 +4,7 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
4
4
|
import { EntityContextType } from '../common/types';
|
|
5
5
|
import { ImpalaSqlSplitListener } from './impalaSplitListener';
|
|
6
6
|
import { ImpalaEntityCollector } from './impalaEntityCollector';
|
|
7
|
+
import { ImpalaErrorListener } from './ImpalaErrorListener';
|
|
7
8
|
export { ImpalaEntityCollector, ImpalaSqlSplitListener };
|
|
8
9
|
export class ImpalaSQL extends BasicSQL {
|
|
9
10
|
constructor() {
|
|
@@ -30,16 +31,19 @@ export class ImpalaSQL extends BasicSQL {
|
|
|
30
31
|
get splitListener() {
|
|
31
32
|
return new ImpalaSqlSplitListener();
|
|
32
33
|
}
|
|
34
|
+
createErrorListener(_errorListener) {
|
|
35
|
+
return new ImpalaErrorListener(_errorListener, this.preferredRules, this.locale);
|
|
36
|
+
}
|
|
33
37
|
createEntityCollector(input, caretTokenIndex) {
|
|
34
38
|
return new ImpalaEntityCollector(input, caretTokenIndex);
|
|
35
39
|
}
|
|
36
|
-
processCandidates(candidates, allTokens, caretTokenIndex
|
|
40
|
+
processCandidates(candidates, allTokens, caretTokenIndex) {
|
|
37
41
|
const originalSyntaxSuggestions = [];
|
|
38
42
|
const keywords = [];
|
|
39
43
|
for (let candidate of candidates.rules) {
|
|
40
44
|
const [ruleType, candidateRule] = candidate;
|
|
41
|
-
const startTokenIndex = candidateRule.startTokenIndex
|
|
42
|
-
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex +
|
|
45
|
+
const startTokenIndex = candidateRule.startTokenIndex;
|
|
46
|
+
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex + 1);
|
|
43
47
|
let syntaxContextType = void 0;
|
|
44
48
|
switch (ruleType) {
|
|
45
49
|
case ImpalaSqlParser.RULE_functionNameCreate: {
|
|
@@ -6,12 +6,15 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
6
6
|
import { Suggestions } from '../common/types';
|
|
7
7
|
import { MysqlSplitListener } from './mysqlSplitListener';
|
|
8
8
|
import { MySqlEntityCollector } from './mysqlEntityCollector';
|
|
9
|
+
import { MysqlErrorListener } from './mysqlErrorListener';
|
|
10
|
+
import { ErrorListener } from '../common/parseErrorListener';
|
|
9
11
|
export { MySqlEntityCollector, MysqlSplitListener };
|
|
10
12
|
export declare class MySQL extends BasicSQL<MySqlLexer, ProgramContext, MySqlParser> {
|
|
11
13
|
protected createLexerFromCharStream(charStreams: CharStream): MySqlLexer;
|
|
12
14
|
protected createParserFromTokenStream(tokenStream: CommonTokenStream): MySqlParser;
|
|
13
15
|
protected preferredRules: Set<number>;
|
|
14
16
|
protected get splitListener(): MysqlSplitListener;
|
|
17
|
+
protected createErrorListener(_errorListener: ErrorListener): MysqlErrorListener;
|
|
15
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): MySqlEntityCollector;
|
|
16
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number
|
|
19
|
+
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number): Suggestions<Token>;
|
|
17
20
|
}
|
|
@@ -4,6 +4,7 @@ import { BasicSQL } from '../common/basicSQL';
|
|
|
4
4
|
import { EntityContextType } from '../common/types';
|
|
5
5
|
import { MysqlSplitListener } from './mysqlSplitListener';
|
|
6
6
|
import { MySqlEntityCollector } from './mysqlEntityCollector';
|
|
7
|
+
import { MysqlErrorListener } from './mysqlErrorListener';
|
|
7
8
|
export { MySqlEntityCollector, MysqlSplitListener };
|
|
8
9
|
export class MySQL extends BasicSQL {
|
|
9
10
|
constructor() {
|
|
@@ -30,16 +31,19 @@ export class MySQL extends BasicSQL {
|
|
|
30
31
|
get splitListener() {
|
|
31
32
|
return new MysqlSplitListener();
|
|
32
33
|
}
|
|
34
|
+
createErrorListener(_errorListener) {
|
|
35
|
+
return new MysqlErrorListener(_errorListener, this.preferredRules, this.locale);
|
|
36
|
+
}
|
|
33
37
|
createEntityCollector(input, caretTokenIndex) {
|
|
34
38
|
return new MySqlEntityCollector(input, caretTokenIndex);
|
|
35
39
|
}
|
|
36
|
-
processCandidates(candidates, allTokens, caretTokenIndex
|
|
40
|
+
processCandidates(candidates, allTokens, caretTokenIndex) {
|
|
37
41
|
const originalSyntaxSuggestions = [];
|
|
38
42
|
const keywords = [];
|
|
39
43
|
for (const candidate of candidates.rules) {
|
|
40
44
|
const [ruleType, candidateRule] = candidate;
|
|
41
|
-
const startTokenIndex = candidateRule.startTokenIndex
|
|
42
|
-
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex +
|
|
45
|
+
const startTokenIndex = candidateRule.startTokenIndex;
|
|
46
|
+
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex + 1);
|
|
43
47
|
let syntaxContextType = void 0;
|
|
44
48
|
switch (ruleType) {
|
|
45
49
|
case MySqlParser.RULE_databaseName: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ColumnCreateTableContext, ColumnNameCreateContext, CopyCreateTableContext, CreateDatabaseContext, CreateFunctionContext, CreateFunctionLoadableContext, CreateViewContext, DatabaseNameContext, DatabaseNameCreateContext, FunctionNameCreateContext, InsertStatementContext, QueryCreateTableContext, SelectStatementContext, SingleStatementContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext } from '../../lib/mysql/MySqlParser';
|
|
2
2
|
import type { MySqlParserListener } from '../../lib/mysql/MySqlParserListener';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class MySqlEntityCollector extends EntityCollector implements MySqlParserListener {
|
|
@@ -34,4 +34,6 @@ export declare class MySqlEntityCollector extends EntityCollector implements MyS
|
|
|
34
34
|
exitCreateDatabase(ctx: CreateDatabaseContext): void;
|
|
35
35
|
enterCreateFunction(ctx: CreateFunctionContext): void;
|
|
36
36
|
exitCreateFunction(ctx: CreateFunctionContext): void;
|
|
37
|
+
enterCreateFunctionLoadable(ctx: CreateFunctionLoadableContext): void;
|
|
38
|
+
exitCreateFunctionLoadable(ctx: CreateFunctionLoadableContext): void;
|
|
37
39
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ColumnCreateTableContext, CreateDefinitionContext, CreateFunctionContext, TableSourceContext, } from '../../lib/mysql/MySqlParser';
|
|
2
|
+
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
|
|
1
3
|
import { EntityContextType } from '../common/types';
|
|
2
|
-
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
4
|
export class MySqlEntityCollector extends EntityCollector {
|
|
4
5
|
/** ====== Entity Begin */
|
|
5
6
|
exitDatabaseName(ctx) {
|
|
@@ -9,10 +10,24 @@ export class MySqlEntityCollector extends EntityCollector {
|
|
|
9
10
|
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE);
|
|
10
11
|
}
|
|
11
12
|
exitTableName(ctx) {
|
|
12
|
-
|
|
13
|
+
var _a;
|
|
14
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
15
|
+
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
|
|
16
|
+
? [
|
|
17
|
+
{
|
|
18
|
+
attrName: AttrName.alias,
|
|
19
|
+
endContextList: [TableSourceContext.name],
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
: undefined);
|
|
13
23
|
}
|
|
14
24
|
exitTableNameCreate(ctx) {
|
|
15
|
-
this.pushEntity(ctx, EntityContextType.TABLE_CREATE
|
|
25
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
|
|
26
|
+
{
|
|
27
|
+
attrName: AttrName.comment,
|
|
28
|
+
endContextList: [ColumnCreateTableContext.name],
|
|
29
|
+
},
|
|
30
|
+
]);
|
|
16
31
|
}
|
|
17
32
|
exitViewName(ctx) {
|
|
18
33
|
this.pushEntity(ctx, EntityContextType.VIEW);
|
|
@@ -21,10 +36,24 @@ export class MySqlEntityCollector extends EntityCollector {
|
|
|
21
36
|
this.pushEntity(ctx, EntityContextType.VIEW_CREATE);
|
|
22
37
|
}
|
|
23
38
|
exitFunctionNameCreate(ctx) {
|
|
24
|
-
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE
|
|
39
|
+
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE, [
|
|
40
|
+
{
|
|
41
|
+
attrName: AttrName.comment,
|
|
42
|
+
endContextList: [CreateFunctionContext.name],
|
|
43
|
+
},
|
|
44
|
+
]);
|
|
25
45
|
}
|
|
26
46
|
exitColumnNameCreate(ctx) {
|
|
27
|
-
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE
|
|
47
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
48
|
+
{
|
|
49
|
+
attrName: AttrName.comment,
|
|
50
|
+
endContextList: [CreateDefinitionContext.name],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
attrName: AttrName.colType,
|
|
54
|
+
endContextList: [CreateDefinitionContext.name],
|
|
55
|
+
},
|
|
56
|
+
]);
|
|
28
57
|
}
|
|
29
58
|
/** ===== Statement begin */
|
|
30
59
|
enterSingleStatement(ctx) {
|
|
@@ -93,4 +122,10 @@ export class MySqlEntityCollector extends EntityCollector {
|
|
|
93
122
|
exitCreateFunction(ctx) {
|
|
94
123
|
this.popStmt();
|
|
95
124
|
}
|
|
125
|
+
enterCreateFunctionLoadable(ctx) {
|
|
126
|
+
this.pushStmt(ctx, StmtContextType.CREATE_FUNCTION_STMT);
|
|
127
|
+
}
|
|
128
|
+
exitCreateFunctionLoadable(ctx) {
|
|
129
|
+
this.popStmt();
|
|
130
|
+
}
|
|
96
131
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
|
|
2
|
+
import { Parser, Token } from 'antlr4ng';
|
|
3
|
+
import { LOCALE_TYPE } from '../common/types';
|
|
4
|
+
export declare class MysqlErrorListener extends ParseErrorListener {
|
|
5
|
+
private preferredRules;
|
|
6
|
+
private objectNames;
|
|
7
|
+
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
|
+
getExpectedText(parser: Parser, token: Token): string;
|
|
9
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CodeCompletionCore } from 'antlr4-c3';
|
|
2
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
3
|
+
import { MySqlParser } from '../../lib/mysql/MySqlParser';
|
|
4
|
+
export class MysqlErrorListener extends ParseErrorListener {
|
|
5
|
+
constructor(errorListener, preferredRules, locale) {
|
|
6
|
+
super(errorListener, locale);
|
|
7
|
+
this.objectNames = new Map([
|
|
8
|
+
[MySqlParser.RULE_databaseName, 'database'],
|
|
9
|
+
[MySqlParser.RULE_databaseNameCreate, 'database'],
|
|
10
|
+
[MySqlParser.RULE_tableName, 'table'],
|
|
11
|
+
[MySqlParser.RULE_tableNameCreate, 'table'],
|
|
12
|
+
[MySqlParser.RULE_viewName, 'view'],
|
|
13
|
+
[MySqlParser.RULE_viewNameCreate, 'view'],
|
|
14
|
+
[MySqlParser.RULE_functionName, 'function'],
|
|
15
|
+
[MySqlParser.RULE_functionNameCreate, 'function'],
|
|
16
|
+
[MySqlParser.RULE_columnName, 'column'],
|
|
17
|
+
[MySqlParser.RULE_columnNameCreate, 'column'],
|
|
18
|
+
]);
|
|
19
|
+
this.preferredRules = preferredRules;
|
|
20
|
+
}
|
|
21
|
+
getExpectedText(parser, token) {
|
|
22
|
+
var _a;
|
|
23
|
+
let expectedText = '';
|
|
24
|
+
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
25
|
+
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
26
|
+
currentContext = currentContext.parent;
|
|
27
|
+
}
|
|
28
|
+
const core = new CodeCompletionCore(parser);
|
|
29
|
+
core.preferredRules = this.preferredRules;
|
|
30
|
+
const candidates = core.collectCandidates(token.tokenIndex, currentContext);
|
|
31
|
+
if (candidates.rules.size) {
|
|
32
|
+
const result = [];
|
|
33
|
+
// get expectedText as collect rules first
|
|
34
|
+
for (const candidate of candidates.rules) {
|
|
35
|
+
const [ruleType] = candidate;
|
|
36
|
+
const name = this.objectNames.get(ruleType);
|
|
37
|
+
switch (ruleType) {
|
|
38
|
+
case MySqlParser.RULE_databaseName:
|
|
39
|
+
case MySqlParser.RULE_tableName:
|
|
40
|
+
case MySqlParser.RULE_functionName:
|
|
41
|
+
case MySqlParser.RULE_viewName:
|
|
42
|
+
case MySqlParser.RULE_columnName: {
|
|
43
|
+
result.push(`{existing}${name}`);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case MySqlParser.RULE_databaseNameCreate:
|
|
47
|
+
case MySqlParser.RULE_tableNameCreate:
|
|
48
|
+
case MySqlParser.RULE_functionNameCreate:
|
|
49
|
+
case MySqlParser.RULE_viewNameCreate:
|
|
50
|
+
case MySqlParser.RULE_columnNameCreate: {
|
|
51
|
+
result.push(`{new}${name}`);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
expectedText = result.join(`{or}`);
|
|
57
|
+
}
|
|
58
|
+
if (candidates.tokens.size) {
|
|
59
|
+
expectedText += expectedText ? '{orKeyword}' : '{keyword}';
|
|
60
|
+
}
|
|
61
|
+
return expectedText;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -6,12 +6,15 @@ import { Suggestions } from '../common/types';
|
|
|
6
6
|
import { BasicSQL } from '../common/basicSQL';
|
|
7
7
|
import { PostgreSqlEntityCollector } from './postgreEntityCollector';
|
|
8
8
|
import { PostgreSqlSplitListener } from './postgreSplitListener';
|
|
9
|
+
import { ErrorListener } from '../common/parseErrorListener';
|
|
10
|
+
import { PostgreSqlErrorListener } from './postgreErrorListener';
|
|
9
11
|
export { PostgreSqlEntityCollector, PostgreSqlSplitListener };
|
|
10
12
|
export declare class PostgreSQL extends BasicSQL<PostgreSqlLexer, ProgramContext, PostgreSqlParser> {
|
|
11
13
|
protected createLexerFromCharStream(charStreams: CharStream): PostgreSqlLexer;
|
|
12
14
|
protected createParserFromTokenStream(tokenStream: CommonTokenStream): PostgreSqlParser;
|
|
13
15
|
protected preferredRules: Set<number>;
|
|
14
16
|
protected get splitListener(): PostgreSqlSplitListener;
|
|
17
|
+
protected createErrorListener(_errorListener: ErrorListener): PostgreSqlErrorListener;
|
|
15
18
|
protected createEntityCollector(input: string, caretTokenIndex?: number): PostgreSqlEntityCollector;
|
|
16
|
-
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number
|
|
19
|
+
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number): Suggestions<Token>;
|
|
17
20
|
}
|
|
@@ -4,24 +4,25 @@ 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
|
+
import { PostgreSqlErrorListener } from './postgreErrorListener';
|
|
7
8
|
export { PostgreSqlEntityCollector, PostgreSqlSplitListener };
|
|
8
9
|
export class PostgreSQL extends BasicSQL {
|
|
9
10
|
constructor() {
|
|
10
11
|
super(...arguments);
|
|
11
12
|
this.preferredRules = new Set([
|
|
12
|
-
PostgreSqlParser.RULE_table_name_create,
|
|
13
|
-
PostgreSqlParser.RULE_table_name,
|
|
14
|
-
PostgreSqlParser.RULE_function_name,
|
|
15
|
-
PostgreSqlParser.RULE_function_name_create,
|
|
16
|
-
PostgreSqlParser.RULE_schema_name_create,
|
|
17
|
-
PostgreSqlParser.RULE_schema_name,
|
|
18
|
-
PostgreSqlParser.RULE_view_name_create,
|
|
19
|
-
PostgreSqlParser.RULE_view_name,
|
|
20
|
-
PostgreSqlParser.RULE_database_name_create,
|
|
21
|
-
PostgreSqlParser.RULE_database_name,
|
|
22
|
-
PostgreSqlParser.RULE_procedure_name_create,
|
|
23
|
-
PostgreSqlParser.RULE_procedure_name,
|
|
24
|
-
PostgreSqlParser.RULE_column_name_create,
|
|
13
|
+
PostgreSqlParser.RULE_table_name_create, // table name
|
|
14
|
+
PostgreSqlParser.RULE_table_name, // table name that will be created
|
|
15
|
+
PostgreSqlParser.RULE_function_name, // function name
|
|
16
|
+
PostgreSqlParser.RULE_function_name_create, // function name that will be created
|
|
17
|
+
PostgreSqlParser.RULE_schema_name_create, // schema name that will be created
|
|
18
|
+
PostgreSqlParser.RULE_schema_name, // schema name
|
|
19
|
+
PostgreSqlParser.RULE_view_name_create, // view name that will be created
|
|
20
|
+
PostgreSqlParser.RULE_view_name, // view name
|
|
21
|
+
PostgreSqlParser.RULE_database_name_create, // database name that will be created
|
|
22
|
+
PostgreSqlParser.RULE_database_name, // database name
|
|
23
|
+
PostgreSqlParser.RULE_procedure_name_create, // procedure name that will be created
|
|
24
|
+
PostgreSqlParser.RULE_procedure_name, // procedure name
|
|
25
|
+
PostgreSqlParser.RULE_column_name_create, // column name that will be created
|
|
25
26
|
PostgreSqlParser.RULE_column_name, // column name
|
|
26
27
|
]);
|
|
27
28
|
}
|
|
@@ -34,16 +35,19 @@ export class PostgreSQL extends BasicSQL {
|
|
|
34
35
|
get splitListener() {
|
|
35
36
|
return new PostgreSqlSplitListener();
|
|
36
37
|
}
|
|
38
|
+
createErrorListener(_errorListener) {
|
|
39
|
+
return new PostgreSqlErrorListener(_errorListener, this.preferredRules, this.locale);
|
|
40
|
+
}
|
|
37
41
|
createEntityCollector(input, caretTokenIndex) {
|
|
38
42
|
return new PostgreSqlEntityCollector(input, caretTokenIndex);
|
|
39
43
|
}
|
|
40
|
-
processCandidates(candidates, allTokens, caretTokenIndex
|
|
44
|
+
processCandidates(candidates, allTokens, caretTokenIndex) {
|
|
41
45
|
const originalSyntaxSuggestions = [];
|
|
42
46
|
const keywords = [];
|
|
43
47
|
for (let candidate of candidates.rules) {
|
|
44
48
|
const [ruleType, candidateRule] = candidate;
|
|
45
|
-
const startTokenIndex = candidateRule.startTokenIndex
|
|
46
|
-
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex +
|
|
49
|
+
const startTokenIndex = candidateRule.startTokenIndex;
|
|
50
|
+
const tokenRanges = allTokens.slice(startTokenIndex, caretTokenIndex + 1);
|
|
47
51
|
let syntaxContextType = void 0;
|
|
48
52
|
switch (ruleType) {
|
|
49
53
|
case PostgreSqlParser.RULE_table_name_create: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AltertablestmtContext, type ColumnCreateTableContext, type ColumnNameCreateContext, type CreateDatabaseContext, type CreateForeignTableContext, type CreatefunctionstmtContext, type CreateMaterializedViewContext, type CreatePartitionForeignTableContext, type CreateViewContext, type DatabaseNameContext, type DatabaseNameCreateContext, type FunctionNameCreateContext, type InsertStatementContext, type ProcedureNameContext, type ProcedureNameCreateContext, type QueryCreateTableContext, type SelectStatementContext, type SingleStmtContext, type TableNameContext, type TableNameCreateContext, type ViewNameContext, type ViewNameCreateContext } from '../../lib/postgresql/PostgreSqlParser';
|
|
2
2
|
import type { PostgreSqlParserListener } from '../../lib/postgresql/PostgreSqlParserListener';
|
|
3
3
|
import { EntityCollector } from '../common/entityCollector';
|
|
4
4
|
export declare class PostgreSqlEntityCollector extends EntityCollector implements PostgreSqlParserListener {
|
|
@@ -11,6 +11,8 @@ export declare class PostgreSqlEntityCollector extends EntityCollector implement
|
|
|
11
11
|
exitViewNameCreate(ctx: ViewNameCreateContext): void;
|
|
12
12
|
exitFunctionNameCreate(ctx: FunctionNameCreateContext): void;
|
|
13
13
|
exitColumnNameCreate(ctx: ColumnNameCreateContext): void;
|
|
14
|
+
exitProcedureName(ctx: ProcedureNameContext): void;
|
|
15
|
+
exitProcedureNameCreate(ctx: ProcedureNameCreateContext): void;
|
|
14
16
|
/** ===== Statement begin */
|
|
15
17
|
enterSingleStatement(ctx: SingleStmtContext): void;
|
|
16
18
|
exitSingleStatement(ctx: SingleStmtContext): void;
|
|
@@ -34,4 +36,6 @@ export declare class PostgreSqlEntityCollector extends EntityCollector implement
|
|
|
34
36
|
exitInsertStatement(ctx: InsertStatementContext): void;
|
|
35
37
|
enterCreatefunctionstmt(ctx: CreatefunctionstmtContext): void;
|
|
36
38
|
exitCreatefunctionstmt(ctx: CreatefunctionstmtContext): void;
|
|
39
|
+
enterAltertablestmt(ctx: AltertablestmtContext): void;
|
|
40
|
+
exitAltertablestmt(ctx: AltertablestmtContext): void;
|
|
37
41
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { Column_defContext, Table_refContext, } from '../../lib/postgresql/PostgreSqlParser';
|
|
2
|
+
import { AttrName, EntityCollector, StmtContextType } from '../common/entityCollector';
|
|
1
3
|
import { EntityContextType } from '../common/types';
|
|
2
|
-
import { StmtContextType, EntityCollector } from '../common/entityCollector';
|
|
3
4
|
export class PostgreSqlEntityCollector extends EntityCollector {
|
|
4
5
|
/** ====== Entity Begin */
|
|
5
6
|
exitDatabaseName(ctx) {
|
|
@@ -9,13 +10,31 @@ export class PostgreSqlEntityCollector extends EntityCollector {
|
|
|
9
10
|
this.pushEntity(ctx, EntityContextType.DATABASE_CREATE);
|
|
10
11
|
}
|
|
11
12
|
exitTableName(ctx) {
|
|
12
|
-
|
|
13
|
+
var _a;
|
|
14
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
15
|
+
this.pushEntity(ctx, EntityContextType.TABLE, needCollectAttr
|
|
16
|
+
? [
|
|
17
|
+
{
|
|
18
|
+
attrName: AttrName.alias,
|
|
19
|
+
endContextList: [Table_refContext.name],
|
|
20
|
+
},
|
|
21
|
+
]
|
|
22
|
+
: undefined);
|
|
13
23
|
}
|
|
14
24
|
exitTableNameCreate(ctx) {
|
|
15
25
|
this.pushEntity(ctx, EntityContextType.TABLE_CREATE);
|
|
16
26
|
}
|
|
17
27
|
exitViewName(ctx) {
|
|
18
|
-
|
|
28
|
+
var _a;
|
|
29
|
+
const needCollectAttr = ((_a = this.getRootStmt()) === null || _a === void 0 ? void 0 : _a.stmtContextType) === StmtContextType.SELECT_STMT;
|
|
30
|
+
this.pushEntity(ctx, EntityContextType.VIEW, needCollectAttr
|
|
31
|
+
? [
|
|
32
|
+
{
|
|
33
|
+
attrName: AttrName.alias,
|
|
34
|
+
endContextList: [Table_refContext.name],
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
: undefined);
|
|
19
38
|
}
|
|
20
39
|
exitViewNameCreate(ctx) {
|
|
21
40
|
this.pushEntity(ctx, EntityContextType.VIEW_CREATE);
|
|
@@ -24,7 +43,22 @@ export class PostgreSqlEntityCollector extends EntityCollector {
|
|
|
24
43
|
this.pushEntity(ctx, EntityContextType.FUNCTION_CREATE);
|
|
25
44
|
}
|
|
26
45
|
exitColumnNameCreate(ctx) {
|
|
27
|
-
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE
|
|
46
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
47
|
+
{
|
|
48
|
+
attrName: AttrName.comment,
|
|
49
|
+
endContextList: [Column_defContext.name],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
attrName: AttrName.colType,
|
|
53
|
+
endContextList: [Column_defContext.name],
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
}
|
|
57
|
+
exitProcedureName(ctx) {
|
|
58
|
+
this.pushEntity(ctx, EntityContextType.PROCEDURE);
|
|
59
|
+
}
|
|
60
|
+
exitProcedureNameCreate(ctx) {
|
|
61
|
+
this.pushEntity(ctx, EntityContextType.PROCEDURE_CREATE);
|
|
28
62
|
}
|
|
29
63
|
/** ===== Statement begin */
|
|
30
64
|
enterSingleStatement(ctx) {
|
|
@@ -93,4 +127,10 @@ export class PostgreSqlEntityCollector extends EntityCollector {
|
|
|
93
127
|
exitCreatefunctionstmt(ctx) {
|
|
94
128
|
this.popStmt();
|
|
95
129
|
}
|
|
130
|
+
enterAltertablestmt(ctx) {
|
|
131
|
+
this.pushStmt(ctx, StmtContextType.ALTER_TABLE_STMT);
|
|
132
|
+
}
|
|
133
|
+
exitAltertablestmt(ctx) {
|
|
134
|
+
this.popStmt();
|
|
135
|
+
}
|
|
96
136
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ErrorListener, ParseErrorListener } from '../common/parseErrorListener';
|
|
2
|
+
import { Parser, Token } from 'antlr4ng';
|
|
3
|
+
import { LOCALE_TYPE } from '../common/types';
|
|
4
|
+
export declare class PostgreSqlErrorListener extends ParseErrorListener {
|
|
5
|
+
private preferredRules;
|
|
6
|
+
private objectNames;
|
|
7
|
+
constructor(errorListener: ErrorListener, preferredRules: Set<number>, locale: LOCALE_TYPE);
|
|
8
|
+
getExpectedText(parser: Parser, token: Token): string;
|
|
9
|
+
}
|