feat: add generic and plsql basic parser file

This commit is contained in:
xiaowei
2020-09-11 17:39:10 +08:00
parent 68800312d3
commit f85163892a
83 changed files with 326433 additions and 155590 deletions

File diff suppressed because one or more lines are too long

9901
src/lib/generic/SqlLexer.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

87886
src/lib/generic/SqlParser.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

985
src/lib/hive/HiveSql.interp Normal file

File diff suppressed because one or more lines are too long

384
src/lib/hive/HiveSql.tokens Normal file
View File

@ -0,0 +1,384 @@
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
T__5=6
T__6=7
T__7=8
T__8=9
T__9=10
T_GO=11
T_BEGIN=12
T_SEMICOLON=13
T_END=14
T_EXCEPTION=15
T_WHEN=16
L_ID=17
T_THEN=18
T_NULL=19
T_SET=20
T_COMMA=21
T_COLON=22
T_EQUAL=23
T_OPEN_P=24
T_CLOSE_P=25
T_ALLOCATE=26
T_CURSOR=27
T_FOR=28
T_RESULT=29
T_PROCEDURE=30
T_ASSOCIATE=31
T_LOCATOR=32
T_LOCATORS=33
T_WITH=34
T_TRANSACTION=35
T_BREAK=36
T_CALL=37
T_DECLARE=38
T_AS=39
T_CONSTANT=40
T_CONDITION=41
T_IS=42
T_RETURN=43
T_ONLY=44
T_TO=45
T_CALLER=46
T_CLIENT=47
T_WITHOUT=48
T_CONTINUE=49
T_EXIT=50
T_HANDLER=51
T_SQLEXCEPTION=52
T_SQLWARNING=53
T_NOT=54
T_FOUND=55
T_GLOBAL=56
T_TEMPORARY=57
T_TABLE=58
T_CREATE=59
T_IF=60
T_EXISTS=61
T_LOCAL=62
T_MULTISET=63
T_VOLATILE=64
T_LIKE=65
T_CONSTRAINT=66
T_PRIMARY=67
T_KEY=68
T_UNIQUE=69
T_REFERENCES=70
T_IDENTITY=71
L_INT=72
T_AUTO_INCREMENT=73
T_ENABLE=74
T_CLUSTERED=75
T_ASC=76
T_DESC=77
T_FOREIGN=78
T_ON=79
T_UPDATE=80
T_DELETE=81
T_NO=82
T_ACTION=83
T_RESTRICT=84
T_DEFAULT=85
T_CASCADE=86
T_LOG=87
T_FALLBACK=88
T_COMMIT=89
T_PRESERVE=90
T_ROWS=91
T_SEGMENT=92
T_CREATION=93
T_IMMEDIATE=94
T_DEFERRED=95
T_PCTFREE=96
T_PCTUSED=97
T_INITRANS=98
T_MAXTRANS=99
T_NOCOMPRESS=100
T_LOGGING=101
T_NOLOGGING=102
T_STORAGE=103
T_TABLESPACE=104
T_INDEX=105
T_IN=106
T_REPLACE=107
T_DISTRIBUTE=108
T_BY=109
T_HASH=110
T_LOGGED=111
T_COMPRESS=112
T_YES=113
T_DEFINITION=114
T_DROP=115
T_DATA=116
T_STORED=117
T_ROW=118
T_FORMAT=119
T_DELIMITED=120
T_FIELDS=121
T_TERMINATED=122
T_ESCAPED=123
T_COLLECTION=124
T_ITEMS=125
T_MAP=126
T_KEYS=127
T_LINES=128
T_DEFINED=129
T_TEXTIMAGE_ON=130
T_COMMENT=131
T_CHARACTER=132
T_CHARSET=133
T_ENGINE=134
T_ALTER=135
T_ADD2=136
T_CHAR=137
T_BIGINT=138
T_BINARY_DOUBLE=139
T_BINARY_FLOAT=140
T_BINARY_INTEGER=141
T_BIT=142
T_DATE=143
T_DATETIME=144
T_DEC=145
T_DECIMAL=146
T_DOUBLE=147
T_PRECISION=148
T_FLOAT=149
T_INT=150
T_INT2=151
T_INT4=152
T_INT8=153
T_INTEGER=154
T_NCHAR=155
T_NVARCHAR=156
T_NUMBER=157
T_NUMERIC=158
T_PLS_INTEGER=159
T_REAL=160
T_RESULT_SET_LOCATOR=161
T_VARYING=162
T_SIMPLE_FLOAT=163
T_SIMPLE_DOUBLE=164
T_SIMPLE_INTEGER=165
T_SMALLINT=166
T_SMALLDATETIME=167
T_STRING=168
T_SYS_REFCURSOR=169
T_TIMESTAMP=170
T_TINYINT=171
T_VARCHAR=172
T_VARCHAR2=173
T_XML=174
T_TYPE=175
T_ROWTYPE=176
T_MAX=177
T_BYTE=178
T_CASESPECIFIC=179
T_CS=180
T_DATABASE=181
T_SCHEMA=182
T_LOCATION=183
T_OR=184
T_FUNCTION=185
T_RETURNS=186
T_PACKAGE=187
T_PROC=188
T_BODY=189
T_OUT=190
T_INOUT=191
T_LANGUAGE=192
T_SQL=193
T_SECURITY=194
T_CREATOR=195
T_DEFINER=196
T_INVOKER=197
T_OWNER=198
T_DYNAMIC=199
T_SETS=200
T_EXEC=201
T_EXECUTE=202
T_INTO=203
T_ELSE=204
T_ELSIF=205
T_ELSEIF=206
T_INCLUDE=207
T_INSERT=208
T_OVERWRITE=209
T_VALUES=210
T_DIRECTORY=211
T_GET=212
T_DIAGNOSTICS=213
T_MESSAGE_TEXT=214
T_ROW_COUNT=215
T_GRANT=216
T_ROLE=217
T_LEAVE=218
T_OBJECT=219
T_AT=220
T_OPEN=221
T_FETCH=222
T_FROM=223
T_COLLECT=224
T_STATISTICS=225
T_STATS=226
T_COLUMN=227
T_CLOSE=228
T_CMP=229
T_SUM=230
T_COPY=231
T_HDFS=232
T_BATCHSIZE=233
T_DELIMITER=234
T_SQLINSERT=235
T_IGNORE=236
T_WORK=237
T_PRINT=238
T_QUIT=239
T_RAISE=240
T_RESIGNAL=241
T_SQLSTATE=242
T_VALUE=243
T_ROLLBACK=244
T_CURRENT=245
T_CURRENT_SCHEMA=246
T_ANSI_NULLS=247
T_ANSI_PADDING=248
T_NOCOUNT=249
T_QUOTED_IDENTIFIER=250
T_XACT_ABORT=251
T_OFF=252
T_QUERY_BAND=253
T_NONE=254
T_SESSION=255
T_SIGNAL=256
T_SUMMARY=257
T_TOP=258
T_LIMIT=259
T_TRUNCATE=260
T_USE=261
T_WHILE=262
T_DO=263
T_LOOP=264
T_REVERSE=265
T_DOT2=266
T_STEP=267
L_LABEL=268
T_LESS=269
T_GREATER=270
T_USING=271
T_UNION=272
T_ALL=273
T_EXCEPT=274
T_INTERSECT=275
T_SELECT=276
T_SEL=277
T_DISTINCT=278
T_TITLE=279
L_S_STRING=280
T_INNER=281
T_JOIN=282
T_LEFT=283
T_RIGHT=284
T_FULL=285
T_OUTER=286
T_WHERE=287
T_GROUP=288
T_HAVING=289
T_QUALIFY=290
T_ORDER=291
T_RR=292
T_RS=293
T_UR=294
T_AND=295
T_KEEP=296
T_EXCLUSIVE=297
T_SHARE=298
T_LOCKS=299
T_MERGE=300
T_MATCHED=301
T_DESCRIBE=302
T_BETWEEN=303
T_EQUAL2=304
T_NOTEQUAL=305
T_NOTEQUAL2=306
T_LESSEQUAL=307
T_GREATEREQUAL=308
T_RLIKE=309
T_REGEXP=310
T_MUL=311
T_DIV=312
T_ADD=313
T_SUB=314
T_INTERVAL=315
T_DAY=316
T_DAYS=317
T_MICROSECOND=318
T_MICROSECONDS=319
T_SECOND=320
T_SECONDS=321
T_PIPE=322
T_CONCAT=323
T_CASE=324
T_ISOPEN=325
T_NOTFOUND=326
T_AVG=327
T_COUNT=328
T_COUNT_BIG=329
T_CUME_DIST=330
T_DENSE_RANK=331
T_FIRST_VALUE=332
T_LAG=333
T_LAST_VALUE=334
T_LEAD=335
T_MIN=336
T_RANK=337
T_ROW_NUMBER=338
T_STDEV=339
T_VAR=340
T_VARIANCE=341
T_OVER=342
T_PARTITION=343
T_ACTIVITY_COUNT=344
T_CAST=345
T_CURRENT_DATE=346
T_CURRENT_TIMESTAMP=347
T_CURRENT_USER=348
T_USER=349
T_MAX_PART_STRING=350
T_MIN_PART_STRING=351
T_MAX_PART_INT=352
T_MIN_PART_INT=353
T_MAX_PART_DATE=354
T_MIN_PART_DATE=355
T_PART_COUNT=356
T_PART_LOC=357
T_TRIM=358
T_SUBSTRING=359
T_SYSDATE=360
T_HIVE=361
T_HOST=362
L_FILE=363
L_D_STRING=364
L_DEC=365
T_TRUE=366
T_FALSE=367
T_DIR=368
T_FILE=369
T_FILES=370
T_NEW=371
T_PWD=372
T_SESSIONS=373
T_SUBDIR=374
'@'=1
'#'=2
'/'=3
'%'=4
'.'=5
'*'=6
'!'=7
';'=8
'-'=9
'+'=10

View File

@ -0,0 +1,47 @@
token literal names:
null
'@'
'#'
'/'
'%'
'.'
'*'
'!'
';'
'-'
'+'
token symbolic names:
null
null
null
null
null
null
null
null
null
null
null
rule names:
T__0
T__1
T__2
T__3
T__4
T__5
T__6
T__7
T__8
T__9
channel names:
DEFAULT_TOKEN_CHANNEL
HIDDEN
mode names:
DEFAULT_MODE
atn:
[3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 12, 43, 8, 1, 4, 2, 9, 2, 4, 3, 9, 3, 4, 4, 9, 4, 4, 5, 9, 5, 4, 6, 9, 6, 4, 7, 9, 7, 4, 8, 9, 8, 4, 9, 9, 9, 4, 10, 9, 10, 4, 11, 9, 11, 3, 2, 3, 2, 3, 3, 3, 3, 3, 4, 3, 4, 3, 5, 3, 5, 3, 6, 3, 6, 3, 7, 3, 7, 3, 8, 3, 8, 3, 9, 3, 9, 3, 10, 3, 10, 3, 11, 3, 11, 2, 2, 12, 3, 3, 5, 4, 7, 5, 9, 6, 11, 7, 13, 8, 15, 9, 17, 10, 19, 11, 21, 12, 3, 2, 2, 2, 42, 2, 3, 3, 2, 2, 2, 2, 5, 3, 2, 2, 2, 2, 7, 3, 2, 2, 2, 2, 9, 3, 2, 2, 2, 2, 11, 3, 2, 2, 2, 2, 13, 3, 2, 2, 2, 2, 15, 3, 2, 2, 2, 2, 17, 3, 2, 2, 2, 2, 19, 3, 2, 2, 2, 2, 21, 3, 2, 2, 2, 3, 23, 3, 2, 2, 2, 5, 25, 3, 2, 2, 2, 7, 27, 3, 2, 2, 2, 9, 29, 3, 2, 2, 2, 11, 31, 3, 2, 2, 2, 13, 33, 3, 2, 2, 2, 15, 35, 3, 2, 2, 2, 17, 37, 3, 2, 2, 2, 19, 39, 3, 2, 2, 2, 21, 41, 3, 2, 2, 2, 23, 24, 7, 66, 2, 2, 24, 4, 3, 2, 2, 2, 25, 26, 7, 37, 2, 2, 26, 6, 3, 2, 2, 2, 27, 28, 7, 49, 2, 2, 28, 8, 3, 2, 2, 2, 29, 30, 7, 39, 2, 2, 30, 10, 3, 2, 2, 2, 31, 32, 7, 48, 2, 2, 32, 12, 3, 2, 2, 2, 33, 34, 7, 44, 2, 2, 34, 14, 3, 2, 2, 2, 35, 36, 7, 35, 2, 2, 36, 16, 3, 2, 2, 2, 37, 38, 7, 61, 2, 2, 38, 18, 3, 2, 2, 2, 39, 40, 7, 47, 2, 2, 40, 20, 3, 2, 2, 2, 41, 42, 7, 45, 2, 2, 42, 22, 3, 2, 2, 2, 3, 2, 2]

View File

@ -0,0 +1,85 @@
// Generated from /Users/ziv/Workspace/dt-sql-parser/src/grammar/hive/HiveSql.g4 by ANTLR 4.8
// jshint ignore: start
var antlr4 = require('antlr4/index');
var serializedATN = ["\u0003\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964",
"\u0002\f+\b\u0001\u0004\u0002\t\u0002\u0004\u0003\t\u0003\u0004\u0004",
"\t\u0004\u0004\u0005\t\u0005\u0004\u0006\t\u0006\u0004\u0007\t\u0007",
"\u0004\b\t\b\u0004\t\t\t\u0004\n\t\n\u0004\u000b\t\u000b\u0003\u0002",
"\u0003\u0002\u0003\u0003\u0003\u0003\u0003\u0004\u0003\u0004\u0003\u0005",
"\u0003\u0005\u0003\u0006\u0003\u0006\u0003\u0007\u0003\u0007\u0003\b",
"\u0003\b\u0003\t\u0003\t\u0003\n\u0003\n\u0003\u000b\u0003\u000b\u0002",
"\u0002\f\u0003\u0003\u0005\u0004\u0007\u0005\t\u0006\u000b\u0007\r\b",
"\u000f\t\u0011\n\u0013\u000b\u0015\f\u0003\u0002\u0002\u0002*\u0002",
"\u0003\u0003\u0002\u0002\u0002\u0002\u0005\u0003\u0002\u0002\u0002\u0002",
"\u0007\u0003\u0002\u0002\u0002\u0002\t\u0003\u0002\u0002\u0002\u0002",
"\u000b\u0003\u0002\u0002\u0002\u0002\r\u0003\u0002\u0002\u0002\u0002",
"\u000f\u0003\u0002\u0002\u0002\u0002\u0011\u0003\u0002\u0002\u0002\u0002",
"\u0013\u0003\u0002\u0002\u0002\u0002\u0015\u0003\u0002\u0002\u0002\u0003",
"\u0017\u0003\u0002\u0002\u0002\u0005\u0019\u0003\u0002\u0002\u0002\u0007",
"\u001b\u0003\u0002\u0002\u0002\t\u001d\u0003\u0002\u0002\u0002\u000b",
"\u001f\u0003\u0002\u0002\u0002\r!\u0003\u0002\u0002\u0002\u000f#\u0003",
"\u0002\u0002\u0002\u0011%\u0003\u0002\u0002\u0002\u0013\'\u0003\u0002",
"\u0002\u0002\u0015)\u0003\u0002\u0002\u0002\u0017\u0018\u0007B\u0002",
"\u0002\u0018\u0004\u0003\u0002\u0002\u0002\u0019\u001a\u0007%\u0002",
"\u0002\u001a\u0006\u0003\u0002\u0002\u0002\u001b\u001c\u00071\u0002",
"\u0002\u001c\b\u0003\u0002\u0002\u0002\u001d\u001e\u0007\'\u0002\u0002",
"\u001e\n\u0003\u0002\u0002\u0002\u001f \u00070\u0002\u0002 \f\u0003",
"\u0002\u0002\u0002!\"\u0007,\u0002\u0002\"\u000e\u0003\u0002\u0002\u0002",
"#$\u0007#\u0002\u0002$\u0010\u0003\u0002\u0002\u0002%&\u0007=\u0002",
"\u0002&\u0012\u0003\u0002\u0002\u0002\'(\u0007/\u0002\u0002(\u0014\u0003",
"\u0002\u0002\u0002)*\u0007-\u0002\u0002*\u0016\u0003\u0002\u0002\u0002",
"\u0003\u0002\u0002"].join("");
var atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN);
var decisionsToDFA = atn.decisionToState.map( function(ds, index) { return new antlr4.dfa.DFA(ds, index); });
function HiveSqlLexer(input) {
antlr4.Lexer.call(this, input);
this._interp = new antlr4.atn.LexerATNSimulator(this, atn, decisionsToDFA, new antlr4.PredictionContextCache());
return this;
}
HiveSqlLexer.prototype = Object.create(antlr4.Lexer.prototype);
HiveSqlLexer.prototype.constructor = HiveSqlLexer;
Object.defineProperty(HiveSqlLexer.prototype, "atn", {
get : function() {
return atn;
}
});
HiveSqlLexer.EOF = antlr4.Token.EOF;
HiveSqlLexer.T__0 = 1;
HiveSqlLexer.T__1 = 2;
HiveSqlLexer.T__2 = 3;
HiveSqlLexer.T__3 = 4;
HiveSqlLexer.T__4 = 5;
HiveSqlLexer.T__5 = 6;
HiveSqlLexer.T__6 = 7;
HiveSqlLexer.T__7 = 8;
HiveSqlLexer.T__8 = 9;
HiveSqlLexer.T__9 = 10;
HiveSqlLexer.prototype.channelNames = [ "DEFAULT_TOKEN_CHANNEL", "HIDDEN" ];
HiveSqlLexer.prototype.modeNames = [ "DEFAULT_MODE" ];
HiveSqlLexer.prototype.literalNames = [ null, "'@'", "'#'", "'/'", "'%'",
"'.'", "'*'", "'!'", "';'", "'-'",
"'+'" ];
HiveSqlLexer.prototype.symbolicNames = [ ];
HiveSqlLexer.prototype.ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4",
"T__5", "T__6", "T__7", "T__8", "T__9" ];
HiveSqlLexer.prototype.grammarFileName = "HiveSql.g4";
exports.HiveSqlLexer = HiveSqlLexer;

View File

@ -0,0 +1,20 @@
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
T__5=6
T__6=7
T__7=8
T__8=9
T__9=10
'@'=1
'#'=2
'/'=3
'%'=4
'.'=5
'*'=6
'!'=7
';'=8
'-'=9
'+'=10

File diff suppressed because it is too large Load Diff

37756
src/lib/hive/HiveSqlParser.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,16 @@
const Lexer = require('antlr4').Lexer;
function PlSqlBaseLexer(...args) {
Lexer.call(this, ...args);
return this;
}
PlSqlBaseLexer.prototype = Object.create(Lexer.prototype);
PlSqlBaseLexer.prototype.constructor = PlSqlBaseLexer;
PlSqlBaseLexer.prototype.IsNewlineAtPos = function(pos) {
const la = this._input.LA(pos);
return la == -1 || la == '\n';
};
exports.PlSqlBaseLexer = PlSqlBaseLexer;

View File

@ -0,0 +1,27 @@
const Parser = require('antlr4').Parser;
function PlSqlBaseParser(...args) {
Parser.call(this, ...args);
this._isVersion10 = false;
this._isVersion12 = true;
return this;
}
PlSqlBaseParser.prototype = Object.create(Parser.prototype);
PlSqlBaseParser.prototype.constructor = PlSqlBaseParser;
PlSqlBaseParser.prototype.isVersion10 = function() {
return this._isVersion10;
};
PlSqlBaseParser.prototype.isVersion12 = function() {
return this._isVersion12;
};
PlSqlBaseParser.prototype.setVersion10 = function(value) {
this._isVersion10 = value;
};
PlSqlBaseParser.prototype.setVersion12 = function(value) {
this._isVersion12 = value;
};
exports.PlSqlBaseParser = PlSqlBaseParser;

File diff suppressed because one or more lines are too long

23834
src/lib/plsql/PlSqlLexer.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

100054
src/lib/plsql/PlSqlParser.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff