Debian Codegraph @

storage/innobase/pars/pars0lex.l

raw
1 /*****************************************************************************
2
3 Copyright (c) 1997, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20 for more details.
21
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /******************************************************
29 SQL parser lexical analyzer: input file for the GNU Flex lexer generator
30
31 The InnoDB parser is frozen because MySQL takes care of SQL parsing.
32 Therefore we normally keep the InnoDB parser C files as they are, and do
33 not automatically generate them from pars0grm.y and pars0lex.l.
34
35 How to make the InnoDB parser and lexer C files:
36
37 1. Run ./make_flex.sh to generate lexer files.
38
39 2. Run ./make_bison.sh to generate parser files.
40
41 These instructions seem to work at least with bison-1.875d and flex-2.5.31 on
42 Linux.
43
44 Created 12/14/1997 Heikki Tuuri
45 *******************************************************/
46
47 %option nostdinit
48 %option 8bit
49 %option warn
50 %option pointer
51 %option never-interactive
52 %option nodefault
53 %option noinput
54 %option nounput
55 %option noyywrap
56 %option noyy_scan_buffer
57 %option noyy_scan_bytes
58 %option noyy_scan_string
59 %option nounistd
60
61 %{
62 #define YYSTYPE que_node_t*
63
64 #include "univ.i"
65 #include "pars0pars.h"
66 #include "pars0grm.h"
67 #include "pars0sym.h"
68 #include "mem0mem.h"
69 #include "os0proc.h"
70
71 #define malloc(A) ut::malloc_withkey(UT_NEW_THIS_FILE_PSI_KEY, A)
72 #define free(A) ut::free(A)
73 #define realloc(P, A) ut_realloc(P, A)
74 #define exit(A) ut_error
75
76 /* Note: We cast result from int to yy_size_t */
77 #define YY_INPUT(buf, result, max_size) \
78 ((result) = pars_get_lex_chars(buf, max_size))
79
80 /* String buffer for removing quotes */
81 static ulint stringbuf_len_alloc = 0; /* Allocated length */
82 static ulint stringbuf_len = 0; /* Current length */
83 static char* stringbuf; /* Start of buffer */
84 /** Appends a string to the buffer. */
85 static
86 void
87 string_append(
88 /*==========*/
89 const char* str, /*!< in: string to be appended */
90 ulint len) /*!< in: length of the string */
91 {
92 if (stringbuf == NULL) {
93 stringbuf = static_cast<char*>(malloc(1));
94 stringbuf_len_alloc = 1;
95 }
96
97 if (stringbuf_len + len > stringbuf_len_alloc) {
98 while (stringbuf_len + len > stringbuf_len_alloc) {
99 stringbuf_len_alloc <<= 1;
100 }
101
102 stringbuf = static_cast<char*>(
103 realloc(stringbuf, stringbuf_len_alloc));
104 }
105
106 memcpy(stringbuf + stringbuf_len, str, len);
107 stringbuf_len += len;
108 }
109
110 %}
111
112 DIGIT [0-9]
113 ID [a-z_A-Z][a-z_A-Z0-9]*
114 TABLE_NAME [a-z_A-Z][@a-z_A-Z0-9]*\/(#sql-|[a-z_A-Z])[a-z_A-Z0-9]*
115 BOUND_LIT \:[a-z_A-Z0-9]+
116 BOUND_ID \$[a-z_A-Z0-9]+
117
118 %x comment
119 %x quoted
120 %x id
121 %%
122
123 {DIGIT}+ {
124 yylval = sym_tab_add_int_lit(pars_sym_tab_global,
125 atoi(yytext));
126 return(PARS_INT_LIT);
127 }
128
129 {DIGIT}+"."{DIGIT}* {
130 ut_error; /* not implemented */
131
132 return(PARS_FLOAT_LIT);
133 }
134
135 {BOUND_LIT} {
136 ulint type;
137
138 yylval = sym_tab_add_bound_lit(pars_sym_tab_global,
139 yytext + 1, &type);
140
141 return((int) type);
142 }
143
144 {BOUND_ID} {
145 yylval = sym_tab_add_bound_id(pars_sym_tab_global,
146 yytext + 1);
147
148 return(PARS_ID_TOKEN);
149 }
150
151 "'" {
152 /* Quoted character string literals are handled in an explicit
153 start state 'quoted'. This state is entered and the buffer for
154 the scanned string is emptied upon encountering a starting quote.
155
156 In the state 'quoted', only two actions are possible (defined below). */
157 BEGIN(quoted);
158 stringbuf_len = 0;
159 }
160 <quoted>[^\']+ {
161 /* Got a sequence of characters other than "'":
162 append to string buffer */
163 string_append(yytext, yyleng);
164 }
165 <quoted>"'"+ {
166 /* Got a sequence of "'" characters:
167 append half of them to string buffer,
168 as "''" represents a single "'".
169 We apply truncating division,
170 so that "'''" will result in "'". */
171
172 string_append(yytext, yyleng / 2);
173
174 /* If we got an odd number of quotes, then the
175 last quote we got is the terminating quote.
176 At the end of the string, we return to the
177 initial start state and report the scanned
178 string literal. */
179
180 if (yyleng % 2) {
181 BEGIN(INITIAL);
182 yylval = sym_tab_add_str_lit(
183 pars_sym_tab_global,
184 (byte*) stringbuf, stringbuf_len);
185 return(PARS_STR_LIT);
186 }
187 }
188
189 \" {
190 /* Quoted identifiers are handled in an explicit start state 'id'.
191 This state is entered and the buffer for the scanned string is emptied
192 upon encountering a starting quote.
193
194 In the state 'id', only two actions are possible (defined below). */
195 BEGIN(id);
196 stringbuf_len = 0;
197 }
198 <id>[^\"]+ {
199 /* Got a sequence of characters other than '"':
200 append to string buffer */
201 string_append(yytext, yyleng);
202 }
203 <id>\"+ {
204 /* Got a sequence of '"' characters:
205 append half of them to string buffer,
206 as '""' represents a single '"'.
207 We apply truncating division,
208 so that '"""' will result in '"'. */
209
210 string_append(yytext, yyleng / 2);
211
212 /* If we got an odd number of quotes, then the
213 last quote we got is the terminating quote.
214 At the end of the string, we return to the
215 initial start state and report the scanned
216 identifier. */
217
218 if (yyleng % 2) {
219 BEGIN(INITIAL);
220 yylval = sym_tab_add_id(
221 pars_sym_tab_global,
222 (byte*) stringbuf, stringbuf_len);
223
224 return(PARS_ID_TOKEN);
225 }
226 }
227
228 "NULL" {
229 yylval = sym_tab_add_null_lit(pars_sym_tab_global);
230
231 return(PARS_NULL_LIT);
232 }
233
234 "SQL" {
235 /* Implicit cursor name */
236 yylval = sym_tab_add_str_lit(pars_sym_tab_global,
237 (byte*) yytext, yyleng);
238 return(PARS_SQL_TOKEN);
239 }
240
241 "AND" {
242 return(PARS_AND_TOKEN);
243 }
244
245 "OR" {
246 return(PARS_OR_TOKEN);
247 }
248
249 "NOT" {
250 return(PARS_NOT_TOKEN);
251 }
252
253 "PROCEDURE" {
254 return(PARS_PROCEDURE_TOKEN);
255 }
256
257 "IN" {
258 return(PARS_IN_TOKEN);
259 }
260
261 "OUT" {
262 return(PARS_OUT_TOKEN);
263 }
264
265 "BINARY" {
266 return(PARS_BINARY_TOKEN);
267 }
268
269 "BLOB" {
270 return(PARS_BLOB_TOKEN);
271 }
272
273 "INT" {
274 return(PARS_INT_TOKEN);
275 }
276
277 "INTEGER" {
278 return(PARS_INT_TOKEN);
279 }
280
281 "FLOAT" {
282 return(PARS_FLOAT_TOKEN);
283 }
284
285 "CHAR" {
286 return(PARS_CHAR_TOKEN);
287 }
288
289 "IS" {
290 return(PARS_IS_TOKEN);
291 }
292
293 "BEGIN" {
294 return(PARS_BEGIN_TOKEN);
295 }
296
297 "END" {
298 return(PARS_END_TOKEN);
299 }
300
301 "IF" {
302 return(PARS_IF_TOKEN);
303 }
304
305 "THEN" {
306 return(PARS_THEN_TOKEN);
307 }
308
309 "ELSE" {
310 return(PARS_ELSE_TOKEN);
311 }
312
313 "ELSIF" {
314 return(PARS_ELSIF_TOKEN);
315 }
316
317 "LOOP" {
318 return(PARS_LOOP_TOKEN);
319 }
320
321 "WHILE" {
322 return(PARS_WHILE_TOKEN);
323 }
324
325 "RETURN" {
326 return(PARS_RETURN_TOKEN);
327 }
328
329 "SELECT" {
330 return(PARS_SELECT_TOKEN);
331 }
332
333 "SUM" {
334 return(PARS_SUM_TOKEN);
335 }
336
337 "COUNT" {
338 return(PARS_COUNT_TOKEN);
339 }
340
341 "DISTINCT" {
342 return(PARS_DISTINCT_TOKEN);
343 }
344
345 "FROM" {
346 return(PARS_FROM_TOKEN);
347 }
348
349 "WHERE" {
350 return(PARS_WHERE_TOKEN);
351 }
352
353 "FOR" {
354 return(PARS_FOR_TOKEN);
355 }
356
357 "READ" {
358 return(PARS_READ_TOKEN);
359 }
360
361 "ORDER" {
362 return(PARS_ORDER_TOKEN);
363 }
364
365 "BY" {
366 return(PARS_BY_TOKEN);
367 }
368
369 "ASC" {
370 return(PARS_ASC_TOKEN);
371 }
372
373 "DESC" {
374 return(PARS_DESC_TOKEN);
375 }
376
377 "INSERT" {
378 return(PARS_INSERT_TOKEN);
379 }
380
381 "INTO" {
382 return(PARS_INTO_TOKEN);
383 }
384
385 "VALUES" {
386 return(PARS_VALUES_TOKEN);
387 }
388
389 "UPDATE" {
390 return(PARS_UPDATE_TOKEN);
391 }
392
393 "SET" {
394 return(PARS_SET_TOKEN);
395 }
396
397 "DELETE" {
398 return(PARS_DELETE_TOKEN);
399 }
400
401 "CURRENT" {
402 return(PARS_CURRENT_TOKEN);
403 }
404
405 "OF" {
406 return(PARS_OF_TOKEN);
407 }
408
409 "CREATE" {
410 return(PARS_CREATE_TOKEN);
411 }
412
413 "TABLE" {
414 return(PARS_TABLE_TOKEN);
415 }
416
417 "COMPACT" {
418 return(PARS_COMPACT_TOKEN);
419 }
420
421 "BLOCK_SIZE" {
422 return(PARS_BLOCK_SIZE_TOKEN);
423 }
424
425 "INDEX" {
426 return(PARS_INDEX_TOKEN);
427 }
428
429 "UNIQUE" {
430 return(PARS_UNIQUE_TOKEN);
431 }
432
433 "CLUSTERED" {
434 return(PARS_CLUSTERED_TOKEN);
435 }
436
437 "DOES_NOT_FIT_IN_MEMORY" {
438 return(PARS_DOES_NOT_FIT_IN_MEM_TOKEN);
439 }
440
441 "ON" {
442 return(PARS_ON_TOKEN);
443 }
444
445 "DECLARE" {
446 return(PARS_DECLARE_TOKEN);
447 }
448
449 "CURSOR" {
450 return(PARS_CURSOR_TOKEN);
451 }
452
453 "OPEN" {
454 return(PARS_OPEN_TOKEN);
455 }
456
457 "FETCH" {
458 return(PARS_FETCH_TOKEN);
459 }
460
461 "CLOSE" {
462 return(PARS_CLOSE_TOKEN);
463 }
464
465 "NOTFOUND" {
466 return(PARS_NOTFOUND_TOKEN);
467 }
468
469 "TO_BINARY" {
470 return(PARS_TO_BINARY_TOKEN);
471 }
472
473 "SUBSTR" {
474 return(PARS_SUBSTR_TOKEN);
475 }
476
477 "CONCAT" {
478 return(PARS_CONCAT_TOKEN);
479 }
480
481 "INSTR" {
482 return(PARS_INSTR_TOKEN);
483 }
484
485 "LENGTH" {
486 return(PARS_LENGTH_TOKEN);
487 }
488
489 "COMMIT" {
490 return(PARS_COMMIT_TOKEN);
491 }
492
493 "ROLLBACK" {
494 return(PARS_ROLLBACK_TOKEN);
495 }
496
497 "WORK" {
498 return(PARS_WORK_TOKEN);
499 }
500
501 "UNSIGNED" {
502 return(PARS_UNSIGNED_TOKEN);
503 }
504
505 "EXIT" {
506 return(PARS_EXIT_TOKEN);
507 }
508
509 "FUNCTION" {
510 return(PARS_FUNCTION_TOKEN);
511 }
512
513 "LOCK" {
514 return(PARS_LOCK_TOKEN);
515 }
516
517 "SHARE" {
518 return(PARS_SHARE_TOKEN);
519 }
520
521 "MODE" {
522 return(PARS_MODE_TOKEN);
523 }
524
525 "LIKE" {
526 return(PARS_LIKE_TOKEN);
527 }
528
529 "BIGINT" {
530 return(PARS_BIGINT_TOKEN);
531 }
532
533 {ID} {
534 yylval = sym_tab_add_id(pars_sym_tab_global,
535 (byte*) yytext,
536 ut_strlen(yytext));
537 return(PARS_ID_TOKEN);
538 }
539
540 {TABLE_NAME} {
541 yylval = sym_tab_add_id(pars_sym_tab_global,
542 (byte*) yytext,
543 ut_strlen(yytext));
544 return(PARS_TABLE_NAME_TOKEN);
545 }
546
547 ".." {
548 return(PARS_DDOT_TOKEN);
549 }
550
551 ":=" {
552 return(PARS_ASSIGN_TOKEN);
553 }
554
555 "<=" {
556 return(PARS_LE_TOKEN);
557 }
558
559 ">=" {
560 return(PARS_GE_TOKEN);
561 }
562
563 "<>" {
564 return(PARS_NE_TOKEN);
565 }
566
567 "(" {
568
569 return((int)(*yytext));
570 }
571
572 "=" {
573
574 return((int)(*yytext));
575 }
576
577 ">" {
578
579 return((int)(*yytext));
580 }
581
582 "<" {
583
584 return((int)(*yytext));
585 }
586
587 "," {
588
589 return((int)(*yytext));
590 }
591
592 ";" {
593
594 return((int)(*yytext));
595 }
596
597 ")" {
598
599 return((int)(*yytext));
600 }
601
602 "+" {
603
604 return((int)(*yytext));
605 }
606
607 "-" {
608
609 return((int)(*yytext));
610 }
611
612 "*" {
613
614 return((int)(*yytext));
615 }
616
617 "/" {
618
619 return((int)(*yytext));
620 }
621
622 "%" {
623
624 return((int)(*yytext));
625 }
626
627 "{" {
628
629 return((int)(*yytext));
630 }
631
632 "}" {
633
634 return((int)(*yytext));
635 }
636
637 "?" {
638
639 return((int)(*yytext));
640 }
641
642 "/*" BEGIN(comment); /* eat up comment */
643
644 <comment>[^*]*
645 <comment>"*"+[^*/]*
646 <comment>"*"+"/" BEGIN(INITIAL);
647
648 [ \t\n]+ /* eat up whitespace */
649
650
651 . {
652 fprintf(stderr,"Unrecognized character: %02x\n",
653 *yytext);
654
655 ut_error;
656
657 return(0);
658 }
659
660 %%
661
662 /**********************************************************************
663 Release any resources used by the lexer. */
664 void
665 pars_lexer_close(void)
666 /*==================*/
667 {
668 yylex_destroy();
669 free(stringbuf);
670 stringbuf = NULL;
671 stringbuf_len_alloc = stringbuf_len = 0;
672 }