dt-sql-parser 4.5.0-beta.1 → 4.5.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -2
- package/dist/lib/SQLParserBase.d.ts +1 -13
- package/dist/lib/SQLParserBase.js +5 -40
- package/dist/lib/flink/FlinkSqlParser.d.ts +179 -222
- package/dist/lib/flink/FlinkSqlParser.js +2949 -3300
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +0 -33
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +0 -21
- package/dist/lib/generic/GenericSqlLexer.d.ts +143 -0
- package/dist/lib/generic/GenericSqlLexer.js +603 -0
- package/dist/lib/generic/GenericSqlListener.d.ts +1089 -0
- package/dist/lib/generic/GenericSqlListener.js +11 -0
- package/dist/lib/generic/GenericSqlParser.d.ts +1272 -0
- package/dist/lib/generic/GenericSqlParser.js +7641 -0
- package/dist/lib/generic/GenericSqlVisitor.d.ts +684 -0
- package/dist/lib/generic/GenericSqlVisitor.js +12 -0
- package/dist/lib/hive/HiveSqlParser.d.ts +228 -274
- package/dist/lib/hive/HiveSqlParser.js +5912 -6304
- package/dist/lib/hive/HiveSqlParserListener.d.ts +0 -33
- package/dist/lib/hive/HiveSqlParserVisitor.d.ts +0 -21
- package/dist/lib/impala/ImpalaSqlParser.d.ts +103 -145
- package/dist/lib/impala/ImpalaSqlParser.js +3320 -3687
- package/dist/lib/impala/ImpalaSqlParserListener.d.ts +0 -33
- package/dist/lib/impala/ImpalaSqlParserVisitor.d.ts +0 -21
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/mysql/MySqlParser.d.ts +94 -161
- package/dist/lib/mysql/MySqlParser.js +9499 -9959
- package/dist/lib/mysql/MySqlParserListener.d.ts +5 -79
- package/dist/lib/mysql/MySqlParserVisitor.d.ts +3 -49
- package/dist/lib/postgresql/PostgreSqlParser.d.ts +71 -108
- package/dist/lib/postgresql/PostgreSqlParser.js +10388 -13330
- package/dist/lib/postgresql/PostgreSqlParserListener.d.ts +0 -48
- package/dist/lib/postgresql/PostgreSqlParserVisitor.d.ts +0 -30
- package/dist/lib/spark/SparkSqlParser.d.ts +145 -185
- package/dist/lib/spark/SparkSqlParser.js +5109 -5420
- package/dist/lib/spark/SparkSqlParserListener.d.ts +0 -33
- package/dist/lib/spark/SparkSqlParserVisitor.d.ts +0 -21
- package/dist/parser/common/basicSQL.d.ts +5 -5
- package/dist/parser/common/basicSQL.js +3 -3
- package/dist/parser/common/entityCollector.js +2 -14
- package/dist/parser/flink/index.js +2 -5
- package/dist/parser/generic/genericEntityCollector.d.ts +29 -0
- package/dist/parser/generic/genericEntityCollector.js +103 -0
- package/dist/parser/generic/genericErrorListener.d.ts +6 -0
- package/dist/parser/generic/genericErrorListener.js +56 -0
- package/dist/parser/generic/genericSemanticContextCollector.d.ts +9 -0
- package/dist/parser/generic/genericSemanticContextCollector.js +14 -0
- package/dist/parser/generic/genericSplitListener.d.ts +6 -0
- package/dist/parser/generic/genericSplitListener.js +6 -0
- package/dist/parser/generic/index.d.ts +33 -0
- package/dist/parser/generic/index.js +94 -0
- package/dist/parser/index.d.ts +1 -0
- package/dist/parser/index.js +1 -0
- package/dist/parser/mysql/index.js +1 -3
- package/dist/parser/mysql/mysqlEntityCollector.d.ts +1 -2
- package/dist/parser/mysql/mysqlEntityCollector.js +3 -13
- package/dist/parser/mysql/mysqlErrorListener.js +0 -2
- package/dist/parser/postgresql/postgreEntityCollector.d.ts +1 -3
- package/dist/parser/postgresql/postgreEntityCollector.js +0 -13
- package/dist/parser/spark/index.js +1 -3
- package/package.json +1 -1
|
@@ -131,10 +131,8 @@ import { TableNameCreateContext } from "./SparkSqlParser.js";
|
|
|
131
131
|
import { TableNameContext } from "./SparkSqlParser.js";
|
|
132
132
|
import { ViewNameCreateContext } from "./SparkSqlParser.js";
|
|
133
133
|
import { ViewNameContext } from "./SparkSqlParser.js";
|
|
134
|
-
import { EmptyColumnContext } from "./SparkSqlParser.js";
|
|
135
134
|
import { ColumnNameContext } from "./SparkSqlParser.js";
|
|
136
135
|
import { ColumnNamePathContext } from "./SparkSqlParser.js";
|
|
137
|
-
import { ColumnNamePathAllowEmptyContext } from "./SparkSqlParser.js";
|
|
138
136
|
import { ColumnNameSeqContext } from "./SparkSqlParser.js";
|
|
139
137
|
import { ColumnNameCreateContext } from "./SparkSqlParser.js";
|
|
140
138
|
import { IdentifierReferenceContext } from "./SparkSqlParser.js";
|
|
@@ -208,7 +206,6 @@ import { TableAliasContext } from "./SparkSqlParser.js";
|
|
|
208
206
|
import { RowFormatContext } from "./SparkSqlParser.js";
|
|
209
207
|
import { MultipartIdentifierListContext } from "./SparkSqlParser.js";
|
|
210
208
|
import { MultipartIdentifierContext } from "./SparkSqlParser.js";
|
|
211
|
-
import { MultipartIdentifierAllowEmptyContext } from "./SparkSqlParser.js";
|
|
212
209
|
import { MultipartIdentifierPropertyListContext } from "./SparkSqlParser.js";
|
|
213
210
|
import { MultipartIdentifierPropertyContext } from "./SparkSqlParser.js";
|
|
214
211
|
import { TableIdentifierContext } from "./SparkSqlParser.js";
|
|
@@ -1799,16 +1796,6 @@ export declare class SparkSqlParserListener implements ParseTreeListener {
|
|
|
1799
1796
|
* @param ctx the parse tree
|
|
1800
1797
|
*/
|
|
1801
1798
|
exitViewName?: (ctx: ViewNameContext) => void;
|
|
1802
|
-
/**
|
|
1803
|
-
* Enter a parse tree produced by `SparkSqlParser.emptyColumn`.
|
|
1804
|
-
* @param ctx the parse tree
|
|
1805
|
-
*/
|
|
1806
|
-
enterEmptyColumn?: (ctx: EmptyColumnContext) => void;
|
|
1807
|
-
/**
|
|
1808
|
-
* Exit a parse tree produced by `SparkSqlParser.emptyColumn`.
|
|
1809
|
-
* @param ctx the parse tree
|
|
1810
|
-
*/
|
|
1811
|
-
exitEmptyColumn?: (ctx: EmptyColumnContext) => void;
|
|
1812
1799
|
/**
|
|
1813
1800
|
* Enter a parse tree produced by `SparkSqlParser.columnName`.
|
|
1814
1801
|
* @param ctx the parse tree
|
|
@@ -1829,16 +1816,6 @@ export declare class SparkSqlParserListener implements ParseTreeListener {
|
|
|
1829
1816
|
* @param ctx the parse tree
|
|
1830
1817
|
*/
|
|
1831
1818
|
exitColumnNamePath?: (ctx: ColumnNamePathContext) => void;
|
|
1832
|
-
/**
|
|
1833
|
-
* Enter a parse tree produced by `SparkSqlParser.columnNamePathAllowEmpty`.
|
|
1834
|
-
* @param ctx the parse tree
|
|
1835
|
-
*/
|
|
1836
|
-
enterColumnNamePathAllowEmpty?: (ctx: ColumnNamePathAllowEmptyContext) => void;
|
|
1837
|
-
/**
|
|
1838
|
-
* Exit a parse tree produced by `SparkSqlParser.columnNamePathAllowEmpty`.
|
|
1839
|
-
* @param ctx the parse tree
|
|
1840
|
-
*/
|
|
1841
|
-
exitColumnNamePathAllowEmpty?: (ctx: ColumnNamePathAllowEmptyContext) => void;
|
|
1842
1819
|
/**
|
|
1843
1820
|
* Enter a parse tree produced by `SparkSqlParser.columnNameSeq`.
|
|
1844
1821
|
* @param ctx the parse tree
|
|
@@ -2579,16 +2556,6 @@ export declare class SparkSqlParserListener implements ParseTreeListener {
|
|
|
2579
2556
|
* @param ctx the parse tree
|
|
2580
2557
|
*/
|
|
2581
2558
|
exitMultipartIdentifier?: (ctx: MultipartIdentifierContext) => void;
|
|
2582
|
-
/**
|
|
2583
|
-
* Enter a parse tree produced by `SparkSqlParser.multipartIdentifierAllowEmpty`.
|
|
2584
|
-
* @param ctx the parse tree
|
|
2585
|
-
*/
|
|
2586
|
-
enterMultipartIdentifierAllowEmpty?: (ctx: MultipartIdentifierAllowEmptyContext) => void;
|
|
2587
|
-
/**
|
|
2588
|
-
* Exit a parse tree produced by `SparkSqlParser.multipartIdentifierAllowEmpty`.
|
|
2589
|
-
* @param ctx the parse tree
|
|
2590
|
-
*/
|
|
2591
|
-
exitMultipartIdentifierAllowEmpty?: (ctx: MultipartIdentifierAllowEmptyContext) => void;
|
|
2592
2559
|
/**
|
|
2593
2560
|
* Enter a parse tree produced by `SparkSqlParser.multipartIdentifierPropertyList`.
|
|
2594
2561
|
* @param ctx the parse tree
|
|
@@ -131,10 +131,8 @@ import { TableNameCreateContext } from "./SparkSqlParser.js";
|
|
|
131
131
|
import { TableNameContext } from "./SparkSqlParser.js";
|
|
132
132
|
import { ViewNameCreateContext } from "./SparkSqlParser.js";
|
|
133
133
|
import { ViewNameContext } from "./SparkSqlParser.js";
|
|
134
|
-
import { EmptyColumnContext } from "./SparkSqlParser.js";
|
|
135
134
|
import { ColumnNameContext } from "./SparkSqlParser.js";
|
|
136
135
|
import { ColumnNamePathContext } from "./SparkSqlParser.js";
|
|
137
|
-
import { ColumnNamePathAllowEmptyContext } from "./SparkSqlParser.js";
|
|
138
136
|
import { ColumnNameSeqContext } from "./SparkSqlParser.js";
|
|
139
137
|
import { ColumnNameCreateContext } from "./SparkSqlParser.js";
|
|
140
138
|
import { IdentifierReferenceContext } from "./SparkSqlParser.js";
|
|
@@ -208,7 +206,6 @@ import { TableAliasContext } from "./SparkSqlParser.js";
|
|
|
208
206
|
import { RowFormatContext } from "./SparkSqlParser.js";
|
|
209
207
|
import { MultipartIdentifierListContext } from "./SparkSqlParser.js";
|
|
210
208
|
import { MultipartIdentifierContext } from "./SparkSqlParser.js";
|
|
211
|
-
import { MultipartIdentifierAllowEmptyContext } from "./SparkSqlParser.js";
|
|
212
209
|
import { MultipartIdentifierPropertyListContext } from "./SparkSqlParser.js";
|
|
213
210
|
import { MultipartIdentifierPropertyContext } from "./SparkSqlParser.js";
|
|
214
211
|
import { TableIdentifierContext } from "./SparkSqlParser.js";
|
|
@@ -1178,12 +1175,6 @@ export declare class SparkSqlParserVisitor<Result> extends AbstractParseTreeVisi
|
|
|
1178
1175
|
* @return the visitor result
|
|
1179
1176
|
*/
|
|
1180
1177
|
visitViewName?: (ctx: ViewNameContext) => Result;
|
|
1181
|
-
/**
|
|
1182
|
-
* Visit a parse tree produced by `SparkSqlParser.emptyColumn`.
|
|
1183
|
-
* @param ctx the parse tree
|
|
1184
|
-
* @return the visitor result
|
|
1185
|
-
*/
|
|
1186
|
-
visitEmptyColumn?: (ctx: EmptyColumnContext) => Result;
|
|
1187
1178
|
/**
|
|
1188
1179
|
* Visit a parse tree produced by `SparkSqlParser.columnName`.
|
|
1189
1180
|
* @param ctx the parse tree
|
|
@@ -1196,12 +1187,6 @@ export declare class SparkSqlParserVisitor<Result> extends AbstractParseTreeVisi
|
|
|
1196
1187
|
* @return the visitor result
|
|
1197
1188
|
*/
|
|
1198
1189
|
visitColumnNamePath?: (ctx: ColumnNamePathContext) => Result;
|
|
1199
|
-
/**
|
|
1200
|
-
* Visit a parse tree produced by `SparkSqlParser.columnNamePathAllowEmpty`.
|
|
1201
|
-
* @param ctx the parse tree
|
|
1202
|
-
* @return the visitor result
|
|
1203
|
-
*/
|
|
1204
|
-
visitColumnNamePathAllowEmpty?: (ctx: ColumnNamePathAllowEmptyContext) => Result;
|
|
1205
1190
|
/**
|
|
1206
1191
|
* Visit a parse tree produced by `SparkSqlParser.columnNameSeq`.
|
|
1207
1192
|
* @param ctx the parse tree
|
|
@@ -1645,12 +1630,6 @@ export declare class SparkSqlParserVisitor<Result> extends AbstractParseTreeVisi
|
|
|
1645
1630
|
* @return the visitor result
|
|
1646
1631
|
*/
|
|
1647
1632
|
visitMultipartIdentifier?: (ctx: MultipartIdentifierContext) => Result;
|
|
1648
|
-
/**
|
|
1649
|
-
* Visit a parse tree produced by `SparkSqlParser.multipartIdentifierAllowEmpty`.
|
|
1650
|
-
* @param ctx the parse tree
|
|
1651
|
-
* @return the visitor result
|
|
1652
|
-
*/
|
|
1653
|
-
visitMultipartIdentifierAllowEmpty?: (ctx: MultipartIdentifierAllowEmptyContext) => Result;
|
|
1654
1633
|
/**
|
|
1655
1634
|
* Visit a parse tree produced by `SparkSqlParser.multipartIdentifierPropertyList`.
|
|
1656
1635
|
* @param ctx the parse tree
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { Lexer, Token, CommonTokenStream, CharStream, ParserRuleContext, ParseTreeListener, ANTLRErrorListener, Parser } from 'antlr4ng';
|
|
1
2
|
import { CandidatesCollection } from 'antlr4-c3';
|
|
2
|
-
import { ANTLRErrorListener, CharStream, CommonTokenStream, Lexer, Parser, ParserRuleContext, ParseTreeListener, Token } from 'antlr4ng';
|
|
3
3
|
import { SQLParserBase } from '../../lib/SQLParserBase';
|
|
4
|
+
import { TextSlice } from './textAndWord';
|
|
5
|
+
import { CaretPosition, LOCALE_TYPE, SemanticCollectOptions, Suggestions } from './types';
|
|
6
|
+
import { ParseError, ErrorListener } from './parseErrorListener';
|
|
7
|
+
import type { SplitListener } from './splitListener';
|
|
4
8
|
import type { EntityCollector } from './entityCollector';
|
|
5
9
|
import { EntityContext } from './entityCollector';
|
|
6
|
-
import { ErrorListener, ParseError } from './parseErrorListener';
|
|
7
10
|
import SemanticContextCollector from './semanticContextCollector';
|
|
8
|
-
import type { SplitListener } from './splitListener';
|
|
9
|
-
import { TextSlice } from './textAndWord';
|
|
10
|
-
import { CaretPosition, LOCALE_TYPE, SemanticCollectOptions, Suggestions } from './types';
|
|
11
11
|
export declare const SQL_SPLIT_SYMBOL_TEXT = ";";
|
|
12
12
|
/**
|
|
13
13
|
* Basic SQL class, every sql needs extends it.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CodeCompletionCore } from 'antlr4-c3';
|
|
2
1
|
import { CharStreams, CommonTokenStream, ParseTreeWalker, PredictionMode, } from 'antlr4ng';
|
|
3
|
-
import {
|
|
2
|
+
import { CodeCompletionCore } from 'antlr4-c3';
|
|
4
3
|
import { findCaretTokenIndex } from './findCaretTokenIndex';
|
|
5
4
|
import { ctxToText, tokenToWord } from './textAndWord';
|
|
5
|
+
import { ErrorStrategy } from './errorStrategy';
|
|
6
6
|
export const SQL_SPLIT_SYMBOL_TEXT = ';';
|
|
7
7
|
/**
|
|
8
8
|
* Basic SQL class, every sql needs extends it.
|
|
@@ -360,7 +360,7 @@ export class BasicSQL {
|
|
|
360
360
|
const core = new CodeCompletionCore(sqlParserIns);
|
|
361
361
|
core.preferredRules = this.preferredRules;
|
|
362
362
|
// core.showRuleStack = true;
|
|
363
|
-
//
|
|
363
|
+
// core.showResult = true;
|
|
364
364
|
const candidates = core.collectCandidates(caretTokenIndex, parseTree);
|
|
365
365
|
const originalSuggestions = this.processCandidates(candidates, allTokens, caretTokenIndex);
|
|
366
366
|
const syntaxSuggestions = originalSuggestions.syntax.map((syntaxCtx) => {
|
|
@@ -436,20 +436,8 @@ export class EntityCollector {
|
|
|
436
436
|
}
|
|
437
437
|
else {
|
|
438
438
|
// Do not collect column and queryResult entities if they are not inside a select statement
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
// Keep non-COLUMN and non-QUERY_RESULT entities
|
|
442
|
-
if (entity.entityContextType !== EntityContextType.COLUMN &&
|
|
443
|
-
entity.entityContextType !== EntityContextType.QUERY_RESULT) {
|
|
444
|
-
return true;
|
|
445
|
-
}
|
|
446
|
-
// Also keep empty QUERY_RESULT entities (text === '')
|
|
447
|
-
if (entity.entityContextType === EntityContextType.QUERY_RESULT &&
|
|
448
|
-
entity.text === '') {
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
return false;
|
|
452
|
-
});
|
|
439
|
+
return entitiesInsideStmt.filter((entity) => entity.entityContextType !== EntityContextType.COLUMN &&
|
|
440
|
+
entity.entityContextType !== EntityContextType.QUERY_RESULT);
|
|
453
441
|
}
|
|
454
442
|
}
|
|
455
443
|
combineQueryResultStmtEntities(stmtContext, entitiesInsideStmt) {
|
|
@@ -36,7 +36,6 @@ export class FlinkSQL extends BasicSQL {
|
|
|
36
36
|
FlinkSqlParser.RULE_functionNameCreate, // functionName that will be created
|
|
37
37
|
FlinkSqlParser.RULE_columnName,
|
|
38
38
|
FlinkSqlParser.RULE_columnNamePath,
|
|
39
|
-
FlinkSqlParser.RULE_columnNamePathAllowEmpty,
|
|
40
39
|
FlinkSqlParser.RULE_columnNameCreate,
|
|
41
40
|
FlinkSqlParser.RULE_tablePropertyKey,
|
|
42
41
|
FlinkSqlParser.RULE_tablePropertyValue,
|
|
@@ -117,15 +116,13 @@ export class FlinkSQL extends BasicSQL {
|
|
|
117
116
|
syntaxContextType = EntityContextType.COLUMN_CREATE;
|
|
118
117
|
break;
|
|
119
118
|
}
|
|
120
|
-
case FlinkSqlParser.RULE_columnNamePath:
|
|
121
|
-
case FlinkSqlParser.RULE_columnNamePathAllowEmpty: {
|
|
119
|
+
case FlinkSqlParser.RULE_columnNamePath: {
|
|
122
120
|
if (candidateRule.ruleList.includes(FlinkSqlParser.RULE_selectClause) ||
|
|
123
121
|
candidateRule.ruleList.includes(FlinkSqlParser.RULE_whereClause) ||
|
|
124
122
|
candidateRule.ruleList.includes(FlinkSqlParser.RULE_groupByClause) ||
|
|
125
123
|
candidateRule.ruleList.includes(FlinkSqlParser.RULE_limitClause) ||
|
|
126
124
|
candidateRule.ruleList.includes(FlinkSqlParser.RULE_whenClause) ||
|
|
127
|
-
candidateRule.ruleList.includes(FlinkSqlParser.RULE_havingClause)
|
|
128
|
-
candidateRule.ruleList.includes(FlinkSqlParser.RULE_joinCondition)) {
|
|
125
|
+
candidateRule.ruleList.includes(FlinkSqlParser.RULE_havingClause)) {
|
|
129
126
|
syntaxContextType = EntityContextType.COLUMN;
|
|
130
127
|
}
|
|
131
128
|
break;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { GenericSqlListener } from '../../lib/generic/GenericSqlListener';
|
|
2
|
+
import { AlterTableContext, ColumnDefinitionContext, ColumnRefContext, CreateTableContext, DeleteContext, DropTableContext, InsertContext, QuerySpecificationContext, QueryStatementContext, SelectItemContext, SingleStatementContext, TableNameContext, TableNameCreateContext, UpdateContext } from '../../lib/generic/GenericSqlParser';
|
|
3
|
+
import { EntityCollector } from '../common/entityCollector';
|
|
4
|
+
export declare class GenericEntityCollector extends EntityCollector implements GenericSqlListener {
|
|
5
|
+
/** ====== Entity Begin */
|
|
6
|
+
exitTableName(ctx: TableNameContext): void;
|
|
7
|
+
exitTableNameCreate(ctx: TableNameCreateContext): void;
|
|
8
|
+
exitColumnRef(ctx: ColumnRefContext): void;
|
|
9
|
+
exitColumnDefinition(ctx: ColumnDefinitionContext): void;
|
|
10
|
+
exitQuerySpecification(ctx: QuerySpecificationContext): void;
|
|
11
|
+
exitSelectItem(ctx: SelectItemContext): void;
|
|
12
|
+
/** ===== Statement begin */
|
|
13
|
+
enterSingleStatement(ctx: SingleStatementContext): void;
|
|
14
|
+
exitSingleStatement(ctx: SingleStatementContext): void;
|
|
15
|
+
enterCreateTable(ctx: CreateTableContext): void;
|
|
16
|
+
exitCreateTable(ctx: CreateTableContext): void;
|
|
17
|
+
enterQueryStatement(ctx: QueryStatementContext): void;
|
|
18
|
+
exitQueryStatement(ctx: QueryStatementContext): void;
|
|
19
|
+
enterInsert(ctx: InsertContext): void;
|
|
20
|
+
exitInsert(ctx: InsertContext): void;
|
|
21
|
+
enterUpdate(ctx: UpdateContext): void;
|
|
22
|
+
exitUpdate(ctx: UpdateContext): void;
|
|
23
|
+
enterDelete(ctx: DeleteContext): void;
|
|
24
|
+
exitDelete(ctx: DeleteContext): void;
|
|
25
|
+
enterAlterTable(ctx: AlterTableContext): void;
|
|
26
|
+
exitAlterTable(ctx: AlterTableContext): void;
|
|
27
|
+
enterDropTable(ctx: DropTableContext): void;
|
|
28
|
+
exitDropTable(ctx: DropTableContext): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ColumnDefinitionContext, CreateTableStatementContext, SelectItemContext, } from '../../lib/generic/GenericSqlParser';
|
|
2
|
+
import { AttrName, ColumnDeclareType, EntityCollector, StmtContextType, TableDeclareType, } from '../common/entityCollector';
|
|
3
|
+
import { EntityContextType } from '../common/types';
|
|
4
|
+
export class GenericEntityCollector extends EntityCollector {
|
|
5
|
+
/** ====== Entity Begin */
|
|
6
|
+
exitTableName(ctx) {
|
|
7
|
+
this.pushEntity(ctx, EntityContextType.TABLE, [], {
|
|
8
|
+
declareType: TableDeclareType.LITERAL,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
exitTableNameCreate(ctx) {
|
|
12
|
+
this.pushEntity(ctx, EntityContextType.TABLE_CREATE, [
|
|
13
|
+
{
|
|
14
|
+
attrName: AttrName.comment,
|
|
15
|
+
endContextList: [CreateTableStatementContext.name],
|
|
16
|
+
},
|
|
17
|
+
]);
|
|
18
|
+
}
|
|
19
|
+
exitColumnRef(ctx) {
|
|
20
|
+
this.pushEntity(ctx, EntityContextType.COLUMN);
|
|
21
|
+
}
|
|
22
|
+
exitColumnDefinition(ctx) {
|
|
23
|
+
this.pushEntity(ctx, EntityContextType.COLUMN_CREATE, [
|
|
24
|
+
{
|
|
25
|
+
attrName: AttrName.colType,
|
|
26
|
+
endContextList: [ColumnDefinitionContext.name],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
attrName: AttrName.comment,
|
|
30
|
+
endContextList: [ColumnDefinitionContext.name],
|
|
31
|
+
},
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
exitQuerySpecification(ctx) {
|
|
35
|
+
this.pushEntity(ctx, EntityContextType.QUERY_RESULT);
|
|
36
|
+
}
|
|
37
|
+
exitSelectItem(ctx) {
|
|
38
|
+
if (ctx.ASTERISK()) {
|
|
39
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [], {
|
|
40
|
+
declareType: ColumnDeclareType.ALL,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.pushEntity(ctx, EntityContextType.COLUMN, [
|
|
45
|
+
{
|
|
46
|
+
attrName: AttrName.alias,
|
|
47
|
+
endContextList: [SelectItemContext.name],
|
|
48
|
+
},
|
|
49
|
+
], {
|
|
50
|
+
declareType: ColumnDeclareType.EXPRESSION,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** ===== Statement begin */
|
|
55
|
+
enterSingleStatement(ctx) {
|
|
56
|
+
this.pushStmt(ctx, StmtContextType.COMMON_STMT);
|
|
57
|
+
}
|
|
58
|
+
exitSingleStatement(ctx) {
|
|
59
|
+
this.popStmt();
|
|
60
|
+
}
|
|
61
|
+
enterCreateTable(ctx) {
|
|
62
|
+
this.pushStmt(ctx, StmtContextType.CREATE_TABLE_STMT);
|
|
63
|
+
}
|
|
64
|
+
exitCreateTable(ctx) {
|
|
65
|
+
this.popStmt();
|
|
66
|
+
}
|
|
67
|
+
enterQueryStatement(ctx) {
|
|
68
|
+
this.pushStmt(ctx, StmtContextType.SELECT_STMT);
|
|
69
|
+
}
|
|
70
|
+
exitQueryStatement(ctx) {
|
|
71
|
+
this.popStmt();
|
|
72
|
+
}
|
|
73
|
+
enterInsert(ctx) {
|
|
74
|
+
this.pushStmt(ctx, StmtContextType.INSERT_STMT);
|
|
75
|
+
}
|
|
76
|
+
exitInsert(ctx) {
|
|
77
|
+
this.popStmt();
|
|
78
|
+
}
|
|
79
|
+
enterUpdate(ctx) {
|
|
80
|
+
this.pushStmt(ctx, StmtContextType.COMMON_STMT);
|
|
81
|
+
}
|
|
82
|
+
exitUpdate(ctx) {
|
|
83
|
+
this.popStmt();
|
|
84
|
+
}
|
|
85
|
+
enterDelete(ctx) {
|
|
86
|
+
this.pushStmt(ctx, StmtContextType.COMMON_STMT);
|
|
87
|
+
}
|
|
88
|
+
exitDelete(ctx) {
|
|
89
|
+
this.popStmt();
|
|
90
|
+
}
|
|
91
|
+
enterAlterTable(ctx) {
|
|
92
|
+
this.pushStmt(ctx, StmtContextType.ALTER_TABLE_STMT);
|
|
93
|
+
}
|
|
94
|
+
exitAlterTable(ctx) {
|
|
95
|
+
this.popStmt();
|
|
96
|
+
}
|
|
97
|
+
enterDropTable(ctx) {
|
|
98
|
+
this.pushStmt(ctx, StmtContextType.COMMON_STMT);
|
|
99
|
+
}
|
|
100
|
+
exitDropTable(ctx) {
|
|
101
|
+
this.popStmt();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CodeCompletionCore } from 'antlr4-c3';
|
|
2
|
+
import { GenericSqlParser } from '../../lib/generic/GenericSqlParser';
|
|
3
|
+
import { ParseErrorListener } from '../common/parseErrorListener';
|
|
4
|
+
export class GenericErrorListener extends ParseErrorListener {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.objectNames = new Map([
|
|
8
|
+
[GenericSqlParser.RULE_tableName, 'table'],
|
|
9
|
+
[GenericSqlParser.RULE_tableNameCreate, 'table'],
|
|
10
|
+
[GenericSqlParser.RULE_columnRef, 'column'],
|
|
11
|
+
]);
|
|
12
|
+
}
|
|
13
|
+
getExpectedText(parser, token) {
|
|
14
|
+
var _a;
|
|
15
|
+
let expectedText = '';
|
|
16
|
+
const input = this.parserContext.getParsedInput();
|
|
17
|
+
let currentContext = (_a = parser.context) !== null && _a !== void 0 ? _a : undefined;
|
|
18
|
+
while (currentContext === null || currentContext === void 0 ? void 0 : currentContext.parent) {
|
|
19
|
+
currentContext = currentContext.parent;
|
|
20
|
+
}
|
|
21
|
+
const parserInfo = this.parserContext.getMinimumParserInfo(input, token.tokenIndex, currentContext);
|
|
22
|
+
if (!parserInfo)
|
|
23
|
+
return '';
|
|
24
|
+
const { parser: c3Parser, newTokenIndex, parseTree: c3Context } = parserInfo;
|
|
25
|
+
const core = new CodeCompletionCore(c3Parser);
|
|
26
|
+
core.preferredRules = this.preferredRules;
|
|
27
|
+
const candidates = core.collectCandidates(newTokenIndex, c3Context);
|
|
28
|
+
if (candidates.rules.size) {
|
|
29
|
+
const result = [];
|
|
30
|
+
for (const candidate of candidates.rules) {
|
|
31
|
+
const [ruleType] = candidate;
|
|
32
|
+
const name = this.objectNames.get(ruleType);
|
|
33
|
+
switch (ruleType) {
|
|
34
|
+
case GenericSqlParser.RULE_tableName:
|
|
35
|
+
case GenericSqlParser.RULE_columnRef: {
|
|
36
|
+
if (name && !result.includes(`{existing}${name}`)) {
|
|
37
|
+
result.push(`{existing}${name}`);
|
|
38
|
+
}
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case GenericSqlParser.RULE_tableNameCreate: {
|
|
42
|
+
if (name && !result.includes(`{new}${name}`)) {
|
|
43
|
+
result.push(`{new}${name}`);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
expectedText = result.join('{or}');
|
|
50
|
+
}
|
|
51
|
+
if (candidates.tokens.size) {
|
|
52
|
+
expectedText += expectedText ? '{orKeyword}' : '{keyword}';
|
|
53
|
+
}
|
|
54
|
+
return expectedText;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GenericSqlListener } from '../../lib/generic/GenericSqlListener';
|
|
2
|
+
import { StatementsContext } from '../../lib/generic/GenericSqlParser';
|
|
3
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
4
|
+
declare class GenericSemanticContextCollector extends SemanticContextCollector implements GenericSqlListener {
|
|
5
|
+
getWhiteSpaceRuleType(): number;
|
|
6
|
+
getStatementRuleType(): number;
|
|
7
|
+
enterStatements(ctx: StatementsContext): void;
|
|
8
|
+
}
|
|
9
|
+
export { GenericSemanticContextCollector };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GenericSqlParser } from '../../lib/generic/GenericSqlParser';
|
|
2
|
+
import SemanticContextCollector from '../common/semanticContextCollector';
|
|
3
|
+
class GenericSemanticContextCollector extends SemanticContextCollector {
|
|
4
|
+
getWhiteSpaceRuleType() {
|
|
5
|
+
return GenericSqlParser.WHITE_SPACE;
|
|
6
|
+
}
|
|
7
|
+
getStatementRuleType() {
|
|
8
|
+
return GenericSqlParser.RULE_statements;
|
|
9
|
+
}
|
|
10
|
+
enterStatements(ctx) {
|
|
11
|
+
this.visitStatement(ctx);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export { GenericSemanticContextCollector };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SingleStatementContext } from '../../lib/generic/GenericSqlParser';
|
|
2
|
+
import { GenericSqlListener } from '../../lib/generic/GenericSqlListener';
|
|
3
|
+
import { SplitListener } from '../common/splitListener';
|
|
4
|
+
export declare class GenericSplitListener extends SplitListener<SingleStatementContext> implements GenericSqlListener {
|
|
5
|
+
exitSingleStatement(ctx: SingleStatementContext): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CandidatesCollection } from 'antlr4-c3';
|
|
2
|
+
import { CharStream, CommonTokenStream, Token } from 'antlr4ng';
|
|
3
|
+
import { GenericSqlLexer } from '../../lib/generic/GenericSqlLexer';
|
|
4
|
+
import { GenericSqlParser, ProgramContext } from '../../lib/generic/GenericSqlParser';
|
|
5
|
+
import { BasicSQL } from '../common/basicSQL';
|
|
6
|
+
import { Suggestions, CaretPosition, SemanticCollectOptions } from '../common/types';
|
|
7
|
+
import { ErrorListener, ParseError } from '../common/parseErrorListener';
|
|
8
|
+
import { GenericEntityCollector } from './genericEntityCollector';
|
|
9
|
+
import { GenericErrorListener } from './genericErrorListener';
|
|
10
|
+
import { GenericSplitListener } from './genericSplitListener';
|
|
11
|
+
import { GenericSemanticContextCollector } from './genericSemanticContextCollector';
|
|
12
|
+
export { GenericEntityCollector, GenericSplitListener };
|
|
13
|
+
export interface GenericSQLOptions {
|
|
14
|
+
/** Enable or disable diagnostics (parse error collection). Defaults to true. */
|
|
15
|
+
diagnostics?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class GenericSQL extends BasicSQL<GenericSqlLexer, ProgramContext, GenericSqlParser> {
|
|
18
|
+
private _diagnostics;
|
|
19
|
+
constructor(options?: GenericSQLOptions);
|
|
20
|
+
protected createLexerFromCharStream(charStreams: CharStream): GenericSqlLexer;
|
|
21
|
+
validate(input: string): ParseError[];
|
|
22
|
+
protected createParserFromTokenStream(tokenStream: CommonTokenStream): GenericSqlParser;
|
|
23
|
+
/**
|
|
24
|
+
* The rules that keywords you don't want to be suggested.
|
|
25
|
+
*/
|
|
26
|
+
protected excludeKeywordRules: Set<number>;
|
|
27
|
+
protected preferredRules: Set<number>;
|
|
28
|
+
protected get splitListener(): GenericSplitListener;
|
|
29
|
+
protected createErrorListener(_errorListener: ErrorListener): GenericErrorListener;
|
|
30
|
+
protected createEntityCollector(input: string, allTokens?: Token[], caretTokenIndex?: number): GenericEntityCollector;
|
|
31
|
+
protected createSemanticContextCollector(input: string, caretPosition: CaretPosition, allTokens: Token[], options?: SemanticCollectOptions): GenericSemanticContextCollector;
|
|
32
|
+
protected processCandidates(candidates: CandidatesCollection, allTokens: Token[], caretTokenIndex: number): Suggestions<Token>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { processTokenCandidates } from '../common/tokenUtils';
|
|
2
|
+
import { GenericSqlLexer } from '../../lib/generic/GenericSqlLexer';
|
|
3
|
+
import { GenericSqlParser } from '../../lib/generic/GenericSqlParser';
|
|
4
|
+
import { BasicSQL } from '../common/basicSQL';
|
|
5
|
+
import { EntityContextType, } from '../common/types';
|
|
6
|
+
import { GenericEntityCollector } from './genericEntityCollector';
|
|
7
|
+
import { GenericErrorListener } from './genericErrorListener';
|
|
8
|
+
import { GenericSplitListener } from './genericSplitListener';
|
|
9
|
+
import { GenericSemanticContextCollector } from './genericSemanticContextCollector';
|
|
10
|
+
export { GenericEntityCollector, GenericSplitListener };
|
|
11
|
+
export class GenericSQL extends BasicSQL {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super();
|
|
14
|
+
/**
|
|
15
|
+
* The rules that keywords you don't want to be suggested.
|
|
16
|
+
*/
|
|
17
|
+
this.excludeKeywordRules = new Set([GenericSqlParser.RULE_nonReserved]);
|
|
18
|
+
this.preferredRules = new Set([
|
|
19
|
+
GenericSqlParser.RULE_tableName,
|
|
20
|
+
GenericSqlParser.RULE_tableNameCreate,
|
|
21
|
+
GenericSqlParser.RULE_columnRef,
|
|
22
|
+
...this.excludeKeywordRules,
|
|
23
|
+
]);
|
|
24
|
+
this._diagnostics = (options === null || options === void 0 ? void 0 : options.diagnostics) !== false;
|
|
25
|
+
}
|
|
26
|
+
createLexerFromCharStream(charStreams) {
|
|
27
|
+
return new GenericSqlLexer(charStreams);
|
|
28
|
+
}
|
|
29
|
+
validate(input) {
|
|
30
|
+
if (!this._diagnostics) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
return super.validate(input);
|
|
34
|
+
}
|
|
35
|
+
createParserFromTokenStream(tokenStream) {
|
|
36
|
+
return new GenericSqlParser(tokenStream);
|
|
37
|
+
}
|
|
38
|
+
get splitListener() {
|
|
39
|
+
return new GenericSplitListener();
|
|
40
|
+
}
|
|
41
|
+
createErrorListener(_errorListener) {
|
|
42
|
+
const parserContext = this;
|
|
43
|
+
return new GenericErrorListener(_errorListener, parserContext, this.preferredRules);
|
|
44
|
+
}
|
|
45
|
+
createEntityCollector(input, allTokens, caretTokenIndex) {
|
|
46
|
+
return new GenericEntityCollector(input, allTokens, caretTokenIndex);
|
|
47
|
+
}
|
|
48
|
+
createSemanticContextCollector(input, caretPosition, allTokens, options) {
|
|
49
|
+
return new GenericSemanticContextCollector(input, caretPosition, allTokens, options);
|
|
50
|
+
}
|
|
51
|
+
processCandidates(candidates, allTokens, caretTokenIndex) {
|
|
52
|
+
const originalSyntaxSuggestions = [];
|
|
53
|
+
const keywords = [];
|
|
54
|
+
for (const candidate of candidates.rules) {
|
|
55
|
+
const [ruleType, candidateRule] = candidate;
|
|
56
|
+
const tokenRanges = allTokens.slice(candidateRule.startTokenIndex, caretTokenIndex + 1);
|
|
57
|
+
let syntaxContextType = void 0;
|
|
58
|
+
switch (ruleType) {
|
|
59
|
+
case GenericSqlParser.RULE_tableName: {
|
|
60
|
+
syntaxContextType = EntityContextType.TABLE;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case GenericSqlParser.RULE_tableNameCreate: {
|
|
64
|
+
syntaxContextType = EntityContextType.TABLE_CREATE;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case GenericSqlParser.RULE_columnRef: {
|
|
68
|
+
syntaxContextType = EntityContextType.COLUMN;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
default:
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (syntaxContextType &&
|
|
75
|
+
!originalSyntaxSuggestions.some((syn) => {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
return syn.syntaxContextType === syntaxContextType &&
|
|
78
|
+
((_a = syn.wordRanges.map((wordRange) => wordRange.text)) === null || _a === void 0 ? void 0 : _a.join(',')) ===
|
|
79
|
+
((_b = tokenRanges.map((tokenRange) => tokenRange.text)) === null || _b === void 0 ? void 0 : _b.join(','));
|
|
80
|
+
})) {
|
|
81
|
+
originalSyntaxSuggestions.push({
|
|
82
|
+
syntaxContextType,
|
|
83
|
+
wordRanges: tokenRanges,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const processedKeywords = processTokenCandidates(this._parser, candidates.tokens);
|
|
88
|
+
keywords.push(...processedKeywords);
|
|
89
|
+
return {
|
|
90
|
+
syntax: originalSyntaxSuggestions,
|
|
91
|
+
keywords,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
package/dist/parser/index.d.ts
CHANGED
package/dist/parser/index.js
CHANGED
|
@@ -25,7 +25,6 @@ export class MySQL extends BasicSQL {
|
|
|
25
25
|
MySqlParser.RULE_functionName,
|
|
26
26
|
MySqlParser.RULE_functionNameCreate,
|
|
27
27
|
MySqlParser.RULE_columnName,
|
|
28
|
-
MySqlParser.RULE_columnNamePath,
|
|
29
28
|
MySqlParser.RULE_columnNameCreate,
|
|
30
29
|
...this.excludeKeywordRules,
|
|
31
30
|
]);
|
|
@@ -89,8 +88,7 @@ export class MySQL extends BasicSQL {
|
|
|
89
88
|
syntaxContextType = EntityContextType.FUNCTION_CREATE;
|
|
90
89
|
break;
|
|
91
90
|
}
|
|
92
|
-
case MySqlParser.RULE_columnName:
|
|
93
|
-
case MySqlParser.RULE_columnNamePath: {
|
|
91
|
+
case MySqlParser.RULE_columnName: {
|
|
94
92
|
syntaxContextType = EntityContextType.COLUMN;
|
|
95
93
|
break;
|
|
96
94
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnCreateTableContext, ColumnNameCreateContext, CopyCreateTableContext, CreateDatabaseContext, CreateFunctionContext, CreateFunctionLoadableContext, CreateViewContext, DatabaseNameContext, DatabaseNameCreateContext, FunctionNameCreateContext, InsertStatementContext, QueryCreateTableContext,
|
|
1
|
+
import { ColumnCreateTableContext, ColumnNameCreateContext, CopyCreateTableContext, CreateDatabaseContext, CreateFunctionContext, CreateFunctionLoadableContext, CreateViewContext, DatabaseNameContext, DatabaseNameCreateContext, FunctionNameCreateContext, InsertStatementContext, QueryCreateTableContext, SelectExpressionElementContext, SelectStatementContext, SingleStatementContext, TableNameContext, TableNameCreateContext, ViewNameContext, ViewNameCreateContext, TableAllColumnsContext, SelectLiteralColumnNameContext, AtomSubQueryTableSourceContext, SelectElementsContext, PureAllColumnsContext } 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 {
|
|
@@ -18,7 +18,6 @@ export declare class MySqlEntityCollector extends EntityCollector implements MyS
|
|
|
18
18
|
exitTableAllColumns(ctx: TableAllColumnsContext): void;
|
|
19
19
|
exitPureAllColumns(ctx: PureAllColumnsContext): void;
|
|
20
20
|
exitSelectLiteralColumnName(ctx: SelectLiteralColumnNameContext): void;
|
|
21
|
-
exitSelectElement_dot_empty(ctx: SelectElement_dot_emptyContext): void;
|
|
22
21
|
exitSelectExpressionElement(ctx: SelectExpressionElementContext): void;
|
|
23
22
|
/** ===== Statement begin */
|
|
24
23
|
enterSingleStatement(ctx: SingleStatementContext): void;
|