-
Notifications
You must be signed in to change notification settings - Fork 15
/
hparse.h
14963 lines (14648 loc) · 708 KB
/
hparse.h
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
/* Copyright (c) 2023 by Peter Gulutzan. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
The routines that start with "hparse_*" are a predictive recursive-descent
recognizer for MySQL, generally assuming LL(1) grammar but allowing for a few quirks.
(A recognizer does all the recursive-descent parser stuff except that it generates no tree.)
Generally recursive-descent parsers or recognizers are reputed to be good
because they're simple and can produce good -- often predictive -- error messages,
but bad because they're huge and slow, and that's certainly the case here.
The intent is to make highlight and hover look good.
If any comparison fails, the error message will say:
what we expected, token number + offset + value for the token where comparison failed.
Allowed syntaxes are: MySQL_5.7, MariaDB 10.2, Tarantool (like SQLite), or an ocelotgui client statement.
*/
/*
Todo: DEFAULT doesn't have to be followed by a literal, it can be an expression
Todo: PERCENTILE_CONT and PERCENTILE_DISC can have WITHIN GROUP (ORDER BY ...)
Todo: MEDIAN should only allow OVER (PARTITION ...) but not OVER (ORDER BY ...)
Todo: More support of MariaDB 10.3 system versioning -- https://mariadb.com/kb/en/system-versioned-tables/
Todo: other stuff in MariaDB 10.3.3 e.g. FOR ... END FOR loops
*/
/*
Todo: Actually identifier length maximum isn't always 64.
See http://dev.mysql.com/doc/refman/5.7/en/identifiers.html
*/
#define MYSQL_MAX_IDENTIFIER_LENGTH 64
/*
Currently allow_flags only tries to detect parenthesized expressions
with multiple operands inside (which are only allowed for comp-ops).
And whether we're inside "on duplicate key".
Todo: expand to check for whether subqueries are allowed
(currently we depend on hparse_subquery_is_allowed)
Todo: expand to check data type e.g. no string literal after << operator.
Todo: expand to check whether declared variables are allowed.
Todo: we allow "set @a = (1,2,3)" because we turn on allow_flag_is_multi
when we see "(", but if we forbid that then we will be forbidding
"set @a = (1,2,3) = (4,5,6)" which ought to be legal.
*/
#define ALLOW_FLAG_IS_MULTI 1
#define ALLOW_FLAG_IS_IN_DUPLICATE_KEY 2
/* conflict clauses are temporarily disabled */
//#define ALLOW_CONFLICT_CLAUSES 0
// create virtual is disabled, probably permanently
//#define ALLOW_CREATE_VIRTUAL
void MainWindow::hparse_f_nexttoken()
{
if (hparse_errno > 0) return;
for (;;)
{
++hparse_i;
hparse_token_type= main_token_types[hparse_i];
if ((hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DOUBLE_QUOTE)
&& (hparse_sql_mode_ansi_quotes == true))
{
hparse_token_type= main_token_types[hparse_i]= TOKEN_TYPE_IDENTIFIER_WITH_DOUBLE_QUOTE;
}
else if ((hparse_token_type == TOKEN_TYPE_IDENTIFIER_WITH_DOUBLE_QUOTE)
&& (hparse_sql_mode_ansi_quotes == false))
{
hparse_token_type= main_token_types[hparse_i]= TOKEN_TYPE_LITERAL_WITH_DOUBLE_QUOTE;
}
if ((hparse_token_type != TOKEN_TYPE_COMMENT_WITH_SLASH)
&& (hparse_token_type != TOKEN_TYPE_COMMENT_WITH_OCTOTHORPE)
&& (hparse_token_type != TOKEN_TYPE_COMMENT_WITH_MINUS))
break;
}
hparse_prev_token= hparse_token;
hparse_token= hparse_text_copy.mid(main_token_offsets[hparse_i], main_token_lengths[hparse_i]);
}
/*
Lookahead.
Call this if you want to know what the next symbol is, but don't want to get it.
This is used in only five places, to see whether ":" follows (which could indicate a label),
and to see whether next is "." and next_next is "*" (as in a select-list),
and to see whether NOT is the beginning of NOT LIKE,
and to see whether the word following GRANT ROLE is TO,
and to see whether the word following DATE|TIME|TIMESTAMP is a literal.
Todo: no conversion for identifier|literal with double quotes,
as is done for hparse_f_nexttoken(), maybe it doesn't matter.
*/
void MainWindow::hparse_f_next_nexttoken()
{
hparse_next_token= hparse_next_next_token= "";
hparse_next_next_next_token= "";
hparse_next_next_next_next_token= "";
int saved_hparse_i= hparse_i;
int saved_hparse_token_type= hparse_token_type;
QString saved_hparse_token= hparse_token;
if (main_token_lengths[hparse_i] != 0)
{
hparse_f_nexttoken();
hparse_next_token= hparse_token;
hparse_next_token_type= hparse_token_type;
if (main_token_lengths[hparse_i] != 0)
{
hparse_f_nexttoken();
hparse_next_next_token= hparse_token;
hparse_next_next_token_type= hparse_token_type;
}
if (main_token_lengths[hparse_i] != 0)
{
hparse_f_nexttoken();
hparse_next_next_next_token= hparse_token;
hparse_next_next_next_token_type= hparse_token_type;
}
if (main_token_lengths[hparse_i] != 0)
{
hparse_f_nexttoken();
hparse_next_next_next_next_token= hparse_token;
hparse_next_next_next_next_token_type= hparse_token_type;
}
}
hparse_i= saved_hparse_i;
hparse_token_type= saved_hparse_token_type;
hparse_token= saved_hparse_token;
}
void MainWindow::hparse_f_error()
{
if (hparse_errno > 0) return;
assert(hparse_i >= 0);
assert(hparse_i < (int)main_token_max_count);
main_token_flags[hparse_i] |= TOKEN_FLAG_IS_ERROR;
QString q_errormsg= "The latest token is: ";
if (hparse_token.length() > 40)
{
q_errormsg.append(hparse_token.left(40));
q_errormsg.append("...");
}
else q_errormsg.append(hparse_token);
q_errormsg.append(" (token #");
q_errormsg.append(QString::number(hparse_i + 1));
q_errormsg.append(", offset ");
q_errormsg.append(QString::number(main_token_offsets[hparse_i] + 1));
q_errormsg.append(") ");
q_errormsg.append(". The list of expected tokens is: ");
q_errormsg.append(hparse_expected);
/* Todo: this looks a bit odd. why a loop rather than a single assignment? */
while ((unsigned) q_errormsg.toUtf8().length() >= (unsigned int) sizeof(hparse_errmsg) - 1)
q_errormsg= q_errormsg.left(q_errormsg.length() - 1);
assert(q_errormsg.length() < MAX_HPARSE_ERRMSG_LENGTH);
strcpy(hparse_errmsg, q_errormsg.toUtf8());
hparse_errno= 10400;
}
/*
Merely saying "if (hparse_token == 'x') ..." till we saw delimiter usually is not =.
Warning: We can call this without going via hparse_f_multi_block()
*/
bool MainWindow::hparse_f_is_equal(QString hparse_token_copy, QString token)
{
if (hparse_token_copy == hparse_delimiter_str) return false;
if (hparse_token_copy == token) return true;
return false;
}
/*
Tarantool only -- after WITH, and within CREATE TRIGGER,
only certain verbs are legal.
*/
bool MainWindow::hparse_f_is_special_verb(int outer_verb)
{
QString s= hparse_token.toUpper();
if ((s== "DELETE") || (s == "INSERT") || (s == "REPLACE")
|| (s== "SELECT") || (s == "UPDATE") || (s == "VALUES"))
return true;
if ((outer_verb == TOKEN_KEYWORD_TRIGGER) && (s == "WITH")) return true;
hparse_f_accept(FLAG_VERSION_TARANTOOL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_DELETE, "DELETE");
hparse_f_accept(FLAG_VERSION_TARANTOOL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_INSERT, "INSERT");
hparse_f_accept(FLAG_VERSION_TARANTOOL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_REPLACE, "REPLACE");
hparse_f_accept(FLAG_VERSION_TARANTOOL|FLAG_VERSION_MARIADB_10_2_2, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_SELECT, "SELECT");
hparse_f_accept(FLAG_VERSION_TARANTOOL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_UPDATE, "UPDATE");
hparse_f_accept(FLAG_VERSION_TARANTOOL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_VALUES, "VALUES");
if (outer_verb == TOKEN_KEYWORD_TRIGGER)
hparse_f_accept(FLAG_VERSION_TARANTOOL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_WITH, "WITH");
hparse_f_error();
return false;
}
/*
accept means: if current == expected then clear list of what was expected, get next, and return 1,
else add to list of what was expected, and return 0
*/
int MainWindow::hparse_f_accept(unsigned int flag_version, unsigned char reftype, int proposed_type, QString token)
{
if (hparse_errno > 0) return 0;
if ((hparse_dbms_mask & flag_version) == 0) return 0;
bool equality= false;
if (token == "[eof]")
{
if (hparse_token.length() == 0)
{
equality= true;
}
}
else if ((hparse_token == hparse_delimiter_str) && (hparse_delimiter_str != ";"))
{
if ((hparse_token == token) && (proposed_type == TOKEN_TYPE_DELIMITER)) equality= true;
else equality= false;
}
else if (hparse_text_copy.mid(main_token_offsets[hparse_i], 2).toUpper() == "\\G")
{
/* \G and \g can act somewhat like delimiters. No change to hparse_expected list. */
if (proposed_type == TOKEN_TYPE_DELIMITER)
{
//main_token_types[hparse_i]= proposed_type;
//main_token_types[hparse_i + 1]= proposed_type;
hparse_expected= "";
completer_widget->clear_wrapper();
hparse_f_nexttoken();
hparse_i_of_last_accepted= hparse_i;
hparse_f_nexttoken();
++hparse_count_of_accepts;
return 1;
}
return 0;
}
else if (token == "[identifier]")
{
/* todo: stop checking if it's "[identifier]" when reftype is always passed. */
if ((hparse_dbms_mask & FLAG_VERSION_LUA) != 0)
{
if ((main_token_flags[hparse_i] & TOKEN_FLAG_IS_MAYBE_LUA) != 0)
{
main_token_flags[hparse_i] |= TOKEN_FLAG_IS_RESERVED;
}
else
{
main_token_flags[hparse_i] &= (~TOKEN_FLAG_IS_RESERVED);
if ((hparse_token_type >= TOKEN_TYPE_OTHER)
|| (hparse_token_type == TOKEN_TYPE_IDENTIFIER))
equality= true;
}
}
else
{
if (hparse_token_type == TOKEN_TYPE_IDENTIFIER_WITH_BACKTICK)
{
if ((hparse_token.size() == 1) || (hparse_token.right(1) != "`"))
{
/* Starts with ` but doesn't end with ` so identifier required but not there yet. */
int ret= hparse_f_expected_exact(reftype);
if (ret == 1) equality= true;
if (ret == 2) return 0;
}
else equality= true; /* starts and ends with ` */
}
if (hparse_token_type == TOKEN_TYPE_IDENTIFIER_WITH_DOUBLE_QUOTE)
{
if ((hparse_token.size() == 1) || (hparse_token.right(1) != "\""))
{
/* Starts with " but doesn't end with " so identifier required but not there yet. */
int ret= hparse_f_expected_exact(reftype);
if (ret == 1) equality= true;
if (ret == 2) return 0;
}
else equality= true; /* starts and ends with " */
}
// if ((hparse_token_type == TOKEN_TYPE_IDENTIFIER_WITH_BACKTICK)
// || (hparse_token_type == TOKEN_TYPE_IDENTIFIER_WITH_DOUBLE_QUOTE)
if ((hparse_token_type == TOKEN_TYPE_IDENTIFIER_WITH_AT)
|| ((hparse_token_type >= TOKEN_TYPE_OTHER)
&& ((main_token_flags[hparse_i] & TOKEN_FLAG_IS_RESERVED) == 0)))
{
if (hparse_f_expected_exact(reftype) > 0) equality= true;
}
}
}
else if (token == "[literal]")
{
if (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_SINGLE_QUOTE)
{
if ((hparse_token.size() == 1) || (hparse_token.right(1) != "'"))
{
/* Starts with ' but doesn't end with ' so literal required but not there yet. */
hparse_expected= token;
return 0;
}
}
if (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DOUBLE_QUOTE)
{
if ((hparse_token.size() == 1) || (hparse_token.right(1) != "\""))
{
/* Starts with ' but doesn't end with " so literal required but not there yet. */
hparse_expected= token;
return 0;
}
}
if (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_BRACKET)
{
if (hparse_token.right(2) != "]]")
{
/* Starts with [[ but doesn't end with ]] so literal required but not there yet. */
hparse_expected= token;
return 0;
}
}
if ((hparse_token_type == TOKEN_TYPE_LITERAL_WITH_SINGLE_QUOTE)
|| (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DOUBLE_QUOTE)
|| (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DIGIT)
|| (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_BRACKET)
/* literal_with_brace == literal */
|| (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_BRACE)) /* obsolete? */
{
equality= true;
}
}
else if (token == "[introducer]")
{
if ((hparse_token_type >= TOKEN_KEYWORD__ARMSCII8)
&& (hparse_token_type <= TOKEN_KEYWORD__UTF8MB4))
{
equality= true;
}
}
else if (token == "[reserved function]")
{
if (((main_token_flags[hparse_i] & TOKEN_FLAG_IS_RESERVED) != 0)
&& ((main_token_flags[hparse_i] & TOKEN_FLAG_IS_FUNCTION) != 0))
equality= true;
}
#ifdef DBMS_TARANTOOL
else if (token == "[field identifier]")
{
int base_size= strlen(TARANTOOL_FIELD_NAME_BASE);
bool ok= false;
int field_integer= 0;
int field_integer_length= hparse_token.length() - (base_size + 1);
if (field_integer_length > 0) field_integer= hparse_token.right(field_integer_length).toInt(&ok);
if ((hparse_token.left(base_size) == TARANTOOL_FIELD_NAME_BASE)
&& (hparse_token.mid(base_size, 1) == "_")
&& (field_integer > 0)
&& (ok == true)
&& (hparse_token.length() < TARANTOOL_MAX_FIELD_NAME_LENGTH))
{
equality= true;
}
}
#endif
else
{
if ((hparse_dbms_mask & FLAG_VERSION_LUA) != 0)
{
if (QString::compare(hparse_token, token, Qt::CaseSensitive) == 0)
{
equality= true;
}
}
else if (QString::compare(hparse_token, token, Qt::CaseInsensitive) == 0)
{
equality= true;
}
}
if (equality == true)
{
/*
Change the token type now that we're sure what it is.
But for keyword: if it's already more specific, leave it.
TODO: that exception no longer works because we moved TOKEN_TYPE_KEYWORD to the end
But for literal: if it's already more specific, leave it
*/
if ((proposed_type == TOKEN_TYPE_KEYWORD)
&& (main_token_types[hparse_i] >= TOKEN_KEYWORDS_START)) {;}
else if ((proposed_type == TOKEN_TYPE_LITERAL)
&& (main_token_types[hparse_i] < TOKEN_TYPE_LITERAL)) {;}
else main_token_types[hparse_i]= proposed_type;
main_token_reftypes[hparse_i]= reftype;
hparse_f_expected_clear();
hparse_i_of_last_accepted= hparse_i;
hparse_f_nexttoken();
++hparse_count_of_accepts;
return 1;
}
hparse_f_expected_append(token, reftype, proposed_type);
return 0;
}
///*
// I had a theory that using hparse_f_accept_key(TOKEN_KEYWORD_PAD)
// rather than hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_PAD, "PAD")
// would save a bit of space. In a quick test, it didn't. But test again someday.
//*/
//int MainWindow::hparse_f_accept_key(int key)
//{
// return hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,key, QString(strvalues[key].chars));
//}
/*
We tracked "what is expected" with global QString hparse_expected and with a private QListWidget in class completer_widget.
* hparse_expect = the possible error message if syntax checker == 3,
just keywords and [identifiers] separated by " or ", all possibilities even if something has been typed
... we wwill call token_reftype so it's more specific about the possibilities
* completer_widget = the autocomplete helper, [identifiers] established if REHASH happened,
wipe out entries if something has been typed and won't match
* when entering, clear them with hparse_f_expected_initialize()
* When accept succeeds i.e. equality == true, clear them with hparse_f_expected_clear()
* When accept fails and accept() is about to return 0, add to them with hparse_f_expected_append().
todo: maybe I should call hparse_f_token_to_appendee for completer_widget too
todo: there are other places where we might append a token
*/
void MainWindow::hparse_f_expected_initialize()
{
hparse_expected= "";
completer_widget->clear_wrapper();
}
void MainWindow::hparse_f_expected_clear()
{
hparse_expected= "";
completer_widget->clear_wrapper();
}
/*
If there was no REHASH, then anything that looks like a valid identifier is considered equal, return true.
If there was a REHASH, then return true iff the string, not just partial string, is found by rehash_search().
This can result in false if rehash_scan() was not done recently, so we add:
even if it is not found, if there is something ahead i.e. user kept typing anyway, regard it as true.
This means we can call rehash_search twice -- once for expected_exact, once for expected_append.
Todo: there are various places where we do QString-to-char* conversions that are less neat than this.
Todo: if hparse_f_is_rehash_searchable() == false, shouldn't we check anyway for missing " or `?
Return 0 = false, 1 = true, 2 = true but missing terminating " or `
*/
int MainWindow::hparse_f_expected_exact(int reftype)
{
if (hparse_f_is_rehash_searchable(reftype) == false) return 1;
if (main_token_lengths[hparse_i + 1] != 0) return 1;
QByteArray ba= hparse_token.toUtf8();
char *tmp= ba.data();
QString rehash_search_result= rehash_search(hparse_f_pre_rehash_search(reftype), tmp, reftype,
hparse_token,
true,
hparse_specified_schema,
hparse_specified_list);
if (rehash_search_result > "")
{
if ((hparse_token.left(1) == "\"") && (hparse_token.right(1) != "\""))
{
hparse_f_expected_append_endquote("\"");
return 2;
}
if ((hparse_token.left(1) == "`") && (hparse_token.right(1) != "`"))
{
hparse_f_expected_append_endquote("`");
return 2;
}
return 1;
}
return 0;
}
/*
But do not append ; if prev was ; -- a kludge of a kludge, as in hparse_f_create_package() .
*/
void MainWindow::hparse_f_expected_append(QString token, unsigned char reftype, int proposed_type)
{
if (hparse_expected > "") hparse_expected.append(" or ");
hparse_expected.append(hparse_f_token_to_appendee(token, hparse_i, reftype));
if (token == ";")
{
if ((hparse_i > 0) && (main_token_lengths[hparse_i - 1] == 1) && (main_token_types[hparse_i - 1] == TOKEN_TYPE_OPERATOR))
{
if (hparse_text_copy.mid(main_token_offsets[hparse_i - 1], main_token_lengths[hparse_i - 1]) == ";") return;
}
}
if (hparse_f_is_rehash_searchable(reftype) == true)
{
if (token.contains("identifier]") == true)
{
QString rehash_search_result= rehash_search(hparse_f_pre_rehash_search(reftype), (char*)"", reftype,
hparse_token,
false,
hparse_specified_schema,
hparse_specified_list);
}
}
// {
// QString s;
// char search_string[512];
// int search_string_len;
// s= text.mid(main_token_offsets[hparse_i], main_token_lengths[hparse_i]);
// if (s.left(1) == "`") s= s.right(s.size() - 1);
// else if (s.left(1) == "\"") s= s.right(s.size() - 1);
// search_string_len= s.toUtf8().size();
// memcpy(search_string, s.toUtf8().constData(), search_string_len);
// search_string[search_string_len]= '\0';
// QString rehash_search_result= rehash_search(hparse_f_pre_rehash_search(), search_string, main_token_reftypes[hparse_i]);
// if (rehash_search_result > "")
// {
// expected_list= "Expecting: ";
// expected_list.append(rehash_search_result);
// unfinished_identifier_seen= true;
// }
// }
// }
hparse_f_variables_append(hparse_i, hparse_text_copy, reftype); /* this is in ocelotgui.cpp */
/* If user has typed DROP TABLE " then possibilities should not include IF */
if ((hparse_token_type== TOKEN_TYPE_IDENTIFIER_WITH_BACKTICK) || (hparse_token_type == TOKEN_TYPE_IDENTIFIER_WITH_DOUBLE_QUOTE))
{
if (token != "[identifier]") return;
}
/* This was passing main_token_types[hparse_i], which would be the type of the unfinished input */
if (proposed_type == TOKEN_TYPE_OPERATOR) completer_widget->append_wrapper(token, hparse_token, proposed_type, main_token_flags[hparse_i], "O");
else completer_widget->append_wrapper(token, hparse_token, proposed_type, main_token_flags[hparse_i], "K");
}
/*
E.g. call this after DROP table "x -- because we should finish the identifier so it's DROP TABLE "x"
An endquote is " or ` but maybe somewhere it's useful to call this for '
Todo: really the type is not "K", we would like the tooltip to say "O" operator, or better still "terminating quote"
*/
void MainWindow::hparse_f_expected_append_endquote(QString token)
{
if (hparse_expected > "") hparse_expected.append(" or ");
hparse_expected= token;
completer_widget->clear_wrapper();
completer_widget->append_wrapper(token, "", TOKEN_TYPE_OPERATOR, TOKEN_REFTYPE_ANY, "K");
}
/*
Replace [identifier] with something more specific.
Todo: there are some problems with what-is-an-identifier calculation:
TOKEN_REFTYPE_ANY can be for @ within a user
TOKEN_REFTYPE_HOST and TOKEN_REFTYPE_USER can be for literals
"*" can be TOKEN_REFTYPE_DATABASE and TOKEN_TYPE_IDENTIFIER
*/
QString MainWindow::hparse_f_token_to_appendee(QString token, int i, char reftype)
{
QString appendee= token;
if (token != "[identifier]") return appendee;
return token_reftype(i, false, TOKEN_TYPE_IDENTIFIER, reftype);
}
/* A variant of hparse_f_accept for debugger keywords which can be shortened to n letters */
/* TODO: are you checking properly for eof or ; ??? */
int MainWindow::hparse_f_acceptn(int proposed_type, QString token, int n)
{
if (hparse_errno > 0) return 0;
QString token_to_compare;
int len= hparse_token.length();
if ((len >= n) && (len < token.length())) token_to_compare= token.left(len);
else token_to_compare= token;
if (QString::compare(hparse_token, token_to_compare, Qt::CaseInsensitive) == 0)
{
main_token_types[hparse_i]= proposed_type;
hparse_f_expected_clear();
hparse_f_nexttoken();
return 1;
}
hparse_f_expected_append(token, 0, TOKEN_TYPE_KEYWORD);
return 0;
}
/* A variant of hparse_f_accept for statement_format_rule words e.g. [keyword] [operator] */
/* TODO: are you checking properly for eof or ; ??? */
/* We won't match , or ; so there will have to be some other way to specify them. */
/* We won't match comments. */
int MainWindow::hparse_f_acceptf(int pass_number, QString replacee)
{
if (hparse_errno > 0) return 0;
bool is_accepted= false;
for (int i= 0; i < 5; ++i)
{
QString k;
if (i == 0) k= "COMMENT";
if (i == 1) k= "IDENTIFIER";
if (i == 2) k= "KEYWORD";
if (i == 3) k= "LITERAL";
if (i == 4) k= "OPERATOR";
if ((pass_number == 1) || (k == replacee))
{
if (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, k) == 1)
{
is_accepted= true;
break;
}
}
}
if (is_accepted == false)
{
int i= main_token_types[hparse_i];
if ((hparse_token != ",") && (hparse_token != ";"))
{
if (((i >= TOKEN_TYPE_IDENTIFIER_WITH_BACKTICK) && (i <= TOKEN_TYPE_IDENTIFIER_WITH_AT))
|| (i >= TOKEN_KEYWORDS_START)
|| ((i >= TOKEN_TYPE_LITERAL_WITH_SINGLE_QUOTE) && (i <= TOKEN_TYPE_LITERAL_WITH_BRACE))
|| (i == TOKEN_TYPE_OPERATOR))
{
hparse_f_expected_clear();
hparse_f_nexttoken();
is_accepted= true;
}
}
}
if (is_accepted == true)
{
if (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "-") == 1)
{
if (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "LOWER") == 0)
hparse_f_expect(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "UPPER");
if (hparse_errno > 0) return 0;
}
return 1;
}
/* guaranteed to fail */
hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "[identifier]");
hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "[keyword]]");
hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_IDENTIFIER, "[literal]");
hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_LITERAL, "[operator]");
return 0;
}
/*
A variant of hparse_f_accept during SET target=value [, ...] so we skip target if we've already done it.
Todo: this is okay for simple situations but wouldn't work for ... SET a=(x=y), x=z.
The idea is that the caller will remove the matching item for tokens.
An alternative is to search backward as far as the SET and not try to accept if it's seen before.
Actually we no longer call this for SET, but we do call for REQUIRE.
*/
int MainWindow::hparse_f_accept_in_set(unsigned int flag_version, QStringList tokens, int *i_of_matched)
{
for (int i= 0; i < tokens.size(); ++i)
{
QString token= tokens.at(i);
if (hparse_f_accept(flag_version, TOKEN_REFTYPE_ANY, TOKEN_TYPE_KEYWORD, token) == 1)
{
*i_of_matched= i;
return 1;
}
}
return 0;
}
/* expect means: if current == expected then get next and return 1; else error */
int MainWindow::hparse_f_expect(unsigned int flag_version, unsigned char reftype,int proposed_type, QString token)
{
if (hparse_errno > 0) return 0;
if ((hparse_dbms_mask & flag_version) == 0) return 0;
if (hparse_f_accept(flag_version, reftype,proposed_type, token)) return 1;
hparse_f_error();
return 0;
}
/* [literal] or _introducer [literal], return 1 if true */
/* todo: this is also accepting {ODBC junk} or NULL, sometimes when it shouldn't. */
/* todo: in fact it's far far too lax, you should pass what's acceptable data type */
/* todo: user mode should affect whether you accept "..." as a literal */
/*
Warning; we had a trick, that if reftype ==
TOKEN_REFTYPE_USER | HOST | CHARACTER_SET | COLLATION |ALIAS,
we would pass TOKEN_TYPE_IDENTIFIER, "[literal]" instead of
TOKEN_TYPE_LITERAL, "[literal]" to hparse_f_accept().
(So that hovering would show them as identifiers not literals.)
But that meant that if ocelot_statement_syntax_checker=3 then
hparse_f_accept() would change the type on the first pass, and
then fail on the second pass because the type was no longer literal.
Hovering should accept that it's literal and look harder at reftype?
*/
int MainWindow::hparse_f_literal(unsigned char reftype, unsigned int flag_version,int token_literal_flags)
{
if (hparse_errno > 0) return 0;
if ((hparse_dbms_mask & flag_version) == 0) return 0;
if (token_literal_flags & TOKEN_LITERAL_FLAG_INTRODUCER)
{
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_INTRODUCER,TOKEN_TYPE_KEYWORD, "[introducer]") == 1)
{
if (hparse_f_literal(reftype, FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_LITERAL_FLAG_STRING) == 0) hparse_f_error();
if (hparse_errno > 0) return 0;
return 1;
}
}
if (token_literal_flags & TOKEN_LITERAL_FLAG_ODBC)
{
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "{") == 1)
{
/* I can't imagine how {oj ...} could be valid if we're looking for a literal */
if ((hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "D") == 1) || (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "T") == 1) || (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "TS") == 1))
{
if (hparse_f_literal(reftype, FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_LITERAL_FLAG_ANY) == 0) hparse_f_error();
if (hparse_errno > 0) return 0;
hparse_f_expect(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "}");
if (hparse_errno > 0) return 0;
return 1;
}
else hparse_f_error();
return 0;
}
}
if (token_literal_flags & TOKEN_LITERAL_FLAG_MAP)
{
if (hparse_f_accept(FLAG_VERSION_TARANTOOL_2_7, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "{") == 1)
{
hparse_f_opr_1(0, 0); /* hmm, since {} contains expressions it's not really a literal, eh? */
if (hparse_errno > 0) return 0;
hparse_f_expect(FLAG_VERSION_TARANTOOL_2_7, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, ":");
if (hparse_errno > 0) return 0;
hparse_f_opr_1(0, 0);
if (hparse_errno > 0) return 0;
hparse_f_expect(FLAG_VERSION_TARANTOOL_2_7, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "}");
if (hparse_errno > 0) return 0;
return 1;
}
}
if (token_literal_flags & TOKEN_LITERAL_FLAG_CONSTANT)
{
if ((hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_NULL, "NULL") == 1)
|| (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_TRUE, "TRUE") == 1)
|| (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_FALSE, "FALSE") == 1)
|| (hparse_f_accept(FLAG_VERSION_TARANTOOL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_UNKNOWN, "UNKNOWN") == 1))
{
return 1;
}
}
if (token_literal_flags & TOKEN_LITERAL_FLAG_DATE)
{
/* DATE '...' | TIME '...' | TIMESTAMP '...' are literals, but DATE|TIME|TIMESTAMP are not. */
QString hpu= hparse_token.toUpper();
if ((hpu == "DATE") || (hpu == "TIME") || (hpu == "TIMESTAMP"))
{
hparse_f_next_nexttoken();
if ((hparse_next_token.mid(0,1) == "\"") || (hparse_next_token.mid(0,1) == "'"))
{
if ((hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "DATE") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "TIME") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "TIMESTAMP") == 1))
{
if (hparse_f_literal(reftype, FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_LITERAL_FLAG_STRING) == 0) hparse_f_error();
if (hparse_errno > 0) return 0;
return 1;
}
}
}
}
/* Allow for -integer, but not +integer. */
if (token_literal_flags & TOKEN_LITERAL_FLAG_SIGNED_INTEGER)
{
if (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "-") == 1)
{
if (hparse_f_literal(reftype, flag_version, TOKEN_LITERAL_FLAG_UNSIGNED_INTEGER) == 0) hparse_f_error();
if (hparse_errno > 0) return 0;
return 1;
}
}
bool possible= false;
if (token_literal_flags & TOKEN_LITERAL_FLAG_UNSIGNED_INTEGER)
{
if (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DIGIT)
{
if ((hparse_token.contains("E",Qt::CaseInsensitive) == false)
&& (hparse_token.contains(".") == false))
possible= true;
}
}
if (token_literal_flags & TOKEN_LITERAL_FLAG_SIGNED_INTEGER)
{
if (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DIGIT)
{
if ((hparse_token.contains("E",Qt::CaseInsensitive) == false)
&& (hparse_token.contains(".") == false))
possible= true;
}
}
if (token_literal_flags & TOKEN_LITERAL_FLAG_FLOAT)
{
if (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DIGIT)
{
possible= true;
}
}
if (token_literal_flags & (TOKEN_LITERAL_FLAG_STRING | TOKEN_LITERAL_FLAG_USER_STRING | TOKEN_LITERAL_FLAG_HOST_STRING))
{
if ((hparse_token_type == TOKEN_TYPE_LITERAL_WITH_SINGLE_QUOTE)
|| (hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DOUBLE_QUOTE))
{
possible= true;
}
if ((hparse_token_type == TOKEN_TYPE_LITERAL_WITH_DIGIT)
&& (hparse_token.left(2) == "0x"))
{
possible= true;
}
}
if (possible)
{
if (hparse_f_accept(flag_version, reftype, TOKEN_TYPE_LITERAL, "[literal]") == 1) return 1;
}
else
{
/* guaranteed to fail */
char expectation[128];
if ((token_literal_flags & TOKEN_LITERAL_FLAG_INTEGER)
&& ((token_literal_flags & TOKEN_LITERAL_FLAG_STRING) == 0)
&& ((token_literal_flags & TOKEN_LITERAL_FLAG_FLOAT) == 0))
strcpy(expectation, "[integer]");
else if ((token_literal_flags & TOKEN_LITERAL_FLAG_NUMBER)
&& (token_literal_flags & TOKEN_LITERAL_FLAG_STRING))
strcpy(expectation, "[number/string]");
else if (token_literal_flags & TOKEN_LITERAL_FLAG_NUMBER)
strcpy(expectation, "[number]");
else if (token_literal_flags & TOKEN_LITERAL_FLAG_STRING)
strcpy(expectation, "[string]");
else if (token_literal_flags & TOKEN_LITERAL_FLAG_USER_STRING)
strcpy(expectation, "[user-string]");
else if (token_literal_flags & TOKEN_LITERAL_FLAG_HOST_STRING)
strcpy(expectation, "[host-string]");
else
strcpy(expectation, "[non-number/non-string]");
if (hparse_f_accept(flag_version, reftype, TOKEN_TYPE_LITERAL, expectation) == 1) return 1;
}
return 0;
}
/*
DEFAULT is a reserved word which, as an operand, might be
() the right side of an assignment for INSERT/REPLACE/UPDATE
() the beginning of DEFAULT(col_name)
() the right side of an assignment for SET server-variable = DEFAULT.
Not to be confused with hparse_f_default_clause.
*/
int MainWindow::hparse_f_default(int who_is_calling, bool server_variable_seen)
{
if (who_is_calling == TOKEN_KEYWORD_SET)
{
if (server_variable_seen)
{
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_DEFAULT, "DEFAULT") == 1) return 1;
}
return 0;
}
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_KEYWORD_DEFAULT, "DEFAULT") == 1)
{
bool parenthesis_seen= false;
if ((who_is_calling == TOKEN_KEYWORD_INSERT)
|| (who_is_calling == TOKEN_KEYWORD_UPDATE)
|| (who_is_calling == TOKEN_KEYWORD_REPLACE))
{
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "(") == 1) parenthesis_seen= true;
}
else
{
hparse_f_expect(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "(");
if (hparse_errno > 0) return 0;
parenthesis_seen= true;
}
if (parenthesis_seen == true)
{
hparse_f_expect(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_COLUMN,TOKEN_TYPE_IDENTIFIER, "[identifier]");
if (hparse_errno > 0) return 0;
hparse_f_expect(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, ")");
if (hparse_errno > 0) return 0;
}
return 1;
}
return 0;
}
/*
MySQL + MariaDB both allow user names like 'a'@'b' or 'a' or a.
MySQL 8.0 allows role names the same way, MariaDB only allows 'a' or a.
token_reftype = TOKEN_REFTYPE_USER or (MySQL 8.0) TOKEN_REFTYPE_ROLE
Beware: we treat @ as a separator so 'a' @ 'b' is a user name.
MySQL doesn't expect spaces. But I'm thinking it won't cause ambiguity.
Todo: Something bizarre happens when I enter "a"@" (it doesn't say it expects more)
or "a"` ... AHA, it thinks @ is the start of an identifier,
but doesn't look for the closing ".
*/
int MainWindow::hparse_f_user_or_role_name(int token_reftype)
{
if ((hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, token_reftype,TOKEN_TYPE_IDENTIFIER, "[identifier]") == 1)
|| (hparse_f_literal(token_reftype, FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_LITERAL_FLAG_USER_STRING) == 1))
{
if ((token_reftype == TOKEN_REFTYPE_ROLE)
&& ((hparse_dbms_mask & FLAG_VERSION_MARIADB_ALL) != 0)) return 1;
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_IDENTIFIER, "@") == 1)
{
if ((hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_HOST,TOKEN_TYPE_IDENTIFIER, "[identifier]") == 1)
|| (hparse_f_literal(TOKEN_REFTYPE_HOST, FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_LITERAL_FLAG_HOST_STRING) == 1)) {;}
}
else if ((hparse_token.mid(0, 1) == "@")
&& (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_HOST,TOKEN_TYPE_IDENTIFIER, "[identifier]") == 1))
{
;
}
return 1;
}
if (token_reftype == TOKEN_REFTYPE_USER)
{
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_KEYWORD, "CURRENT_USER") == 1)
{
if (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, "(") == 1)
{
hparse_f_expect(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_ANY,TOKEN_TYPE_OPERATOR, ")");
if (hparse_errno > 0) return 0;
}
return 1;
}
}
return 0;
}
/*
It's possible for a user to define a new character set, but
we only check the official names. An undocumented "feature"
is that users can pass a string literal, we won't check it.
*/
int MainWindow::hparse_f_character_set_name()
{
if ((hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "ARMSCII8") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "ASCII") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "BIG5") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "BINARY") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP1250") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP1251") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP1256") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP1257") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP850") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP852") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP866") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "CP932") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "DEC8") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "EUCJPMS") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "EUCKR") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "FILENAME") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "GB2312") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "GBK") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "GEOSTD8") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "GREEK") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "HEBREW") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "HP8") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "KEYBCS2") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "KOI8R") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "KOI8U") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "LATIN1") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "LATIN2") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "LATIN5") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "LATIN7") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "MACCE") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "MACROMAN") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "SJIS") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "SWE7") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "TIS620") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UCS2") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UJIS") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UTF16") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UTF16LE") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UTF32") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UTF8") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UTF8MB3") == 1)
|| (hparse_f_accept(FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_REFTYPE_CHARACTER_SET,TOKEN_TYPE_KEYWORD, "UTF8MB4") == 1))
return 1;
if (hparse_f_literal(TOKEN_REFTYPE_CHARACTER_SET, FLAG_VERSION_MYSQL_OR_MARIADB_ALL, TOKEN_LITERAL_FLAG_STRING) == 1) return 1;
return 0;
}
/* Todo: someday check collation names the way we check character set names. */
int MainWindow::hparse_f_collation_name()
{
if (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_COLLATION,TOKEN_TYPE_IDENTIFIER, "[identifier]") == 1) return 1;
// if ((hparse_dbms_mask & FLAG_VERSION_TARANTOOL) != 0)
// {
// if (hparse_f_accept(FLAG_VERSION_ALL, TOKEN_REFTYPE_COLLATION,TOKEN_TYPE_KEYWORD, "BINARY") == 1) return 1;
// }
if ((hparse_dbms_mask & FLAG_VERSION_MYSQL_OR_MARIADB_ALL) != 0)
{
if (hparse_f_literal(TOKEN_REFTYPE_COLLATION, FLAG_VERSION_ALL, TOKEN_LITERAL_FLAG_STRING) == 1) return 1;
}
return 0;
}
/*
Routines starting with hparse_f_table... are based on
https://dev.mysql.com/doc/refman/5.5/en/join.html
*/
/*