dt-sql-parser 4.5.0-beta.2 → 4.5.0-beta.3
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 +2 -3
- package/dist/index.js +2 -2
- package/dist/lib/flink/FlinkSqlLexer.d.ts +399 -397
- package/dist/lib/flink/FlinkSqlLexer.js +2504 -2489
- package/dist/lib/flink/FlinkSqlParser.d.ts +616 -464
- package/dist/lib/flink/FlinkSqlParser.js +4969 -3315
- package/dist/lib/flink/FlinkSqlParserListener.d.ts +90 -0
- package/dist/lib/flink/FlinkSqlParserVisitor.d.ts +57 -0
- package/dist/lib/index.d.ts +0 -2
- package/dist/lib/index.js +0 -2
- package/dist/parser/common/basicSQL.d.ts +12 -0
- package/dist/parser/common/basicSQL.js +71 -0
- package/dist/parser/index.d.ts +0 -1
- package/dist/parser/index.js +0 -1
- package/package.json +1 -1
- package/dist/lib/generic/GenericSqlLexer.d.ts +0 -143
- package/dist/lib/generic/GenericSqlLexer.js +0 -603
- package/dist/lib/generic/GenericSqlListener.d.ts +0 -1089
- package/dist/lib/generic/GenericSqlListener.js +0 -11
- package/dist/lib/generic/GenericSqlParser.d.ts +0 -1272
- package/dist/lib/generic/GenericSqlParser.js +0 -7641
- package/dist/lib/generic/GenericSqlVisitor.d.ts +0 -684
- package/dist/lib/generic/GenericSqlVisitor.js +0 -12
- package/dist/parser/generic/genericEntityCollector.d.ts +0 -29
- package/dist/parser/generic/genericEntityCollector.js +0 -103
- package/dist/parser/generic/genericErrorListener.d.ts +0 -6
- package/dist/parser/generic/genericErrorListener.js +0 -56
- package/dist/parser/generic/genericSemanticContextCollector.d.ts +0 -9
- package/dist/parser/generic/genericSemanticContextCollector.js +0 -14
- package/dist/parser/generic/genericSplitListener.d.ts +0 -6
- package/dist/parser/generic/genericSplitListener.js +0 -6
- package/dist/parser/generic/index.d.ts +0 -33
- package/dist/parser/generic/index.js +0 -94
|
@@ -138,6 +138,8 @@ import { AfterMatchStrategyContext } from "./FlinkSqlParser.js";
|
|
|
138
138
|
import { PatternVariablesDefinitionContext } from "./FlinkSqlParser.js";
|
|
139
139
|
import { WindowFrameContext } from "./FlinkSqlParser.js";
|
|
140
140
|
import { FrameBoundContext } from "./FlinkSqlParser.js";
|
|
141
|
+
import { FrameStartContext } from "./FlinkSqlParser.js";
|
|
142
|
+
import { FrameEndContext } from "./FlinkSqlParser.js";
|
|
141
143
|
import { WithinClauseContext } from "./FlinkSqlParser.js";
|
|
142
144
|
import { ExpressionContext } from "./FlinkSqlParser.js";
|
|
143
145
|
import { LogicalNotContext } from "./FlinkSqlParser.js";
|
|
@@ -146,6 +148,7 @@ import { ExistsContext } from "./FlinkSqlParser.js";
|
|
|
146
148
|
import { LogicalNestedContext } from "./FlinkSqlParser.js";
|
|
147
149
|
import { LogicalBinaryContext } from "./FlinkSqlParser.js";
|
|
148
150
|
import { PredicateContext } from "./FlinkSqlParser.js";
|
|
151
|
+
import { JsonFunctionBranchContext } from "./FlinkSqlParser.js";
|
|
149
152
|
import { LikePredicateContext } from "./FlinkSqlParser.js";
|
|
150
153
|
import { ValueExpressionDefaultContext } from "./FlinkSqlParser.js";
|
|
151
154
|
import { ComparisonContext } from "./FlinkSqlParser.js";
|
|
@@ -162,6 +165,7 @@ import { SubqueryExpressionContext } from "./FlinkSqlParser.js";
|
|
|
162
165
|
import { CastContext } from "./FlinkSqlParser.js";
|
|
163
166
|
import { ConstantDefaultContext } from "./FlinkSqlParser.js";
|
|
164
167
|
import { ParenthesizedExpressionContext } from "./FlinkSqlParser.js";
|
|
168
|
+
import { ExtractContext } from "./FlinkSqlParser.js";
|
|
165
169
|
import { FunctionCallContext } from "./FlinkSqlParser.js";
|
|
166
170
|
import { SearchedCaseContext } from "./FlinkSqlParser.js";
|
|
167
171
|
import { PositionContext } from "./FlinkSqlParser.js";
|
|
@@ -171,6 +175,10 @@ import { FunctionNameContext } from "./FlinkSqlParser.js";
|
|
|
171
175
|
import { FunctionNameAndParamsContext } from "./FlinkSqlParser.js";
|
|
172
176
|
import { FunctionNameWithParamsContext } from "./FlinkSqlParser.js";
|
|
173
177
|
import { FunctionParamContext } from "./FlinkSqlParser.js";
|
|
178
|
+
import { JsonValueParamsContext } from "./FlinkSqlParser.js";
|
|
179
|
+
import { JsonQueryParamsContext } from "./FlinkSqlParser.js";
|
|
180
|
+
import { JsonObjectParamsContext } from "./FlinkSqlParser.js";
|
|
181
|
+
import { JsonArrayParamsContext } from "./FlinkSqlParser.js";
|
|
174
182
|
import { DereferenceDefinitionContext } from "./FlinkSqlParser.js";
|
|
175
183
|
import { CorrelationNameContext } from "./FlinkSqlParser.js";
|
|
176
184
|
import { QualifiedNameContext } from "./FlinkSqlParser.js";
|
|
@@ -1625,6 +1633,26 @@ export declare class FlinkSqlParserListener implements ParseTreeListener {
|
|
|
1625
1633
|
* @param ctx the parse tree
|
|
1626
1634
|
*/
|
|
1627
1635
|
exitFrameBound?: (ctx: FrameBoundContext) => void;
|
|
1636
|
+
/**
|
|
1637
|
+
* Enter a parse tree produced by `FlinkSqlParser.frameStart`.
|
|
1638
|
+
* @param ctx the parse tree
|
|
1639
|
+
*/
|
|
1640
|
+
enterFrameStart?: (ctx: FrameStartContext) => void;
|
|
1641
|
+
/**
|
|
1642
|
+
* Exit a parse tree produced by `FlinkSqlParser.frameStart`.
|
|
1643
|
+
* @param ctx the parse tree
|
|
1644
|
+
*/
|
|
1645
|
+
exitFrameStart?: (ctx: FrameStartContext) => void;
|
|
1646
|
+
/**
|
|
1647
|
+
* Enter a parse tree produced by `FlinkSqlParser.frameEnd`.
|
|
1648
|
+
* @param ctx the parse tree
|
|
1649
|
+
*/
|
|
1650
|
+
enterFrameEnd?: (ctx: FrameEndContext) => void;
|
|
1651
|
+
/**
|
|
1652
|
+
* Exit a parse tree produced by `FlinkSqlParser.frameEnd`.
|
|
1653
|
+
* @param ctx the parse tree
|
|
1654
|
+
*/
|
|
1655
|
+
exitFrameEnd?: (ctx: FrameEndContext) => void;
|
|
1628
1656
|
/**
|
|
1629
1657
|
* Enter a parse tree produced by `FlinkSqlParser.withinClause`.
|
|
1630
1658
|
* @param ctx the parse tree
|
|
@@ -1715,6 +1743,16 @@ export declare class FlinkSqlParserListener implements ParseTreeListener {
|
|
|
1715
1743
|
* @param ctx the parse tree
|
|
1716
1744
|
*/
|
|
1717
1745
|
exitPredicate?: (ctx: PredicateContext) => void;
|
|
1746
|
+
/**
|
|
1747
|
+
* Enter a parse tree produced by `FlinkSqlParser.jsonFunctionBranch`.
|
|
1748
|
+
* @param ctx the parse tree
|
|
1749
|
+
*/
|
|
1750
|
+
enterJsonFunctionBranch?: (ctx: JsonFunctionBranchContext) => void;
|
|
1751
|
+
/**
|
|
1752
|
+
* Exit a parse tree produced by `FlinkSqlParser.jsonFunctionBranch`.
|
|
1753
|
+
* @param ctx the parse tree
|
|
1754
|
+
*/
|
|
1755
|
+
exitJsonFunctionBranch?: (ctx: JsonFunctionBranchContext) => void;
|
|
1718
1756
|
/**
|
|
1719
1757
|
* Enter a parse tree produced by `FlinkSqlParser.likePredicate`.
|
|
1720
1758
|
* @param ctx the parse tree
|
|
@@ -1903,6 +1941,18 @@ export declare class FlinkSqlParserListener implements ParseTreeListener {
|
|
|
1903
1941
|
* @param ctx the parse tree
|
|
1904
1942
|
*/
|
|
1905
1943
|
exitParenthesizedExpression?: (ctx: ParenthesizedExpressionContext) => void;
|
|
1944
|
+
/**
|
|
1945
|
+
* Enter a parse tree produced by the `extract`
|
|
1946
|
+
* labeled alternative in `FlinkSqlParser.primaryExpression`.
|
|
1947
|
+
* @param ctx the parse tree
|
|
1948
|
+
*/
|
|
1949
|
+
enterExtract?: (ctx: ExtractContext) => void;
|
|
1950
|
+
/**
|
|
1951
|
+
* Exit a parse tree produced by the `extract`
|
|
1952
|
+
* labeled alternative in `FlinkSqlParser.primaryExpression`.
|
|
1953
|
+
* @param ctx the parse tree
|
|
1954
|
+
*/
|
|
1955
|
+
exitExtract?: (ctx: ExtractContext) => void;
|
|
1906
1956
|
/**
|
|
1907
1957
|
* Enter a parse tree produced by the `functionCall`
|
|
1908
1958
|
* labeled alternative in `FlinkSqlParser.primaryExpression`.
|
|
@@ -2001,6 +2051,46 @@ export declare class FlinkSqlParserListener implements ParseTreeListener {
|
|
|
2001
2051
|
* @param ctx the parse tree
|
|
2002
2052
|
*/
|
|
2003
2053
|
exitFunctionParam?: (ctx: FunctionParamContext) => void;
|
|
2054
|
+
/**
|
|
2055
|
+
* Enter a parse tree produced by `FlinkSqlParser.jsonValueParams`.
|
|
2056
|
+
* @param ctx the parse tree
|
|
2057
|
+
*/
|
|
2058
|
+
enterJsonValueParams?: (ctx: JsonValueParamsContext) => void;
|
|
2059
|
+
/**
|
|
2060
|
+
* Exit a parse tree produced by `FlinkSqlParser.jsonValueParams`.
|
|
2061
|
+
* @param ctx the parse tree
|
|
2062
|
+
*/
|
|
2063
|
+
exitJsonValueParams?: (ctx: JsonValueParamsContext) => void;
|
|
2064
|
+
/**
|
|
2065
|
+
* Enter a parse tree produced by `FlinkSqlParser.jsonQueryParams`.
|
|
2066
|
+
* @param ctx the parse tree
|
|
2067
|
+
*/
|
|
2068
|
+
enterJsonQueryParams?: (ctx: JsonQueryParamsContext) => void;
|
|
2069
|
+
/**
|
|
2070
|
+
* Exit a parse tree produced by `FlinkSqlParser.jsonQueryParams`.
|
|
2071
|
+
* @param ctx the parse tree
|
|
2072
|
+
*/
|
|
2073
|
+
exitJsonQueryParams?: (ctx: JsonQueryParamsContext) => void;
|
|
2074
|
+
/**
|
|
2075
|
+
* Enter a parse tree produced by `FlinkSqlParser.jsonObjectParams`.
|
|
2076
|
+
* @param ctx the parse tree
|
|
2077
|
+
*/
|
|
2078
|
+
enterJsonObjectParams?: (ctx: JsonObjectParamsContext) => void;
|
|
2079
|
+
/**
|
|
2080
|
+
* Exit a parse tree produced by `FlinkSqlParser.jsonObjectParams`.
|
|
2081
|
+
* @param ctx the parse tree
|
|
2082
|
+
*/
|
|
2083
|
+
exitJsonObjectParams?: (ctx: JsonObjectParamsContext) => void;
|
|
2084
|
+
/**
|
|
2085
|
+
* Enter a parse tree produced by `FlinkSqlParser.jsonArrayParams`.
|
|
2086
|
+
* @param ctx the parse tree
|
|
2087
|
+
*/
|
|
2088
|
+
enterJsonArrayParams?: (ctx: JsonArrayParamsContext) => void;
|
|
2089
|
+
/**
|
|
2090
|
+
* Exit a parse tree produced by `FlinkSqlParser.jsonArrayParams`.
|
|
2091
|
+
* @param ctx the parse tree
|
|
2092
|
+
*/
|
|
2093
|
+
exitJsonArrayParams?: (ctx: JsonArrayParamsContext) => void;
|
|
2004
2094
|
/**
|
|
2005
2095
|
* Enter a parse tree produced by `FlinkSqlParser.dereferenceDefinition`.
|
|
2006
2096
|
* @param ctx the parse tree
|
|
@@ -138,6 +138,8 @@ import { AfterMatchStrategyContext } from "./FlinkSqlParser.js";
|
|
|
138
138
|
import { PatternVariablesDefinitionContext } from "./FlinkSqlParser.js";
|
|
139
139
|
import { WindowFrameContext } from "./FlinkSqlParser.js";
|
|
140
140
|
import { FrameBoundContext } from "./FlinkSqlParser.js";
|
|
141
|
+
import { FrameStartContext } from "./FlinkSqlParser.js";
|
|
142
|
+
import { FrameEndContext } from "./FlinkSqlParser.js";
|
|
141
143
|
import { WithinClauseContext } from "./FlinkSqlParser.js";
|
|
142
144
|
import { ExpressionContext } from "./FlinkSqlParser.js";
|
|
143
145
|
import { LogicalNotContext } from "./FlinkSqlParser.js";
|
|
@@ -146,6 +148,7 @@ import { ExistsContext } from "./FlinkSqlParser.js";
|
|
|
146
148
|
import { LogicalNestedContext } from "./FlinkSqlParser.js";
|
|
147
149
|
import { LogicalBinaryContext } from "./FlinkSqlParser.js";
|
|
148
150
|
import { PredicateContext } from "./FlinkSqlParser.js";
|
|
151
|
+
import { JsonFunctionBranchContext } from "./FlinkSqlParser.js";
|
|
149
152
|
import { LikePredicateContext } from "./FlinkSqlParser.js";
|
|
150
153
|
import { ValueExpressionDefaultContext } from "./FlinkSqlParser.js";
|
|
151
154
|
import { ComparisonContext } from "./FlinkSqlParser.js";
|
|
@@ -162,6 +165,7 @@ import { SubqueryExpressionContext } from "./FlinkSqlParser.js";
|
|
|
162
165
|
import { CastContext } from "./FlinkSqlParser.js";
|
|
163
166
|
import { ConstantDefaultContext } from "./FlinkSqlParser.js";
|
|
164
167
|
import { ParenthesizedExpressionContext } from "./FlinkSqlParser.js";
|
|
168
|
+
import { ExtractContext } from "./FlinkSqlParser.js";
|
|
165
169
|
import { FunctionCallContext } from "./FlinkSqlParser.js";
|
|
166
170
|
import { SearchedCaseContext } from "./FlinkSqlParser.js";
|
|
167
171
|
import { PositionContext } from "./FlinkSqlParser.js";
|
|
@@ -171,6 +175,10 @@ import { FunctionNameContext } from "./FlinkSqlParser.js";
|
|
|
171
175
|
import { FunctionNameAndParamsContext } from "./FlinkSqlParser.js";
|
|
172
176
|
import { FunctionNameWithParamsContext } from "./FlinkSqlParser.js";
|
|
173
177
|
import { FunctionParamContext } from "./FlinkSqlParser.js";
|
|
178
|
+
import { JsonValueParamsContext } from "./FlinkSqlParser.js";
|
|
179
|
+
import { JsonQueryParamsContext } from "./FlinkSqlParser.js";
|
|
180
|
+
import { JsonObjectParamsContext } from "./FlinkSqlParser.js";
|
|
181
|
+
import { JsonArrayParamsContext } from "./FlinkSqlParser.js";
|
|
174
182
|
import { DereferenceDefinitionContext } from "./FlinkSqlParser.js";
|
|
175
183
|
import { CorrelationNameContext } from "./FlinkSqlParser.js";
|
|
176
184
|
import { QualifiedNameContext } from "./FlinkSqlParser.js";
|
|
@@ -1070,6 +1078,18 @@ export declare class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisi
|
|
|
1070
1078
|
* @return the visitor result
|
|
1071
1079
|
*/
|
|
1072
1080
|
visitFrameBound?: (ctx: FrameBoundContext) => Result;
|
|
1081
|
+
/**
|
|
1082
|
+
* Visit a parse tree produced by `FlinkSqlParser.frameStart`.
|
|
1083
|
+
* @param ctx the parse tree
|
|
1084
|
+
* @return the visitor result
|
|
1085
|
+
*/
|
|
1086
|
+
visitFrameStart?: (ctx: FrameStartContext) => Result;
|
|
1087
|
+
/**
|
|
1088
|
+
* Visit a parse tree produced by `FlinkSqlParser.frameEnd`.
|
|
1089
|
+
* @param ctx the parse tree
|
|
1090
|
+
* @return the visitor result
|
|
1091
|
+
*/
|
|
1092
|
+
visitFrameEnd?: (ctx: FrameEndContext) => Result;
|
|
1073
1093
|
/**
|
|
1074
1094
|
* Visit a parse tree produced by `FlinkSqlParser.withinClause`.
|
|
1075
1095
|
* @param ctx the parse tree
|
|
@@ -1123,6 +1143,12 @@ export declare class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisi
|
|
|
1123
1143
|
* @return the visitor result
|
|
1124
1144
|
*/
|
|
1125
1145
|
visitPredicate?: (ctx: PredicateContext) => Result;
|
|
1146
|
+
/**
|
|
1147
|
+
* Visit a parse tree produced by `FlinkSqlParser.jsonFunctionBranch`.
|
|
1148
|
+
* @param ctx the parse tree
|
|
1149
|
+
* @return the visitor result
|
|
1150
|
+
*/
|
|
1151
|
+
visitJsonFunctionBranch?: (ctx: JsonFunctionBranchContext) => Result;
|
|
1126
1152
|
/**
|
|
1127
1153
|
* Visit a parse tree produced by `FlinkSqlParser.likePredicate`.
|
|
1128
1154
|
* @param ctx the parse tree
|
|
@@ -1233,6 +1259,13 @@ export declare class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisi
|
|
|
1233
1259
|
* @return the visitor result
|
|
1234
1260
|
*/
|
|
1235
1261
|
visitParenthesizedExpression?: (ctx: ParenthesizedExpressionContext) => Result;
|
|
1262
|
+
/**
|
|
1263
|
+
* Visit a parse tree produced by the `extract`
|
|
1264
|
+
* labeled alternative in `FlinkSqlParser.primaryExpression`.
|
|
1265
|
+
* @param ctx the parse tree
|
|
1266
|
+
* @return the visitor result
|
|
1267
|
+
*/
|
|
1268
|
+
visitExtract?: (ctx: ExtractContext) => Result;
|
|
1236
1269
|
/**
|
|
1237
1270
|
* Visit a parse tree produced by the `functionCall`
|
|
1238
1271
|
* labeled alternative in `FlinkSqlParser.primaryExpression`.
|
|
@@ -1291,6 +1324,30 @@ export declare class FlinkSqlParserVisitor<Result> extends AbstractParseTreeVisi
|
|
|
1291
1324
|
* @return the visitor result
|
|
1292
1325
|
*/
|
|
1293
1326
|
visitFunctionParam?: (ctx: FunctionParamContext) => Result;
|
|
1327
|
+
/**
|
|
1328
|
+
* Visit a parse tree produced by `FlinkSqlParser.jsonValueParams`.
|
|
1329
|
+
* @param ctx the parse tree
|
|
1330
|
+
* @return the visitor result
|
|
1331
|
+
*/
|
|
1332
|
+
visitJsonValueParams?: (ctx: JsonValueParamsContext) => Result;
|
|
1333
|
+
/**
|
|
1334
|
+
* Visit a parse tree produced by `FlinkSqlParser.jsonQueryParams`.
|
|
1335
|
+
* @param ctx the parse tree
|
|
1336
|
+
* @return the visitor result
|
|
1337
|
+
*/
|
|
1338
|
+
visitJsonQueryParams?: (ctx: JsonQueryParamsContext) => Result;
|
|
1339
|
+
/**
|
|
1340
|
+
* Visit a parse tree produced by `FlinkSqlParser.jsonObjectParams`.
|
|
1341
|
+
* @param ctx the parse tree
|
|
1342
|
+
* @return the visitor result
|
|
1343
|
+
*/
|
|
1344
|
+
visitJsonObjectParams?: (ctx: JsonObjectParamsContext) => Result;
|
|
1345
|
+
/**
|
|
1346
|
+
* Visit a parse tree produced by `FlinkSqlParser.jsonArrayParams`.
|
|
1347
|
+
* @param ctx the parse tree
|
|
1348
|
+
* @return the visitor result
|
|
1349
|
+
*/
|
|
1350
|
+
visitJsonArrayParams?: (ctx: JsonArrayParamsContext) => Result;
|
|
1294
1351
|
/**
|
|
1295
1352
|
* Visit a parse tree produced by `FlinkSqlParser.dereferenceDefinition`.
|
|
1296
1353
|
* @param ctx the parse tree
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -12,5 +12,3 @@ export { TrinoSqlListener } from './trino/TrinoSqlListener';
|
|
|
12
12
|
export { TrinoSqlVisitor } from './trino/TrinoSqlVisitor';
|
|
13
13
|
export { ImpalaSqlParserListener } from './impala/ImpalaSqlParserListener';
|
|
14
14
|
export { ImpalaSqlParserVisitor } from './impala/ImpalaSqlParserVisitor';
|
|
15
|
-
export { GenericSqlListener } from './generic/GenericSqlListener';
|
|
16
|
-
export { GenericSqlVisitor } from './generic/GenericSqlVisitor';
|
package/dist/lib/index.js
CHANGED
|
@@ -12,5 +12,3 @@ export { TrinoSqlListener } from './trino/TrinoSqlListener';
|
|
|
12
12
|
export { TrinoSqlVisitor } from './trino/TrinoSqlVisitor';
|
|
13
13
|
export { ImpalaSqlParserListener } from './impala/ImpalaSqlParserListener';
|
|
14
14
|
export { ImpalaSqlParserVisitor } from './impala/ImpalaSqlParserVisitor';
|
|
15
|
-
export { GenericSqlListener } from './generic/GenericSqlListener';
|
|
16
|
-
export { GenericSqlVisitor } from './generic/GenericSqlVisitor';
|
|
@@ -95,10 +95,22 @@ export declare abstract class BasicSQL<L extends Lexer = Lexer, PRC extends Pars
|
|
|
95
95
|
private parseWithCache;
|
|
96
96
|
/**
|
|
97
97
|
* Validate input string and return syntax errors if exists.
|
|
98
|
+
* When input contains multiple statements separated by semicolons
|
|
99
|
+
* and the initial parse doesn't capture all errors, each statement
|
|
100
|
+
* is validated independently to collect all errors.
|
|
98
101
|
* @param input source string
|
|
99
102
|
* @returns syntax errors
|
|
100
103
|
*/
|
|
101
104
|
validate(input: string): ParseError[];
|
|
105
|
+
/**
|
|
106
|
+
* Validate each statement fragment independently and collect all errors.
|
|
107
|
+
*/
|
|
108
|
+
private validateStatements;
|
|
109
|
+
/**
|
|
110
|
+
* Split input into individual statement strings by semicolons.
|
|
111
|
+
* Handles semicolons inside quoted strings correctly.
|
|
112
|
+
*/
|
|
113
|
+
private splitStatements;
|
|
102
114
|
/**
|
|
103
115
|
* Get the input string that has been parsed.
|
|
104
116
|
*/
|
|
@@ -104,13 +104,84 @@ export class BasicSQL {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Validate input string and return syntax errors if exists.
|
|
107
|
+
* When input contains multiple statements separated by semicolons
|
|
108
|
+
* and the initial parse doesn't capture all errors, each statement
|
|
109
|
+
* is validated independently to collect all errors.
|
|
107
110
|
* @param input source string
|
|
108
111
|
* @returns syntax errors
|
|
109
112
|
*/
|
|
110
113
|
validate(input) {
|
|
111
114
|
this.parseWithCache(input);
|
|
115
|
+
if (this._parseErrors.length > 0) {
|
|
116
|
+
const statements = this.splitStatements(input);
|
|
117
|
+
if (statements.length > 1) {
|
|
118
|
+
const splitErrors = this.validateStatements(statements);
|
|
119
|
+
if (splitErrors.length > this._parseErrors.length) {
|
|
120
|
+
this._parseErrors = splitErrors;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
112
124
|
return this._parseErrors;
|
|
113
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Validate each statement fragment independently and collect all errors.
|
|
128
|
+
*/
|
|
129
|
+
validateStatements(statements) {
|
|
130
|
+
const allErrors = [];
|
|
131
|
+
let lineOffset = 0;
|
|
132
|
+
for (const statement of statements) {
|
|
133
|
+
if (!statement.text.trim()) {
|
|
134
|
+
const newlines = (statement.text.match(/\n/g) || []).length;
|
|
135
|
+
lineOffset += newlines;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const parser = this.createParser(statement.text);
|
|
139
|
+
const errors = [];
|
|
140
|
+
parser.removeErrorListeners();
|
|
141
|
+
parser.addErrorListener(this.createErrorListener((error) => {
|
|
142
|
+
errors.push({
|
|
143
|
+
startLine: error.startLine + lineOffset,
|
|
144
|
+
endLine: error.endLine + lineOffset,
|
|
145
|
+
startColumn: error.startColumn,
|
|
146
|
+
endColumn: error.endColumn,
|
|
147
|
+
message: error.message,
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
parser.errorHandler = new ErrorStrategy();
|
|
151
|
+
parser.program();
|
|
152
|
+
allErrors.push(...errors);
|
|
153
|
+
const newlines = (statement.text.match(/\n/g) || []).length;
|
|
154
|
+
lineOffset += newlines;
|
|
155
|
+
}
|
|
156
|
+
return allErrors;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Split input into individual statement strings by semicolons.
|
|
160
|
+
* Handles semicolons inside quoted strings correctly.
|
|
161
|
+
*/
|
|
162
|
+
splitStatements(input) {
|
|
163
|
+
const statements = [];
|
|
164
|
+
let inSingleQuote = false;
|
|
165
|
+
let inDoubleQuote = false;
|
|
166
|
+
let lastSplit = 0;
|
|
167
|
+
for (let i = 0; i < input.length; i++) {
|
|
168
|
+
const ch = input[i];
|
|
169
|
+
if (ch === "'" && !inDoubleQuote) {
|
|
170
|
+
inSingleQuote = !inSingleQuote;
|
|
171
|
+
}
|
|
172
|
+
else if (ch === '"' && !inSingleQuote) {
|
|
173
|
+
inDoubleQuote = !inDoubleQuote;
|
|
174
|
+
}
|
|
175
|
+
else if (ch === ';' && !inSingleQuote && !inDoubleQuote) {
|
|
176
|
+
statements.push({ text: input.slice(lastSplit, i + 1), start: lastSplit });
|
|
177
|
+
lastSplit = i + 1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (lastSplit < input.length) {
|
|
181
|
+
statements.push({ text: input.slice(lastSplit), start: lastSplit });
|
|
182
|
+
}
|
|
183
|
+
return statements;
|
|
184
|
+
}
|
|
114
185
|
/**
|
|
115
186
|
* Get the input string that has been parsed.
|
|
116
187
|
*/
|
package/dist/parser/index.d.ts
CHANGED
package/dist/parser/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import * as antlr from "antlr4ng";
|
|
2
|
-
export declare class GenericSqlLexer extends antlr.Lexer {
|
|
3
|
-
static readonly T__0 = 1;
|
|
4
|
-
static readonly T__1 = 2;
|
|
5
|
-
static readonly T__2 = 3;
|
|
6
|
-
static readonly T__3 = 4;
|
|
7
|
-
static readonly KW_ADD = 5;
|
|
8
|
-
static readonly KW_ALL = 6;
|
|
9
|
-
static readonly KW_ALTER = 7;
|
|
10
|
-
static readonly KW_AND = 8;
|
|
11
|
-
static readonly KW_AS = 9;
|
|
12
|
-
static readonly KW_ASC = 10;
|
|
13
|
-
static readonly KW_BETWEEN = 11;
|
|
14
|
-
static readonly KW_BIGINT = 12;
|
|
15
|
-
static readonly KW_BINARY = 13;
|
|
16
|
-
static readonly KW_BOOLEAN = 14;
|
|
17
|
-
static readonly KW_BY = 15;
|
|
18
|
-
static readonly KW_CASE = 16;
|
|
19
|
-
static readonly KW_CAST = 17;
|
|
20
|
-
static readonly KW_CHAR = 18;
|
|
21
|
-
static readonly KW_CHECK = 19;
|
|
22
|
-
static readonly KW_COALESCE = 20;
|
|
23
|
-
static readonly KW_COLUMN = 21;
|
|
24
|
-
static readonly KW_CONSTRAINT = 22;
|
|
25
|
-
static readonly KW_CREATE = 23;
|
|
26
|
-
static readonly KW_CROSS = 24;
|
|
27
|
-
static readonly KW_DATE = 25;
|
|
28
|
-
static readonly KW_DECIMAL = 26;
|
|
29
|
-
static readonly KW_DEFAULT = 27;
|
|
30
|
-
static readonly KW_DELETE = 28;
|
|
31
|
-
static readonly KW_DESC = 29;
|
|
32
|
-
static readonly KW_DISTINCT = 30;
|
|
33
|
-
static readonly KW_DOUBLE = 31;
|
|
34
|
-
static readonly KW_DROP = 32;
|
|
35
|
-
static readonly KW_ELSE = 33;
|
|
36
|
-
static readonly KW_END = 34;
|
|
37
|
-
static readonly KW_ESCAPE = 35;
|
|
38
|
-
static readonly KW_EXCEPT = 36;
|
|
39
|
-
static readonly KW_EXISTS = 37;
|
|
40
|
-
static readonly KW_FALSE = 38;
|
|
41
|
-
static readonly KW_FIRST = 39;
|
|
42
|
-
static readonly KW_FLOAT = 40;
|
|
43
|
-
static readonly KW_FOREIGN = 41;
|
|
44
|
-
static readonly KW_FROM = 42;
|
|
45
|
-
static readonly KW_FULL = 43;
|
|
46
|
-
static readonly KW_GROUP = 44;
|
|
47
|
-
static readonly KW_HAVING = 45;
|
|
48
|
-
static readonly KW_IF = 46;
|
|
49
|
-
static readonly KW_IN = 47;
|
|
50
|
-
static readonly KW_INNER = 48;
|
|
51
|
-
static readonly KW_INSERT = 49;
|
|
52
|
-
static readonly KW_INT = 50;
|
|
53
|
-
static readonly KW_INTEGER = 51;
|
|
54
|
-
static readonly KW_INTERSECT = 52;
|
|
55
|
-
static readonly KW_INTO = 53;
|
|
56
|
-
static readonly KW_IS = 54;
|
|
57
|
-
static readonly KW_JOIN = 55;
|
|
58
|
-
static readonly KW_KEY = 56;
|
|
59
|
-
static readonly KW_LAST = 57;
|
|
60
|
-
static readonly KW_LEFT = 58;
|
|
61
|
-
static readonly KW_LIKE = 59;
|
|
62
|
-
static readonly KW_LIMIT = 60;
|
|
63
|
-
static readonly KW_NOT = 61;
|
|
64
|
-
static readonly KW_NULL = 62;
|
|
65
|
-
static readonly KW_NULLIF = 63;
|
|
66
|
-
static readonly KW_NULLS = 64;
|
|
67
|
-
static readonly KW_NUMERIC = 65;
|
|
68
|
-
static readonly KW_OFFSET = 66;
|
|
69
|
-
static readonly KW_ON = 67;
|
|
70
|
-
static readonly KW_OR = 68;
|
|
71
|
-
static readonly KW_ORDER = 69;
|
|
72
|
-
static readonly KW_OUTER = 70;
|
|
73
|
-
static readonly KW_PRIMARY = 71;
|
|
74
|
-
static readonly KW_RECURSIVE = 72;
|
|
75
|
-
static readonly KW_REFERENCES = 73;
|
|
76
|
-
static readonly KW_RENAME = 74;
|
|
77
|
-
static readonly KW_RIGHT = 75;
|
|
78
|
-
static readonly KW_SELECT = 76;
|
|
79
|
-
static readonly KW_SET = 77;
|
|
80
|
-
static readonly KW_SMALLINT = 78;
|
|
81
|
-
static readonly KW_TABLE = 79;
|
|
82
|
-
static readonly KW_TEXT = 80;
|
|
83
|
-
static readonly KW_THEN = 81;
|
|
84
|
-
static readonly KW_TIME = 82;
|
|
85
|
-
static readonly KW_TIMESTAMP = 83;
|
|
86
|
-
static readonly KW_TINYINT = 84;
|
|
87
|
-
static readonly KW_TO = 85;
|
|
88
|
-
static readonly KW_TRUE = 86;
|
|
89
|
-
static readonly KW_UNION = 87;
|
|
90
|
-
static readonly KW_UNIQUE = 88;
|
|
91
|
-
static readonly KW_UPDATE = 89;
|
|
92
|
-
static readonly KW_VARCHAR = 90;
|
|
93
|
-
static readonly KW_VARBINARY = 91;
|
|
94
|
-
static readonly KW_WHEN = 92;
|
|
95
|
-
static readonly KW_WHERE = 93;
|
|
96
|
-
static readonly KW_WITH = 94;
|
|
97
|
-
static readonly EQ = 95;
|
|
98
|
-
static readonly NEQ = 96;
|
|
99
|
-
static readonly LT = 97;
|
|
100
|
-
static readonly LTE = 98;
|
|
101
|
-
static readonly GT = 99;
|
|
102
|
-
static readonly GTE = 100;
|
|
103
|
-
static readonly PLUS = 101;
|
|
104
|
-
static readonly MINUS = 102;
|
|
105
|
-
static readonly ASTERISK = 103;
|
|
106
|
-
static readonly SLASH = 104;
|
|
107
|
-
static readonly PERCENT = 105;
|
|
108
|
-
static readonly CONCAT = 106;
|
|
109
|
-
static readonly QUESTION_MARK = 107;
|
|
110
|
-
static readonly SEMICOLON = 108;
|
|
111
|
-
static readonly STRING = 109;
|
|
112
|
-
static readonly BINARY_LITERAL = 110;
|
|
113
|
-
static readonly INTEGER_VALUE = 111;
|
|
114
|
-
static readonly DECIMAL_VALUE = 112;
|
|
115
|
-
static readonly DOUBLE_VALUE = 113;
|
|
116
|
-
static readonly IDENTIFIER = 114;
|
|
117
|
-
static readonly DIGIT_IDENTIFIER = 115;
|
|
118
|
-
static readonly QUOTED_IDENTIFIER = 116;
|
|
119
|
-
static readonly BACKQUOTED_IDENTIFIER = 117;
|
|
120
|
-
static readonly LINE_COMMENT = 118;
|
|
121
|
-
static readonly BRACKETED_COMMENT = 119;
|
|
122
|
-
static readonly WHITE_SPACE = 120;
|
|
123
|
-
static readonly UNRECOGNIZED = 121;
|
|
124
|
-
static readonly channelNames: string[];
|
|
125
|
-
static readonly literalNames: (string | null)[];
|
|
126
|
-
static readonly symbolicNames: (string | null)[];
|
|
127
|
-
static readonly modeNames: string[];
|
|
128
|
-
static readonly ruleNames: string[];
|
|
129
|
-
constructor(input: antlr.CharStream);
|
|
130
|
-
get grammarFileName(): string;
|
|
131
|
-
get literalNames(): (string | null)[];
|
|
132
|
-
get symbolicNames(): (string | null)[];
|
|
133
|
-
get ruleNames(): string[];
|
|
134
|
-
get serializedATN(): number[];
|
|
135
|
-
get channelNames(): string[];
|
|
136
|
-
get modeNames(): string[];
|
|
137
|
-
static readonly _serializedATN: number[];
|
|
138
|
-
private static __ATN;
|
|
139
|
-
static get _ATN(): antlr.ATN;
|
|
140
|
-
private static readonly vocabulary;
|
|
141
|
-
get vocabulary(): antlr.Vocabulary;
|
|
142
|
-
private static readonly decisionsToDFA;
|
|
143
|
-
}
|