forked from florajs/sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sql.pegjs
1159 lines (977 loc) · 25.7 KB
/
sql.pegjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
var reservedMap = {
'ALL': true,
'AND': true,
'AS': true,
'ASC': true,
'BETWEEN': true,
'BY': true,
'CASE': true,
'CREATE': true,
'CONTAINS': true,
'CURRENT_DATE': true,
'CURRENT_TIME': true,
'CURRENT_TIMESTAMP': true,
'CURRENT_USER': true,
'DELETE': true,
'DESC': true,
'DISTINCT': true,
'DROP': true,
'ELSE': true,
'END': true,
'EXISTS': true,
'EXPLAIN': true,
'FALSE': true,
'FROM': true,
'FULL': true,
'GROUP': true,
'HAVING': true,
'IN': true,
'INDEX': true,
'INNER': true,
'INSERT': true,
'INTO': true,
'IS': true,
'JOIN': true,
'JSON': true,
'LEFT': true,
'LIKE': true,
'LIMIT': true,
'NOT': true,
'NULL': true,
'ON': true,
'OR': true,
'ORDER': true,
'OUTER': true,
'RECURSIVE': true,
'REPLACE': true,
'RIGHT': true,
'SELECT': true,
'SESSION_USER': true,
'SET': true,
'SHOW': true,
'STATUS': true, // reserved (MySQL)
'SYSTEM_USER': true,
'TABLE': true,
'THEN': true,
'TRUE': true,
'TYPE': true, // reserved (MySQL)
'UNION': true,
'UPDATE': true,
'USER': true,
'USING': true,
'VALUES': true,
'WITH': true,
'WHEN': true,
'WHERE': true
};
function createUnaryExpr(op, e) {
return {
type: 'unary_expr',
operator: op,
expr: e
};
}
function createBinaryExpr(op, left, right) {
return {
type: 'binary_expr',
operator: op,
left: left,
right: right
};
}
function createList(head, tail) {
var result = [head];
for (var i = 0; i < tail.length; i++) {
result.push(tail[i][3]);
}
return result;
}
function createBinaryExprChain(head, tail) {
var result = head;
for (var i = 0; i < tail.length; i++) {
result = createBinaryExpr(tail[i][1], result, tail[i][3]);
}
return result;
}
var cmpPrefixMap = {
'+': true,
'-': true,
'*': true,
'/': true,
'>': true,
'<': true,
'!': true,
'=': true,
//between
'B': true,
'b': true,
//for is or in
'I': true,
'i': true,
//for like
'L': true,
'l': true,
//for not
'N': true,
'n': true
};
// used for dependency analysis
var varList = [];
}
start
= union_stmt
/ update_stmt
/ replace_insert_stmt
/ proc_stmts
union_stmt
= head:select_stmt tail:(__ KW_UNION __ select_stmt)* {
var cur = head;
for (var i = 0; i < tail.length; i++) {
cur._next = tail[i][3];
cur = cur._next
}
return head;
}
select_stmt
= select_stmt_nake
/ s:('(' __ select_stmt __ ')') {
return s[2];
}
with_clause
= KW_WITH __ head:cte_definition tail:(__ COMMA __ cte_definition)* {
return createList(head, tail);
}
/ __ KW_WITH __ KW_RECURSIVE __ cte:cte_definition {
cte.recursive = true;
return [cte]
}
cte_definition
= name:ident_name __ columns:cte_column_definition? __ KW_AS __ LPAREN __ stmt:union_stmt __ RPAREN {
return { name, stmt, columns };
}
cte_column_definition
= LPAREN __ head:column tail:(__ COMMA __ column)* __ RPAREN {
return createList(head, tail);
}
select_stmt_nake
= cte:with_clause? __ KW_SELECT __
opts:option_clause? __
d:KW_DISTINCT? __
c:column_clause __
f:from_clause? __
w:where_clause? __
g:group_by_clause? __
h:having_clause? __
o:order_by_clause? __
l:limit_clause? {
return {
with: cte,
type: 'select',
options: opts,
distinct: d,
columns: c,
from: f,
where: w,
groupby: g,
having: h,
orderby: o,
limit: l
};
}
// MySQL extensions to standard SQL
option_clause
= head:query_option tail:(__ query_option)* {
var opts = [head];
for (var i = 0, l = tail.length; i < l; ++i) {
opts.push(tail[i][1]);
}
return opts;
}
query_option
= option:(
OPT_SQL_CALC_FOUND_ROWS
/ (OPT_SQL_CACHE / OPT_SQL_NO_CACHE)
/ OPT_SQL_BIG_RESULT
/ OPT_SQL_SMALL_RESULT
/ OPT_SQL_BUFFER_RESULT
) { return option; }
column_clause
= (KW_ALL / (STAR !ident_start)) { return '*'; }
/ head:column_list_item tail:(__ COMMA __ column_list_item)* {
return createList(head, tail);
}
column_list_item
= tbl:ident __ DOT __ STAR {
return {
expr: {
type: 'column_ref',
table: tbl,
column: '*'
},
as: null
};
}
/ e:expr __ alias:alias_clause? {
return { expr: e, as: alias };
}
alias_clause
= KW_AS? __ i:ident { return i; }
from_clause
= KW_FROM __ l:table_ref_list { return l; }
table_ref_list
= head:table_base
tail:table_ref* {
tail.unshift(head);
return tail;
}
table_ref
= __ COMMA __ t:table_base { return t; }
/ __ t:table_join { return t; }
table_join
= op:join_op __ t:table_base __ KW_USING __ LPAREN __ head:ident_name tail:(__ COMMA __ ident_name)* __ RPAREN {
t.join = op;
t.using = createList(head, tail);
return t;
}
/ op:join_op __ t:table_base __ expr:on_clause? {
t.join = op;
t.on = expr;
return t;
}
/ op:join_op __ LPAREN __ stmt:union_stmt __ RPAREN __ KW_AS? __ alias:ident __ expr:on_clause? {
stmt.parentheses = true;
return {
expr: stmt,
as: alias,
join: op,
on: expr
};
}
//NOTE that, the table assigned to `var` shouldn't write in `table_join`
table_base
= KW_DUAL {
return {
type: 'dual'
};
}
/ t:table_name __ KW_AS? __ alias:ident? {
if (t.type === 'var') {
t.as = alias;
return t;
} else {
return {
db: t.db,
table: t.table,
as: alias
};
}
}
/ LPAREN __ stmt:union_stmt __ RPAREN __ KW_AS? __ alias:ident {
stmt.parentheses = true;
return {
expr: stmt,
as: alias
};
}
join_op
= KW_LEFT __ KW_OUTER? __ KW_JOIN { return 'LEFT JOIN'; }
/ KW_RIGHT __ KW_OUTER? __ KW_JOIN { return 'RIGHT JOIN'; }
/ KW_FULL __ KW_OUTER? __ KW_JOIN { return 'FULL JOIN'; }
/ (KW_INNER __)? KW_JOIN { return 'INNER JOIN'; }
table_name
= dt:ident tail:(__ DOT __ ident)? {
var obj = { db: null, table: dt };
if (tail !== null) {
obj.db = dt;
obj.table = tail[3];
}
return obj;
}
/ v:var_decl {
v.db = null;
v.table = v.name;
return v;
}
on_clause
= KW_ON __ e:expr { return e; }
where_clause
= KW_WHERE __ e:expr { return e; }
group_by_clause
= KW_GROUP __ KW_BY __ l:column_ref_list { return l; }
column_ref_list
= head:column_ref tail:(__ COMMA __ column_ref)* {
return createList(head, tail);
}
having_clause
= KW_HAVING __ e:expr { return e; }
order_by_clause
= KW_ORDER __ KW_BY __ l:order_by_list { return l; }
order_by_list
= head:order_by_element tail:(__ COMMA __ order_by_element)* {
return createList(head, tail);
}
order_by_element
= e:expr __ d:(KW_DESC / KW_ASC)? {
var obj = { expr: e, type: 'ASC' };
if (d === 'DESC') obj.type = 'DESC';
return obj;
}
number_or_param
= literal_numeric
/ param
limit_clause
= KW_LIMIT __ i1:(number_or_param) __ tail:(COMMA __ number_or_param)? {
var res = [i1];
if (tail === null) res.unshift({ type: 'number', value: 0 });
else res.push(tail[2]);
return res;
}
update_stmt
= KW_UPDATE __
t:table_name __
KW_SET __
l:set_list __
w:where_clause {
return {
type: 'update',
db: t.db,
table: t.table,
set: l,
where: w
};
}
set_list
= head:set_item tail:(__ COMMA __ set_item)* {
return createList(head, tail);
}
/**
* here only use `additive_expr` to support 'col1 = col1+2'
* if you want to use lower operator, please use '()' like below
* 'col1 = (col2 > 3)'
*/
set_item
= c:column_name __ '=' __ v:additive_expr {
return { column: c, value: v };
}
replace_insert_stmt
= ri:replace_insert __
KW_INTO __
t:table_name __ LPAREN __
c:column_list __ RPAREN __
v:value_clause {
return {
type: ri,
db: t.db,
table: t.table,
columns: c,
values: v
};
}
replace_insert
= KW_INSERT { return 'insert'; }
/ KW_REPLACE { return 'replace'; }
value_clause
= KW_VALUES __ l:value_list { return l; }
value_list
= head:value_item tail:(__ COMMA __ value_item)* {
return createList(head, tail);
}
value_item
= LPAREN __ l:expr_list __ RPAREN {
return l;
}
expr_list
= head:expr tail:(__ COMMA __ expr)* {
var el = { type: 'expr_list' };
el.value = createList(head, tail);
return el;
}
case_expr
= KW_CASE __
expr:expr? __
condition_list:case_when_then+ __
otherwise:case_else? __
KW_END __ KW_CASE? {
if (otherwise) condition_list.push(otherwise);
return {
type: 'case',
expr: expr || null,
args: condition_list
};
}
case_when_then
= KW_WHEN __ condition:expr __ KW_THEN __ result:expr __ {
return {
type: 'when',
cond: condition,
result: result
};
}
case_else = KW_ELSE __ result:expr {
return { type: 'else', result: result };
}
/**
* Borrowed from PL/SQL ,the priority of below list IS ORDER BY DESC
* ---------------------------------------------------------------------------------------------------
* | +, - | identity, negation |
* | *, / | multiplication, division |
* | +, - | addition, subtraction, concatenation |
* | =, <, >, <=, >=, <>, !=, IS, LIKE, BETWEEN, IN | comparion |
* | !, NOT | logical negation |
* | AND | conjunction |
* | OR | inclusion |
* ---------------------------------------------------------------------------------------------------
*/
expr
= or_expr
/ select_stmt
or_expr
= head:and_expr tail:(__ KW_OR __ and_expr)* {
return createBinaryExprChain(head, tail);
}
and_expr
= head:not_expr tail:(__ KW_AND __ not_expr)* {
return createBinaryExprChain(head, tail);
}
//here we should use `NOT` instead of `comparision_expr` to support chain-expr
not_expr
= comparison_expr
/ exists_expr
/ (KW_NOT / "!" !"=") __ expr:not_expr {
return createUnaryExpr('NOT', expr);
}
comparison_expr
= left:additive_expr __ rh:comparison_op_right? {
if (rh === null) return left;
else if (rh.type === 'arithmetic') return createBinaryExprChain(left, rh.tail);
else return createBinaryExpr(rh.op, left, rh.right);
}
exists_expr
= op:exists_op __ LPAREN __ stmt:union_stmt __ RPAREN {
stmt.parentheses = true;
return createUnaryExpr(op, stmt);
}
exists_op
= nk:(KW_NOT __ KW_EXISTS) { return nk[0] + ' ' + nk[2]; }
/ KW_EXISTS
comparison_op_right
= arithmetic_op_right
/ in_op_right
/ between_op_right
/ is_op_right
/ like_op_right
arithmetic_op_right
= l:(__ arithmetic_comparison_operator __ additive_expr)+ {
return { type: 'arithmetic', tail: l };
}
arithmetic_comparison_operator
= ">=" / ">" / "<=" / "<>" / "<" / "=" / "!="
is_op_right
= KW_IS __ right:additive_expr {
return { op: 'IS', right: right };
}
/ (KW_IS __ KW_NOT) __ right:additive_expr {
return { op: 'IS NOT', right: right };
}
between_op_right
= op:between_or_not_between_op __ begin:additive_expr __ KW_AND __ end:additive_expr {
return {
op: op,
right: {
type: 'expr_list',
value: [begin, end]
}
};
}
between_or_not_between_op
= nk:(KW_NOT __ KW_BETWEEN) { return nk[0] + ' ' + nk[2]; }
/ KW_BETWEEN
like_op
= nk:(KW_NOT __ KW_LIKE) { return nk[0] + ' ' + nk[2]; }
/ KW_LIKE
in_op
= nk:(KW_NOT __ KW_IN) { return nk[0] + ' ' + nk[2]; }
/ KW_IN
like_op_right
= op:like_op __ right:comparison_expr {
return { op: op, right: right };
}
in_op_right
= op:in_op __ LPAREN __ l:expr_list __ RPAREN {
return { op: op, right: l };
}
/ op:in_op __ e:var_decl {
return { op: op, right: e };
}
additive_expr
= head:multiplicative_expr
tail:(__ additive_operator __ multiplicative_expr)* {
return createBinaryExprChain(head, tail);
}
additive_operator
= "+" / "-"
multiplicative_expr
= head:primary
tail:(__ multiplicative_operator __ primary)* {
return createBinaryExprChain(head, tail)
}
multiplicative_operator
= "*" / "/" / "%"
primary
= literal
/ cast_expr
/ aggr_func
/ func_call
/ case_expr
/ column_ref
/ param
/ LPAREN __ e:expr __ RPAREN {
e.parentheses = true;
return e;
}
/ LPAREN __ list:expr_list __ RPAREN {
list.parentheses = true;
return list;
}
/ var_decl
column_ref
= tbl:ident __ DOT __ col:column {
return {
type: 'column_ref',
table: tbl,
column: col
};
}
/ col:column {
return {
type: 'column_ref',
table: null,
column: col
};
}
column_list
= head:column tail:(__ COMMA __ column)* {
return createList(head, tail);
}
ident
= name:ident_name !{ return reservedMap[name.toUpperCase()] === true; } {
return name;
}
/ name:quoted_ident {
return name;
}
quoted_ident
= double_quoted_ident
/ single_quoted_ident
/ backticks_quoted_ident
double_quoted_ident
= '"' chars:[^"]+ '"' { return chars.join(''); }
single_quoted_ident
= "'" chars:[^']+ "'" { return chars.join(''); }
backticks_quoted_ident
= "`" chars:[^`]+ "`" { return chars.join(''); }
column
= name:column_name !{ return reservedMap[name.toUpperCase()] === true; } { return name; }
/ quoted_ident
column_name
= start:ident_start parts:column_part* { return start + parts.join(''); }
ident_name
= start:ident_start parts:ident_part* { return start + parts.join(''); }
ident_start = [A-Za-z_]
ident_part = [A-Za-z0-9_]
// to support column name like `cf1:name` in hbase
column_part = [A-Za-z0-9_:]
param
= l:(':' ident_name) {
return { type: 'param', value: l[1] };
}
aggr_func
= aggr_fun_count
/ aggr_fun_smma
aggr_fun_smma
= name:KW_SUM_MAX_MIN_AVG __ LPAREN __ e:additive_expr __ RPAREN {
return {
type: 'aggr_func',
name: name,
args: {
expr: e
}
};
}
KW_SUM_MAX_MIN_AVG
= KW_SUM / KW_MAX / KW_MIN / KW_AVG
aggr_fun_count
= name:KW_COUNT __ LPAREN __ arg:count_arg __ RPAREN {
return {
type: 'aggr_func',
name: name,
args: arg
};
}
count_arg
= e:star_expr { return { expr: e }; }
/ d:KW_DISTINCT? __ c:column_ref { return { distinct: d, expr: c }; }
star_expr
= "*" { return { type: 'star', value: '*' }; }
func_call
= name:ident __ LPAREN __ l:expr_list? __ RPAREN {
return {
type: 'function',
name: name,
args: l ? l: { type: 'expr_list', value: [] }
};
}
/ name:scalar_func {
return {
type: 'function',
name: name,
args: { type: 'expr_list', value: [] }
};
}
scalar_func
= KW_CURRENT_DATE
/ KW_CURRENT_TIME
/ KW_CURRENT_TIMESTAMP
/ KW_CURRENT_USER
/ KW_USER
/ KW_SESSION_USER
/ KW_SYSTEM_USER
cast_expr
= KW_CAST __ LPAREN __ e:expr __ KW_AS __ t:data_type __ RPAREN {
return {
type: 'cast',
expr: e,
target: t
};
}
/ KW_CAST __ LPAREN __ e:expr __ KW_AS __ KW_DECIMAL __ LPAREN __ precision:int __ RPAREN __ RPAREN {
return {
type: 'cast',
expr: e,
target: {
dataType: 'DECIMAL(' + precision + ')'
}
};
}
/ KW_CAST __ LPAREN __ e:expr __ KW_AS __ KW_DECIMAL __ LPAREN __ precision:int __ COMMA __ scale:int __ RPAREN __ RPAREN {
return {
type: 'cast',
expr: e,
target: {
dataType: 'DECIMAL(' + precision + ', ' + scale + ')'
}
};
}
/ KW_CAST __ LPAREN __ e:expr __ KW_AS __ s:signedness __ t:KW_INTEGER? __ RPAREN { /* MySQL cast to un-/signed integer */
return {
type: 'cast',
expr: e,
target: {
dataType: s + (t ? ' ' + t: '')
}
};
}
signedness
= KW_SIGNED
/ KW_UNSIGNED
literal
= literal_string
/ literal_numeric
/ literal_bool
/ literal_null
/ literal_datetime
literal_list
= head:literal tail:(__ COMMA __ literal)* {
return createList(head, tail);
}
literal_null
= KW_NULL {
return { type: 'null', value: null };
}
literal_bool
= KW_TRUE {
return { type: 'bool', value: true };
}
/ KW_FALSE {
return { type: 'bool', value: false };
}
literal_string
= ca:("'" single_char* "'") {
return {
type: 'string',
value: ca[1].join('')
};
}
literal_datetime
= type:(KW_TIME / KW_DATE / KW_TIMESTAMP) __ ca:("'" single_char* "'") {
return {
type: type.toLowerCase(),
value: ca[1].join('')
};
}
single_char
= [^'\\\0-\x1F\x7f]
/ escape_char
escape_char
= "\\'" { return "'"; }
/ '\\"' { return '"'; }
/ "\\\\" { return "\\"; }
/ "\\/" { return "/"; }
/ "\\b" { return "\b"; }
/ "\\f" { return "\f"; }
/ "\\n" { return "\n"; }
/ "\\r" { return "\r"; }
/ "\\t" { return "\t"; }
/ "\\u" h1:hexDigit h2:hexDigit h3:hexDigit h4:hexDigit {
return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4));
}
line_terminator
= [\n\r]
literal_numeric
= n:number {
return { type: 'number', value: n };
}
number
= int_:int frac:frac exp:exp __ { return parseFloat(int_ + frac + exp); }
/ int_:int frac:frac __ { return parseFloat(int_ + frac); }
/ int_:int exp:exp __ { return parseFloat(int_ + exp); }
/ int_:int __ { return parseFloat(int_); }
int
= digits
/ digit:digit
/ op:("-" / "+" ) digits:digits { return "-" + digits; }
/ op:("-" / "+" ) digit:digit { return "-" + digit; }
frac
= "." digits:digits { return "." + digits; }
exp
= e:e digits:digits { return e + digits; }
digits
= digits:digit+ { return digits.join(""); }
digit = [0-9]
hexDigit
= [0-9a-fA-F]
e
= e:[eE] sign:[+-]? { return e + (sign !== null ? sign: ''); }
KW_NULL = "NULL"i !ident_start
KW_TRUE = "TRUE"i !ident_start
KW_FALSE = "FALSE"i !ident_start
KW_SHOW = "SHOW"i !ident_start
KW_DROP = "DROP"i !ident_start
KW_SELECT = "SELECT"i !ident_start
KW_UPDATE = "UPDATE"i !ident_start
KW_CREATE = "CREATE"i !ident_start
KW_DELETE = "DELETE"i !ident_start
KW_INSERT = "INSERT"i !ident_start
KW_RECURSIVE= "RECURSIVE" !ident_start
KW_REPLACE = "REPLACE"i !ident_start
KW_EXPLAIN = "EXPLAIN"i !ident_start
KW_INTO = "INTO"i !ident_start
KW_FROM = "FROM"i !ident_start
KW_SET = "SET"i !ident_start
KW_AS = "AS"i !ident_start
KW_TABLE = "TABLE"i !ident_start
KW_ON = "ON"i !ident_start
KW_LEFT = "LEFT"i !ident_start
KW_RIGHT = "RIGHT"i !ident_start
KW_FULL = "FULL"i !ident_start
KW_INNER = "INNER"i !ident_start
KW_JOIN = "JOIN"i !ident_start
KW_OUTER = "OUTER"i !ident_start
KW_UNION = "UNION"i !ident_start
KW_VALUES = "VALUES"i !ident_start
KW_USING = "USING"i !ident_start
KW_WHERE = "WHERE"i !ident_start
KW_WITH = "WITH"i !ident_start
KW_GROUP = "GROUP"i !ident_start
KW_BY = "BY"i !ident_start
KW_ORDER = "ORDER"i !ident_start
KW_HAVING = "HAVING"i !ident_start
KW_LIMIT = "LIMIT"i !ident_start
KW_ASC = "ASC"i !ident_start { return 'ASC'; }
KW_DESC = "DESC"i !ident_start { return 'DESC'; }
KW_ALL = "ALL"i !ident_start { return 'ALL'; }
KW_DISTINCT = "DISTINCT"i !ident_start { return 'DISTINCT';}
KW_BETWEEN = "BETWEEN"i !ident_start { return 'BETWEEN'; }
KW_IN = "IN"i !ident_start { return 'IN'; }
KW_IS = "IS"i !ident_start { return 'IS'; }
KW_LIKE = "LIKE"i !ident_start { return 'LIKE'; }
KW_EXISTS = "EXISTS"i !ident_start { return 'EXISTS'; }
KW_NOT = "NOT"i !ident_start { return 'NOT'; }
KW_AND = "AND"i !ident_start { return 'AND'; }
KW_OR = "OR"i !ident_start { return 'OR'; }
KW_COUNT = "COUNT"i !ident_start { return 'COUNT'; }
KW_MAX = "MAX"i !ident_start { return 'MAX'; }
KW_MIN = "MIN"i !ident_start { return 'MIN'; }
KW_SUM = "SUM"i !ident_start { return 'SUM'; }
KW_AVG = "AVG"i !ident_start { return 'AVG'; }
KW_CASE = "CASE"i !ident_start
KW_WHEN = "WHEN"i !ident_start
KW_THEN = "THEN"i !ident_start
KW_ELSE = "ELSE"i !ident_start
KW_END = "END"i !ident_start
KW_CAST = "CAST"i !ident_start
KW_CHAR = "CHAR"i !ident_start { return 'CHAR'; }
KW_VARCHAR = "VARCHAR"i !ident_start { return 'VARCHAR';}
KW_NUMERIC = "NUMERIC"i !ident_start { return 'NUMERIC'; }
KW_DECIMAL = "DECIMAL"i !ident_start { return 'DECIMAL'; }
KW_SIGNED = "SIGNED"i !ident_start { return 'SIGNED'; }
KW_UNSIGNED = "UNSIGNED"i !ident_start { return 'UNSIGNED'; }
KW_INT = "INT"i !ident_start { return 'INT'; }
KW_INTEGER = "INTEGER"i !ident_start { return 'INTEGER'; }
KW_JSON = "JSON"i !ident_start { return 'JSON'; }
KW_SMALLINT = "SMALLINT"i !ident_start { return 'SMALLINT'; }
KW_DATE = "DATE"i !ident_start { return 'DATE'; }
KW_TIME = "TIME"i !ident_start { return 'TIME'; }
KW_TIMESTAMP= "TIMESTAMP"i!ident_start { return 'TIMESTAMP'; }
KW_USER = "USER"i !ident_start { return 'USER'; }
KW_CURRENT_DATE = "CURRENT_DATE"i !ident_start { return 'CURRENT_DATE'; }
KW_CURRENT_TIME = "CURRENT_TIME"i !ident_start { return 'CURRENT_TIME'; }
KW_CURRENT_TIMESTAMP= "CURRENT_TIMESTAMP"i !ident_start { return 'CURRENT_TIMESTAMP'; }
KW_CURRENT_USER = "CURRENT_USER"i !ident_start { return 'CURRENT_USER'; }
KW_SESSION_USER = "SESSION_USER"i !ident_start { return 'SESSION_USER'; }
KW_SYSTEM_USER = "SYSTEM_USER"i !ident_start { return 'SYSTEM_USER'; }
KW_VAR_PRE = '$'
KW_RETURN = 'return'i
KW_ASSIGN = ':='
KW_DUAL = "DUAL"
// MySQL extensions to SQL
OPT_SQL_CALC_FOUND_ROWS = "SQL_CALC_FOUND_ROWS"i
OPT_SQL_CACHE = "SQL_CACHE"i
OPT_SQL_NO_CACHE = "SQL_NO_CACHE"i
OPT_SQL_SMALL_RESULT = "SQL_SMALL_RESULT"i
OPT_SQL_BIG_RESULT = "SQL_BIG_RESULT"i
OPT_SQL_BUFFER_RESULT = "SQL_BUFFER_RESULT"i
//special character
DOT = '.'