1 #line 2 "scan.c"
2 #line 2 "scan.l"
3 /*-------------------------------------------------------------------------
4 *
5 * scan.l
6 * lexical scanner for PostgreSQL
7 *
8 * NOTE NOTE NOTE:
9 *
10 * The rules in this file must be kept in sync with src/fe_utils/psqlscan.l
11 * and src/interfaces/ecpg/preproc/pgc.l!
12 *
13 * The rules are designed so that the scanner never has to backtrack,
14 * in the sense that there is always a rule that can match the input
15 * consumed so far (the rule action may internally throw back some input
16 * with yyless(), however). As explained in the flex manual, this makes
17 * for a useful speed increase --- about a third faster than a plain -CF
18 * lexer, in simple testing. The extra complexity is mostly in the rules
19 * for handling float numbers and continued string literals. If you change
20 * the lexical rules, verify that you haven't broken the no-backtrack
21 * property by running flex with the "-b" option and checking that the
22 * resulting "lex.backup" file says that no backing up is needed. (As of
23 * Postgres 9.2, this check is made automatically by the Makefile.)
24 *
25 *
26 * Portions Copyright (c) 2003-2019, PgPool Global Development Group
27 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
28 * Portions Copyright (c) 1994, Regents of the University of California
29 *
30 * IDENTIFICATION
31 * src/backend/parser/scan.l
32 *
33 *-------------------------------------------------------------------------
34 */
35 #include "pool_parser.h"
36
37 #include <ctype.h>
38 #include <unistd.h>
39
40 #include "parser.h" /* only needed for GUC variables */
41 #include "scanner.h"
42 #include "gramparse.h"
43 #include "scansup.h"
44 #include "kwlookup.h"
45 #include "pg_wchar.h"
46
47 #include "gram.h"
48 #include "utils/palloc.h"
49 #include "utils/elog.h"
50
51
52
53 #line 54 "scan.c"
54
55 #define YY_INT_ALIGNED short int
56
57 /* A lexical scanner generated by flex */
58
59 #define FLEX_SCANNER
60 #define YY_FLEX_MAJOR_VERSION 2
61 #define YY_FLEX_MINOR_VERSION 5
62 #define YY_FLEX_SUBMINOR_VERSION 37
63 #if YY_FLEX_SUBMINOR_VERSION > 0
64 #define FLEX_BETA
65 #endif
66
67 /* First, we deal with platform-specific or compiler-specific issues. */
68
69 /* begin standard C headers. */
70 #include <stdio.h>
71 #include <string.h>
72 #include <errno.h>
73 #include <stdlib.h>
74
75 /* end standard C headers. */
76
77 /* flex integer type definitions */
78
79 #ifndef FLEXINT_H
80 #define FLEXINT_H
81
82 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
83
84 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
85
86 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
87 * if you want the limit (max/min) macros for int types.
88 */
89 #ifndef __STDC_LIMIT_MACROS
90 #define __STDC_LIMIT_MACROS 1
91 #endif
92
93 #include <inttypes.h>
94 typedef int8_t flex_int8_t;
95 typedef uint8_t flex_uint8_t;
96 typedef int16_t flex_int16_t;
97 typedef uint16_t flex_uint16_t;
98 typedef int32_t flex_int32_t;
99 typedef uint32_t flex_uint32_t;
100 #else
101 typedef signed char flex_int8_t;
102 typedef short int flex_int16_t;
103 typedef int flex_int32_t;
104 typedef unsigned char flex_uint8_t;
105 typedef unsigned short int flex_uint16_t;
106 typedef unsigned int flex_uint32_t;
107
108 /* Limits of integral types. */
109 #ifndef INT8_MIN
110 #define INT8_MIN (-128)
111 #endif
112 #ifndef INT16_MIN
113 #define INT16_MIN (-32767-1)
114 #endif
115 #ifndef INT32_MIN
116 #define INT32_MIN (-2147483647-1)
117 #endif
118 #ifndef INT8_MAX
119 #define INT8_MAX (127)
120 #endif
121 #ifndef INT16_MAX
122 #define INT16_MAX (32767)
123 #endif
124 #ifndef INT32_MAX
125 #define INT32_MAX (2147483647)
126 #endif
127 #ifndef UINT8_MAX
128 #define UINT8_MAX (255U)
129 #endif
130 #ifndef UINT16_MAX
131 #define UINT16_MAX (65535U)
132 #endif
133 #ifndef UINT32_MAX
134 #define UINT32_MAX (4294967295U)
135 #endif
136
137 #endif /* ! C99 */
138
139 #endif /* ! FLEXINT_H */
140
141 #ifdef __cplusplus
142
143 /* The "const" storage-class-modifier is valid. */
144 #define YY_USE_CONST
145
146 #else /* ! __cplusplus */
147
148 /* C99 requires __STDC__ to be defined as 1. */
149 #if defined (__STDC__)
150
151 #define YY_USE_CONST
152
153 #endif /* defined (__STDC__) */
154 #endif /* ! __cplusplus */
155
156 #ifdef YY_USE_CONST
157 #define yyconst const
158 #else
159 #define yyconst
160 #endif
161
162 /* Returned upon end-of-file. */
163 #define YY_NULL 0
164
165 /* Promotes a possibly negative, possibly signed char to an unsigned
166 * integer for use as an array index. If the signed char is negative,
167 * we want to instead treat it as an 8-bit unsigned char, hence the
168 * double cast.
169 */
170 #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
171
172 /* An opaque pointer. */
173 #ifndef YY_TYPEDEF_YY_SCANNER_T
174 #define YY_TYPEDEF_YY_SCANNER_T
175 typedef void* yyscan_t;
176 #endif
177
178 /* For convenience, these vars (plus the bison vars far below)
179 are macros in the reentrant scanner. */
180 #define yyin yyg->yyin_r
181 #define yyout yyg->yyout_r
182 #define yyextra yyg->yyextra_r
183 #define yyleng yyg->yyleng_r
184 #define yytext yyg->yytext_r
185 #define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
186 #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
187 #define yy_flex_debug yyg->yy_flex_debug_r
188
189 /* Enter a start condition. This macro really ought to take a parameter,
190 * but we do it the disgusting crufty way forced on us by the ()-less
191 * definition of BEGIN.
192 */
193 #define BEGIN yyg->yy_start = 1 + 2 *
194
195 /* Translate the current start state into a value that can be later handed
196 * to BEGIN to return to the state. The YYSTATE alias is for lex
197 * compatibility.
198 */
199 #define YY_START ((yyg->yy_start - 1) / 2)
200 #define YYSTATE YY_START
201
202 /* Action number for EOF rule of a given start state. */
203 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
204
205 /* Special action meaning "start processing a new file". */
206 #define YY_NEW_FILE core_yyrestart(yyin ,yyscanner )
207
208 #define YY_END_OF_BUFFER_CHAR 0
209
210 /* Size of default input buffer. */
211 #ifndef YY_BUF_SIZE
212 #define YY_BUF_SIZE 16384
213 #endif
214
215 /* The state buf must be large enough to hold one state per character in the main buffer.
216 */
217 #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
218
219 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
220 #define YY_TYPEDEF_YY_BUFFER_STATE
221 typedef struct yy_buffer_state *YY_BUFFER_STATE;
222 #endif
223
224 #ifndef YY_TYPEDEF_YY_SIZE_T
225 #define YY_TYPEDEF_YY_SIZE_T
226 typedef size_t yy_size_t;
227 #endif
228
229 #define EOB_ACT_CONTINUE_SCAN 0
230 #define EOB_ACT_END_OF_FILE 1
231 #define EOB_ACT_LAST_MATCH 2
232
233 #define YY_LESS_LINENO(n)
234
235 /* Return all but the first "n" matched characters back to the input stream. */
236 #define yyless(n) \
237 do \
238 { \
239 /* Undo effects of setting up yytext. */ \
240 int yyless_macro_arg = (n); \
241 YY_LESS_LINENO(yyless_macro_arg);\
242 *yy_cp = yyg->yy_hold_char; \
243 YY_RESTORE_YY_MORE_OFFSET \
244 yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
245 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
246 } \
247 while ( 0 )
248
249 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
250
251 #ifndef YY_STRUCT_YY_BUFFER_STATE
252 #define YY_STRUCT_YY_BUFFER_STATE
253 struct yy_buffer_state
254 {
255 FILE *yy_input_file;
256
257 char *yy_ch_buf; /* input buffer */
258 char *yy_buf_pos; /* current position in input buffer */
259
260 /* Size of input buffer in bytes, not including room for EOB
261 * characters.
262 */
263 yy_size_t yy_buf_size;
264
265 /* Number of characters read into yy_ch_buf, not including EOB
266 * characters.
267 */
268 yy_size_t yy_n_chars;
269
270 /* Whether we "own" the buffer - i.e., we know we created it,
271 * and can realloc() it to grow it, and should free() it to
272 * delete it.
273 */
274 int yy_is_our_buffer;
275
276 /* Whether this is an "interactive" input source; if so, and
277 * if we're using stdio for input, then we want to use getc()
278 * instead of fread(), to make sure we stop fetching input after
279 * each newline.
280 */
281 int yy_is_interactive;
282
283 /* Whether we're considered to be at the beginning of a line.
284 * If so, '^' rules will be active on the next match, otherwise
285 * not.
286 */
287 int yy_at_bol;
288
289 int yy_bs_lineno; /**< The line count. */
290 int yy_bs_column; /**< The column count. */
291
292 /* Whether to try to fill the input buffer when we reach the
293 * end of it.
294 */
295 int yy_fill_buffer;
296
297 int yy_buffer_status;
298
299 #define YY_BUFFER_NEW 0
300 #define YY_BUFFER_NORMAL 1
301 /* When an EOF's been seen but there's still some text to process
302 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
303 * shouldn't try reading from the input source any more. We might
304 * still have a bunch of tokens to match, though, because of
305 * possible backing-up.
306 *
307 * When we actually see the EOF, we change the status to "new"
308 * (via core_yyrestart()), so that the user can continue scanning by
309 * just pointing yyin at a new input file.
310 */
311 #define YY_BUFFER_EOF_PENDING 2
312
313 };
314 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
315
316 /* We provide macros for accessing buffer states in case in the
317 * future we want to put the buffer states in a more general
318 * "scanner state".
319 *
320 * Returns the top of the stack, or NULL.
321 */
322 #define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
323 ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
324 : NULL)
325
326 /* Same as previous macro, but useful when we know that the buffer stack is not
327 * NULL or when we need an lvalue. For internal use only.
328 */
329 #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
330
331 void core_yyrestart (FILE *input_file ,yyscan_t yyscanner );
332 void core_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
333 YY_BUFFER_STATE core_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
334 void core_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
335 void core_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
336 void core_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
337 void core_yypop_buffer_state (yyscan_t yyscanner );
338
339 static void core_yyensure_buffer_stack (yyscan_t yyscanner );
340 static void core_yy_load_buffer_state (yyscan_t yyscanner );
341 static void core_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
342
343 #define YY_FLUSH_BUFFER core_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
344
345 YY_BUFFER_STATE core_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
346 YY_BUFFER_STATE core_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
347 YY_BUFFER_STATE core_yy_scan_bytes (yyconst char *bytes,yy_size_t len ,yyscan_t yyscanner );
348
349 void *core_yyalloc (yy_size_t ,yyscan_t yyscanner );
350 void *core_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
351 void core_yyfree (void * ,yyscan_t yyscanner );
352
353 #define yy_new_buffer core_yy_create_buffer
354
355 #define yy_set_interactive(is_interactive) \
356 { \
357 if ( ! YY_CURRENT_BUFFER ){ \
358 core_yyensure_buffer_stack (yyscanner); \
359 YY_CURRENT_BUFFER_LVALUE = \
360 core_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
361 } \
362 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
363 }
364
365 #define yy_set_bol(at_bol) \
366 { \
367 if ( ! YY_CURRENT_BUFFER ){\
368 core_yyensure_buffer_stack (yyscanner); \
369 YY_CURRENT_BUFFER_LVALUE = \
370 core_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
371 } \
372 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
373 }
374
375 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
376
377 /* Begin user sect3 */
378
379 #define core_yywrap(yyscanner) 1
380 #define YY_SKIP_YYWRAP
381
382 typedef unsigned char YY_CHAR;
383
384 typedef int yy_state_type;
385
386 #define yytext_ptr yytext_r
387
388 static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
389 static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
390 static int yy_get_next_buffer (yyscan_t yyscanner );
391 static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
392
393 /* Done after the current pattern has been matched and before the
394 * corresponding action - sets up yytext.
395 */
396 #define YY_DO_BEFORE_ACTION \
397 yyg->yytext_ptr = yy_bp; \
398 yyleng = (size_t) (yy_cp - yy_bp); \
399 yyg->yy_hold_char = *yy_cp; \
400 *yy_cp = '\0'; \
401 yyg->yy_c_buf_p = yy_cp;
402
403 #define YY_NUM_RULES 79
404 #define YY_END_OF_BUFFER 80
405 /* This struct is not used in this scanner,
406 but its presence is necessary. */
407 struct yy_trans_info
408 {
409 flex_int32_t yy_verify;
410 flex_int32_t yy_nxt;
411 };
412 static yyconst flex_int16_t yy_accept[290] =
413 { 0,
414 0, 0, 12, 12, 0, 0, 0, 0, 11, 11,
415 0, 0, 0, 0, 0, 0, 0, 0, 55, 55,
416 0, 0, 28, 28, 0, 0, 80, 78, 1, 1,
417 69, 49, 69, 78, 68, 19, 68, 68, 68, 68,
418 71, 68, 68, 68, 68, 77, 77, 77, 77, 77,
419 77, 12, 9, 5, 5, 6, 6, 58, 51, 11,
420 16, 31, 22, 32, 32, 22, 42, 46, 46, 48,
421 52, 54, 53, 53, 54, 54, 24, 27, 26, 26,
422 27, 27, 35, 36, 35, 1, 69, 67, 43, 70,
423 44, 1, 61, 72, 2, 72, 71, 75, 60, 62,
424
425 64, 66, 63, 65, 77, 8, 20, 18, 59, 15,
426 12, 9, 9, 10, 5, 7, 4, 3, 58, 57,
427 11, 16, 16, 17, 31, 22, 22, 30, 23, 32,
428 38, 39, 37, 37, 38, 46, 45, 47, 53, 53,
429 55, 24, 24, 25, 26, 26, 28, 37, 37, 44,
430 1, 1, 2, 73, 72, 76, 74, 50, 21, 9,
431 14, 10, 9, 3, 16, 13, 17, 16, 22, 41,
432 23, 22, 39, 37, 37, 40, 47, 53, 55, 24,
433 25, 24, 26, 28, 37, 37, 9, 9, 9, 9,
434 16, 16, 16, 16, 22, 22, 22, 22, 39, 37,
435
436 37, 40, 55, 24, 24, 24, 24, 28, 37, 37,
437 9, 9, 9, 9, 9, 16, 16, 16, 16, 16,
438 22, 22, 22, 22, 22, 37, 37, 55, 24, 24,
439 24, 24, 24, 28, 37, 37, 9, 16, 22, 37,
440 33, 55, 24, 28, 37, 34, 37, 55, 28, 37,
441 37, 55, 55, 55, 28, 28, 28, 37, 37, 55,
442 55, 28, 28, 37, 56, 55, 55, 55, 55, 29,
443 28, 28, 28, 28, 55, 55, 55, 55, 55, 28,
444 28, 28, 28, 28, 55, 55, 28, 28, 0
445 } ;
446
447 static yyconst flex_int32_t yy_ec[256] =
448 { 0,
449 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
450 1, 2, 4, 1, 1, 1, 1, 1, 1, 1,
451 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
452 1, 2, 5, 6, 7, 8, 9, 10, 11, 12,
453 12, 13, 14, 12, 15, 16, 17, 18, 18, 18,
454 18, 18, 18, 18, 18, 19, 19, 20, 12, 21,
455 22, 23, 7, 7, 24, 25, 26, 27, 28, 27,
456 29, 29, 29, 29, 29, 29, 29, 30, 29, 31,
457 29, 29, 32, 29, 33, 29, 29, 34, 29, 29,
458 12, 35, 12, 9, 29, 7, 24, 25, 26, 27,
459
460 28, 27, 29, 29, 29, 29, 29, 29, 29, 30,
461 29, 31, 29, 29, 32, 29, 36, 29, 29, 37,
462 29, 29, 1, 7, 1, 7, 1, 29, 29, 29,
463 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
464 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
465 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
466 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
467 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
468 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
469 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
470
471 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
472 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
473 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
474 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
475 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
476 29, 29, 29, 29, 29
477 } ;
478
479 static yyconst flex_int32_t yy_meta[38] =
480 { 0,
481 1, 1, 2, 2, 3, 4, 3, 5, 3, 3,
482 6, 1, 7, 3, 3, 1, 7, 8, 8, 1,
483 3, 3, 3, 9, 9, 9, 9, 9, 10, 10,
484 10, 10, 10, 10, 11, 10, 10
485 } ;
486
487 static yyconst flex_int16_t yy_base[357] =
488 { 0,
489 0, 0, 368, 355, 33, 52, 359, 346, 340, 327,
490 326, 321, 41, 42, 55, 75, 325, 324, 82, 117,
491 313, 312, 152, 187, 36, 46, 318, 1171, 85, 88,
492 295, 1171, 0, 85, 0, 1171, 1171, 301, 80, 297,
493 89, 48, 57, 286, 282, 0, 292, 291, 279, 276,
494 274, 0, 98, 0, 0, 47, 269, 0, 274, 0,
495 107, 0, 122, 0, 0, 125, 98, 0, 0, 269,
496 270, 1171, 139, 142, 260, 245, 155, 1171, 145, 158,
497 257, 241, 1171, 1171, 132, 169, 0, 0, 1171, 76,
498 260, 219, 1171, 156, 0, 164, 177, 185, 1171, 1171,
499
500 0, 0, 0, 0, 0, 1171, 1171, 1171, 158, 1171,
501 0, 204, 207, 248, 0, 164, 1171, 0, 0, 1171,
502 0, 210, 235, 240, 0, 241, 249, 1171, 239, 0,
503 1171, 217, 0, 0, 0, 0, 1171, 223, 213, 0,
504 198, 255, 263, 212, 245, 0, 189, 0, 0, 193,
505 0, 274, 0, 1171, 243, 120, 133, 1171, 1171, 290,
506 1171, 183, 296, 0, 304, 1171, 182, 310, 318, 1171,
507 179, 324, 169, 0, 0, 0, 178, 0, 153, 332,
508 163, 338, 0, 150, 0, 0, 342, 346, 352, 356,
509 360, 366, 370, 374, 380, 384, 388, 394, 1171, 0,
510
511 0, 1171, 139, 398, 402, 408, 412, 106, 0, 0,
512 416, 422, 430, 436, 440, 444, 450, 458, 464, 468,
513 472, 478, 486, 492, 496, 0, 0, 92, 500, 506,
514 514, 520, 524, 83, 0, 0, 528, 534, 538, 0,
515 1171, 84, 542, 78, 0, 1171, 0, 548, 558, 0,
516 0, 563, 0, 67, 568, 0, 57, 0, 0, 40,
517 573, 30, 578, 0, 1171, 583, 588, 593, 598, 1171,
518 603, 608, 613, 618, 623, 628, 633, 638, 643, 648,
519 653, 658, 663, 668, 673, 0, 678, 0, 1171, 693,
520 704, 715, 726, 737, 748, 759, 770, 781, 792, 801,
521
522 804, 810, 820, 831, 842, 853, 864, 875, 885, 896,
523 903, 909, 919, 928, 933, 933, 935, 937, 942, 952,
524 963, 967, 969, 978, 989, 1000, 1004, 1006, 1008, 1017,
525 1021, 1023, 1032, 1043, 1054, 1058, 1060, 1069, 1073, 1075,
526 1077, 1079, 1081, 1083, 1085, 1087, 1089, 1091, 1093, 1102,
527 1113, 1117, 1126, 1137, 1148, 1159
528 } ;
529
530 static yyconst flex_int16_t yy_def[357] =
531 { 0,
532 289, 1, 290, 290, 291, 291, 292, 292, 293, 293,
533 294, 294, 295, 295, 296, 296, 292, 292, 297, 297,
534 294, 294, 298, 298, 299, 299, 289, 289, 289, 289,
535 300, 289, 300, 301, 300, 289, 289, 300, 289, 300,
536 289, 289, 300, 300, 300, 302, 302, 302, 302, 302,
537 302, 303, 289, 304, 304, 289, 289, 305, 289, 306,
538 289, 307, 289, 308, 308, 289, 309, 310, 310, 311,
539 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
540 289, 289, 289, 289, 289, 289, 300, 300, 289, 289,
541 312, 313, 289, 289, 314, 289, 289, 289, 289, 289,
542
543 300, 300, 300, 300, 302, 289, 289, 289, 289, 289,
544 303, 289, 289, 289, 304, 289, 289, 315, 305, 289,
545 306, 289, 289, 289, 307, 289, 289, 289, 289, 308,
546 289, 289, 316, 317, 318, 310, 289, 319, 289, 320,
547 289, 289, 289, 289, 289, 321, 289, 322, 323, 312,
548 313, 313, 314, 289, 289, 289, 289, 289, 289, 289,
549 289, 289, 324, 315, 289, 289, 289, 325, 289, 289,
550 289, 326, 289, 327, 328, 329, 319, 320, 289, 289,
551 289, 330, 321, 289, 331, 332, 333, 324, 324, 324,
552 334, 325, 325, 325, 335, 326, 326, 326, 289, 336,
553
554 337, 289, 289, 338, 330, 330, 330, 289, 339, 340,
555 333, 333, 289, 333, 324, 334, 334, 289, 334, 325,
556 335, 335, 289, 335, 326, 341, 342, 289, 338, 338,
557 289, 338, 330, 289, 343, 344, 333, 334, 335, 345,
558 289, 289, 338, 289, 346, 289, 347, 289, 289, 348,
559 349, 289, 350, 289, 289, 351, 289, 352, 342, 289,
560 353, 289, 354, 344, 289, 353, 353, 355, 353, 289,
561 354, 354, 356, 354, 353, 353, 289, 353, 353, 354,
562 354, 289, 354, 354, 355, 350, 356, 351, 0, 289,
563 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
564
565 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
566 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
567 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
568 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
569 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
570 289, 289, 289, 289, 289, 289
571 } ;
572
573 static yyconst flex_int16_t yy_nxt[1209] =
574 { 0,
575 28, 29, 30, 29, 31, 32, 33, 34, 35, 33,
576 36, 37, 35, 35, 38, 39, 40, 41, 41, 42,
577 43, 44, 45, 46, 47, 46, 46, 48, 46, 49,
578 46, 46, 50, 51, 28, 50, 51, 55, 84, 55,
579 270, 55, 55, 65, 65, 56, 55, 55, 84, 57,
580 265, 66, 66, 55, 55, 55, 55, 69, 55, 116,
581 55, 55, 70, 117, 56, 55, 55, 99, 57, 100,
582 85, 263, 55, 55, 55, 67, 67, 69, 101, 102,
583 85, 261, 70, 73, 74, 73, 86, 86, 86, 86,
584 86, 86, 89, 90, 90, 93, 75, 94, 94, 112,
585
586 113, 113, 90, 90, 96, 249, 97, 97, 122, 123,
587 123, 248, 114, 244, 76, 132, 98, 76, 73, 74,
588 73, 124, 242, 126, 127, 127, 126, 127, 127, 234,
589 133, 75, 128, 134, 135, 128, 129, 157, 157, 129,
590 139, 139, 139, 139, 139, 139, 145, 145, 145, 76,
591 157, 157, 76, 79, 80, 79, 142, 143, 143, 145,
592 145, 145, 228, 158, 148, 128, 81, 149, 159, 144,
593 86, 86, 86, 94, 94, 208, 116, 204, 203, 154,
594 117, 155, 155, 98, 82, 137, 199, 82, 79, 80,
595 79, 98, 96, 195, 97, 97, 191, 187, 156, 156,
596
597 89, 81, 157, 157, 98, 112, 113, 113, 160, 160,
598 160, 122, 123, 123, 139, 139, 139, 161, 114, 82,
599 184, 162, 82, 152, 124, 152, 182, 152, 152, 179,
600 137, 152, 152, 152, 173, 152, 165, 165, 165, 152,
601 152, 152, 126, 127, 127, 166, 145, 145, 145, 167,
602 169, 169, 169, 172, 168, 129, 142, 143, 143, 170,
603 155, 155, 163, 171, 180, 180, 180, 89, 147, 144,
604 98, 146, 141, 170, 140, 120, 137, 181, 152, 120,
605 152, 118, 152, 152, 110, 109, 152, 152, 152, 108,
606 152, 160, 160, 160, 152, 152, 152, 189, 113, 113,
607
608 161, 107, 106, 104, 162, 165, 165, 165, 103, 95,
609 190, 193, 123, 123, 166, 92, 88, 289, 167, 169,
610 169, 169, 77, 77, 194, 197, 127, 127, 170, 71,
611 71, 63, 171, 180, 180, 180, 63, 61, 198, 206,
612 143, 143, 170, 212, 213, 213, 181, 189, 113, 113,
613 61, 59, 207, 189, 113, 113, 214, 189, 113, 113,
614 190, 217, 218, 218, 59, 53, 190, 193, 123, 123,
615 215, 193, 123, 123, 219, 193, 123, 123, 53, 289,
616 194, 222, 223, 223, 194, 197, 127, 127, 220, 197,
617 127, 127, 289, 289, 224, 197, 127, 127, 198, 230,
618
619 231, 231, 198, 206, 143, 143, 289, 289, 225, 206,
620 143, 143, 232, 206, 143, 143, 207, 212, 213, 213,
621 289, 289, 207, 212, 213, 213, 233, 289, 289, 289,
622 214, 160, 160, 160, 289, 289, 214, 212, 213, 213,
623 161, 189, 113, 113, 162, 217, 218, 218, 289, 289,
624 237, 217, 218, 218, 215, 289, 289, 289, 219, 165,
625 165, 165, 289, 289, 219, 217, 218, 218, 166, 193,
626 123, 123, 167, 222, 223, 223, 289, 289, 238, 222,
627 223, 223, 220, 289, 289, 289, 224, 169, 169, 169,
628 289, 289, 224, 222, 223, 223, 170, 197, 127, 127,
629
630 171, 230, 231, 231, 289, 289, 239, 230, 231, 231,
631 225, 289, 289, 289, 232, 180, 180, 180, 289, 289,
632 232, 230, 231, 231, 170, 206, 143, 143, 181, 212,
633 213, 213, 289, 289, 243, 217, 218, 218, 233, 222,
634 223, 223, 237, 230, 231, 231, 289, 289, 238, 252,
635 252, 252, 239, 289, 289, 289, 243, 289, 253, 255,
636 255, 255, 254, 289, 252, 252, 252, 289, 256, 255,
637 255, 255, 257, 253, 267, 252, 252, 254, 256, 272,
638 255, 255, 257, 268, 267, 252, 252, 269, 273, 267,
639 252, 252, 274, 268, 276, 277, 277, 269, 268, 267,
640
641 252, 252, 269, 268, 272, 255, 255, 278, 268, 272,
642 255, 255, 279, 273, 281, 282, 282, 274, 273, 272,
643 255, 255, 274, 273, 267, 252, 252, 283, 273, 267,
644 252, 252, 284, 285, 252, 252, 252, 269, 285, 267,
645 252, 252, 269, 286, 267, 252, 252, 254, 285, 272,
646 255, 255, 279, 268, 272, 255, 255, 279, 287, 255,
647 255, 255, 274, 287, 272, 255, 255, 274, 288, 272,
648 255, 255, 257, 287, 276, 277, 277, 284, 273, 281,
649 282, 282, 284, 268, 289, 289, 289, 278, 273, 289,
650 289, 289, 283, 52, 52, 52, 52, 52, 52, 52,
651
652 52, 52, 52, 52, 54, 54, 54, 54, 54, 54,
653 54, 54, 54, 54, 54, 58, 58, 58, 58, 58,
654 58, 58, 58, 58, 58, 58, 60, 60, 60, 60,
655 60, 60, 60, 60, 60, 60, 60, 62, 62, 62,
656 62, 62, 62, 62, 62, 62, 62, 62, 64, 64,
657 64, 64, 64, 64, 64, 64, 64, 64, 64, 68,
658 68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
659 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
660 72, 78, 78, 78, 78, 78, 78, 78, 78, 78,
661 78, 78, 83, 83, 83, 83, 83, 83, 83, 83,
662
663 83, 83, 83, 87, 289, 289, 289, 87, 91, 289,
664 289, 91, 91, 91, 105, 289, 289, 105, 105, 105,
665 111, 111, 111, 111, 111, 289, 111, 111, 111, 111,
666 111, 115, 115, 115, 115, 115, 115, 289, 115, 115,
667 115, 115, 119, 119, 119, 289, 119, 119, 119, 119,
668 119, 119, 119, 121, 121, 121, 121, 121, 289, 121,
669 121, 121, 121, 121, 125, 125, 125, 125, 125, 289,
670 125, 125, 125, 125, 125, 130, 130, 130, 130, 130,
671 289, 130, 130, 130, 130, 131, 131, 131, 131, 131,
672 131, 131, 131, 131, 131, 131, 136, 136, 136, 136,
673
674 289, 136, 136, 136, 136, 136, 136, 138, 289, 289,
675 289, 138, 138, 150, 289, 289, 150, 150, 150, 151,
676 289, 151, 151, 151, 151, 151, 151, 151, 151, 151,
677 153, 289, 289, 289, 153, 164, 289, 289, 289, 164,
678 174, 174, 175, 175, 176, 176, 177, 289, 289, 177,
679 177, 177, 178, 289, 178, 178, 178, 178, 178, 178,
680 178, 178, 178, 183, 289, 183, 183, 183, 183, 183,
681 183, 183, 183, 183, 185, 185, 186, 186, 188, 188,
682 188, 188, 188, 188, 188, 188, 188, 188, 188, 192,
683 192, 192, 192, 192, 192, 192, 192, 192, 192, 192,
684
685 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
686 196, 200, 200, 201, 201, 202, 202, 205, 205, 205,
687 205, 205, 205, 205, 205, 205, 205, 205, 209, 209,
688 210, 210, 211, 211, 211, 211, 211, 211, 211, 211,
689 211, 211, 211, 216, 216, 216, 216, 216, 216, 216,
690 216, 216, 216, 216, 221, 221, 221, 221, 221, 221,
691 221, 221, 221, 221, 221, 226, 226, 227, 227, 229,
692 229, 229, 229, 229, 229, 229, 229, 229, 229, 229,
693 235, 235, 236, 236, 240, 240, 241, 241, 245, 245,
694 246, 246, 247, 247, 250, 250, 251, 251, 258, 258,
695
696 259, 259, 260, 260, 260, 260, 260, 289, 260, 260,
697 260, 260, 260, 262, 262, 262, 262, 262, 289, 262,
698 262, 262, 262, 262, 264, 264, 266, 266, 266, 266,
699 266, 266, 266, 266, 266, 266, 266, 271, 271, 271,
700 271, 271, 271, 271, 271, 271, 271, 271, 275, 275,
701 275, 275, 275, 275, 275, 275, 275, 275, 275, 280,
702 280, 280, 280, 280, 280, 280, 280, 280, 280, 280,
703 27, 289, 289, 289, 289, 289, 289, 289, 289, 289,
704 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
705 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
706
707 289, 289, 289, 289, 289, 289, 289, 289
708 } ;
709
710 static yyconst flex_int16_t yy_chk[1209] =
711 { 0,
712 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
713 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
714 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
715 1, 1, 1, 1, 1, 1, 1, 5, 25, 5,
716 262, 5, 5, 13, 14, 5, 5, 5, 26, 5,
717 260, 13, 14, 5, 5, 5, 6, 15, 6, 56,
718 6, 6, 15, 56, 6, 6, 6, 42, 6, 42,
719 25, 257, 6, 6, 6, 13, 14, 16, 43, 43,
720 26, 254, 16, 19, 19, 19, 29, 29, 29, 30,
721 30, 30, 34, 90, 90, 39, 19, 39, 39, 53,
722
723 53, 53, 34, 34, 41, 244, 41, 41, 61, 61,
724 61, 242, 53, 234, 19, 67, 41, 19, 20, 20,
725 20, 61, 228, 63, 63, 63, 66, 66, 66, 208,
726 67, 20, 63, 67, 67, 66, 63, 156, 156, 66,
727 73, 73, 73, 74, 74, 74, 79, 79, 79, 20,
728 157, 157, 20, 23, 23, 23, 77, 77, 77, 80,
729 80, 80, 203, 109, 85, 77, 23, 85, 109, 77,
730 86, 86, 86, 94, 94, 184, 116, 181, 179, 96,
731 116, 96, 96, 94, 23, 177, 173, 23, 24, 24,
732 24, 96, 97, 171, 97, 97, 167, 162, 98, 98,
733
734 150, 24, 98, 98, 97, 112, 112, 112, 113, 113,
735 113, 122, 122, 122, 139, 139, 139, 113, 112, 24,
736 147, 113, 24, 92, 122, 92, 144, 92, 92, 141,
737 138, 92, 92, 92, 132, 92, 123, 123, 123, 92,
738 92, 92, 126, 126, 126, 123, 145, 145, 145, 123,
739 127, 127, 127, 129, 124, 126, 142, 142, 142, 127,
740 155, 155, 114, 127, 143, 143, 143, 91, 82, 142,
741 155, 81, 76, 143, 75, 71, 70, 143, 152, 59,
742 152, 57, 152, 152, 51, 50, 152, 152, 152, 49,
743 152, 160, 160, 160, 152, 152, 152, 163, 163, 163,
744
745 160, 48, 47, 45, 160, 165, 165, 165, 44, 40,
746 163, 168, 168, 168, 165, 38, 31, 27, 165, 169,
747 169, 169, 22, 21, 168, 172, 172, 172, 169, 18,
748 17, 12, 169, 180, 180, 180, 11, 10, 172, 182,
749 182, 182, 180, 187, 187, 187, 180, 188, 188, 188,
750 9, 8, 182, 189, 189, 189, 187, 190, 190, 190,
751 188, 191, 191, 191, 7, 4, 189, 192, 192, 192,
752 190, 193, 193, 193, 191, 194, 194, 194, 3, 0,
753 192, 195, 195, 195, 193, 196, 196, 196, 194, 197,
754 197, 197, 0, 0, 195, 198, 198, 198, 196, 204,
755
756 204, 204, 197, 205, 205, 205, 0, 0, 198, 206,
757 206, 206, 204, 207, 207, 207, 205, 211, 211, 211,
758 0, 0, 206, 212, 212, 212, 207, 0, 0, 0,
759 211, 213, 213, 213, 0, 0, 212, 214, 214, 214,
760 213, 215, 215, 215, 213, 216, 216, 216, 0, 0,
761 214, 217, 217, 217, 215, 0, 0, 0, 216, 218,
762 218, 218, 0, 0, 217, 219, 219, 219, 218, 220,
763 220, 220, 218, 221, 221, 221, 0, 0, 219, 222,
764 222, 222, 220, 0, 0, 0, 221, 223, 223, 223,
765 0, 0, 222, 224, 224, 224, 223, 225, 225, 225,
766
767 223, 229, 229, 229, 0, 0, 224, 230, 230, 230,
768 225, 0, 0, 0, 229, 231, 231, 231, 0, 0,
769 230, 232, 232, 232, 231, 233, 233, 233, 231, 237,
770 237, 237, 0, 0, 232, 238, 238, 238, 233, 239,
771 239, 239, 237, 243, 243, 243, 0, 0, 238, 248,
772 248, 248, 239, 0, 0, 0, 243, 0, 248, 249,
773 249, 249, 248, 0, 252, 252, 252, 0, 249, 255,
774 255, 255, 249, 252, 261, 261, 261, 252, 255, 263,
775 263, 263, 255, 261, 266, 266, 266, 261, 263, 267,
776 267, 267, 263, 266, 268, 268, 268, 266, 267, 269,
777
778 269, 269, 267, 268, 271, 271, 271, 268, 269, 272,
779 272, 272, 269, 271, 273, 273, 273, 271, 272, 274,
780 274, 274, 272, 273, 275, 275, 275, 273, 274, 276,
781 276, 276, 274, 275, 277, 277, 277, 275, 276, 278,
782 278, 278, 276, 277, 279, 279, 279, 277, 278, 280,
783 280, 280, 278, 279, 281, 281, 281, 279, 280, 282,
784 282, 282, 280, 281, 283, 283, 283, 281, 282, 284,
785 284, 284, 282, 283, 285, 285, 285, 283, 284, 287,
786 287, 287, 284, 285, 0, 0, 0, 285, 287, 0,
787 0, 0, 287, 290, 290, 290, 290, 290, 290, 290,
788
789 290, 290, 290, 290, 291, 291, 291, 291, 291, 291,
790 291, 291, 291, 291, 291, 292, 292, 292, 292, 292,
791 292, 292, 292, 292, 292, 292, 293, 293, 293, 293,
792 293, 293, 293, 293, 293, 293, 293, 294, 294, 294,
793 294, 294, 294, 294, 294, 294, 294, 294, 295, 295,
794 295, 295, 295, 295, 295, 295, 295, 295, 295, 296,
795 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
796 297, 297, 297, 297, 297, 297, 297, 297, 297, 297,
797 297, 298, 298, 298, 298, 298, 298, 298, 298, 298,
798 298, 298, 299, 299, 299, 299, 299, 299, 299, 299,
799
800 299, 299, 299, 300, 0, 0, 0, 300, 301, 0,
801 0, 301, 301, 301, 302, 0, 0, 302, 302, 302,
802 303, 303, 303, 303, 303, 0, 303, 303, 303, 303,
803 303, 304, 304, 304, 304, 304, 304, 0, 304, 304,
804 304, 304, 305, 305, 305, 0, 305, 305, 305, 305,
805 305, 305, 305, 306, 306, 306, 306, 306, 0, 306,
806 306, 306, 306, 306, 307, 307, 307, 307, 307, 0,
807 307, 307, 307, 307, 307, 308, 308, 308, 308, 308,
808 0, 308, 308, 308, 308, 309, 309, 309, 309, 309,
809 309, 309, 309, 309, 309, 309, 310, 310, 310, 310,
810
811 0, 310, 310, 310, 310, 310, 310, 311, 0, 0,
812 0, 311, 311, 312, 0, 0, 312, 312, 312, 313,
813 0, 313, 313, 313, 313, 313, 313, 313, 313, 313,
814 314, 0, 0, 0, 314, 315, 0, 0, 0, 315,
815 316, 316, 317, 317, 318, 318, 319, 0, 0, 319,
816 319, 319, 320, 0, 320, 320, 320, 320, 320, 320,
817 320, 320, 320, 321, 0, 321, 321, 321, 321, 321,
818 321, 321, 321, 321, 322, 322, 323, 323, 324, 324,
819 324, 324, 324, 324, 324, 324, 324, 324, 324, 325,
820 325, 325, 325, 325, 325, 325, 325, 325, 325, 325,
821
822 326, 326, 326, 326, 326, 326, 326, 326, 326, 326,
823 326, 327, 327, 328, 328, 329, 329, 330, 330, 330,
824 330, 330, 330, 330, 330, 330, 330, 330, 331, 331,
825 332, 332, 333, 333, 333, 333, 333, 333, 333, 333,
826 333, 333, 333, 334, 334, 334, 334, 334, 334, 334,
827 334, 334, 334, 334, 335, 335, 335, 335, 335, 335,
828 335, 335, 335, 335, 335, 336, 336, 337, 337, 338,
829 338, 338, 338, 338, 338, 338, 338, 338, 338, 338,
830 339, 339, 340, 340, 341, 341, 342, 342, 343, 343,
831 344, 344, 345, 345, 346, 346, 347, 347, 348, 348,
832
833 349, 349, 350, 350, 350, 350, 350, 0, 350, 350,
834 350, 350, 350, 351, 351, 351, 351, 351, 0, 351,
835 351, 351, 351, 351, 352, 352, 353, 353, 353, 353,
836 353, 353, 353, 353, 353, 353, 353, 354, 354, 354,
837 354, 354, 354, 354, 354, 354, 354, 354, 355, 355,
838 355, 355, 355, 355, 355, 355, 355, 355, 355, 356,
839 356, 356, 356, 356, 356, 356, 356, 356, 356, 356,
840 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
841 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
842 289, 289, 289, 289, 289, 289, 289, 289, 289, 289,
843
844 289, 289, 289, 289, 289, 289, 289, 289
845 } ;
846
847 /* The intent behind this definition is that it'll catch
848 * any uses of REJECT which flex missed.
849 */
850 #define REJECT reject_used_but_not_detected
851 #define yymore() yymore_used_but_not_detected
852 #define YY_MORE_ADJ 0
853 #define YY_RESTORE_YY_MORE_OFFSET
854 #line 1 "scan.l"
855
856 #line 52 "scan.l"
857
858 /* LCOV_EXCL_START */
859
860 /* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
861 #undef fprintf
862 #define fprintf(file, fmt, msg) fprintf_to_ereport(fmt, msg)
863
864 static void
fprintf_to_ereport(const char * fmt,const char * msg)865 fprintf_to_ereport(const char *fmt, const char *msg)
866 {
867 ereport(ERROR, (errmsg_internal("%s", msg)));
868 }
869
870 /*
871 * GUC variables. This is a DIRECT violation of the warning given at the
872 * head of gram.y, ie flex/bison code must not depend on any GUC variables;
873 * as such, changing their values can induce very unintuitive behavior.
874 * But we shall have to live with it until we can remove these variables.
875 */
876 int backslash_quote = BACKSLASH_QUOTE_SAFE_ENCODING;
877 bool escape_string_warning = true;
878 bool standard_conforming_strings = true;
879
880 /*
881 * Constant data exported from this file. This array maps from the
882 * zero-based keyword numbers returned by ScanKeywordLookup to the
883 * Bison token numbers needed by gram.y. This is exported because
884 * callers need to pass it to scanner_init, if they are using the
885 * standard keyword list ScanKeywords.
886 */
887 #define PG_KEYWORD(kwname, value, category) value,
888
889 const uint16 ScanKeywordTokens[] = {
890 #include "kwlist.h"
891 };
892
893 #undef PG_KEYWORD
894
895 /*
896 * Set the type of YYSTYPE.
897 */
898 #define YYSTYPE core_YYSTYPE
899
900 /*
901 * Set the type of yyextra. All state variables used by the scanner should
902 * be in yyextra, *not* statically allocated.
903 */
904 #define YY_EXTRA_TYPE core_yy_extra_type *
905
906 /*
907 * Each call to core_yylex must set yylloc to the location of the found token
908 * (expressed as a byte offset from the start of the input text).
909 * When we parse a token that requires multiple lexer rules to process,
910 * this should be done in the first such rule, else yylloc will point
911 * into the middle of the token.
912 */
913 #define SET_YYLLOC() (*(yylloc) = yytext - yyextra->scanbuf)
914
915 /*
916 * Advance yylloc by the given number of bytes.
917 */
918 #define ADVANCE_YYLLOC(delta) ( *(yylloc) += (delta) )
919
920 #define startlit() ( yyextra->literallen = 0 )
921 static void addlit(char *ytext, int yleng, core_yyscan_t yyscanner);
922 static void addlitchar(unsigned char ychar, core_yyscan_t yyscanner);
923 static char *litbufdup(core_yyscan_t yyscanner);
924 static char *litbuf_udeescape(unsigned char escape, core_yyscan_t yyscanner);
925 static unsigned char unescape_single_char(unsigned char c, core_yyscan_t yyscanner);
926 static int process_integer_literal(const char *token, YYSTYPE *lval);
927 static bool is_utf16_surrogate_first(pg_wchar c);
928 static bool is_utf16_surrogate_second(pg_wchar c);
929 static pg_wchar surrogate_pair_to_codepoint(pg_wchar first, pg_wchar second);
930 static void addunicode(pg_wchar c, yyscan_t yyscanner);
931 static bool check_uescapechar(unsigned char escape);
932
933 #define yyerror(msg) scanner_yyerror(msg, yyscanner)
934
935 #define lexer_errposition() scanner_errposition(*(yylloc), yyscanner)
936
937 static void check_string_escape_warning(unsigned char ychar, core_yyscan_t yyscanner);
938 static void check_escape_warning(core_yyscan_t yyscanner);
939
940 /*
941 * Work around a bug in flex 2.5.35: it emits a couple of functions that
942 * it forgets to emit declarations for. Since we use -Wmissing-prototypes,
943 * this would cause warnings. Providing our own declarations should be
944 * harmless even when the bug gets fixed.
945 */
946 extern int core_yyget_column(yyscan_t yyscanner);
947 extern void core_yyset_column(int column_no, yyscan_t yyscanner);
948
949 #define YY_NO_INPUT 1
950 /*
951 * OK, here is a short description of lex/flex rules behavior.
952 * The longest pattern which matches an input string is always chosen.
953 * For equal-length patterns, the first occurring in the rules list is chosen.
954 * INITIAL is the starting state, to which all non-conditional rules apply.
955 * Exclusive states change parsing rules while the state is active. When in
956 * an exclusive state, only those rules defined for that state apply.
957 *
958 * We use exclusive states for quoted strings, extended comments,
959 * and to eliminate parsing troubles for numeric strings.
960 * Exclusive states:
961 * <xb> bit string literal
962 * <xc> extended C-style comments
963 * <xd> delimited identifiers (double-quoted identifiers)
964 * <xh> hexadecimal numeric string
965 * <xq> standard quoted strings
966 * <xe> extended quoted strings (support backslash escape sequences)
967 * <xdolq> $foo$ quoted strings
968 * <xui> quoted identifier with Unicode escapes
969 * <xuiend> end of a quoted identifier with Unicode escapes, UESCAPE can follow
970 * <xus> quoted string with Unicode escapes
971 * <xusend> end of a quoted string with Unicode escapes, UESCAPE can follow
972 * <xeu> Unicode surrogate pair in extended quoted string
973 *
974 * Remember to add an <<EOF>> case whenever you add a new exclusive state!
975 * The default one is probably not the right thing.
976 */
977
978
979
980
981
982
983
984
985
986
987
988
989 /*
990 * In order to make the world safe for Windows and Mac clients as well as
991 * Unix ones, we accept either \n or \r as a newline. A DOS-style \r\n
992 * sequence will be seen as two successive newlines, but that doesn't cause
993 * any problems. Comments that start with -- and extend to the next
994 * newline are treated as equivalent to a single whitespace character.
995 *
996 * NOTE a fine point: if there is no newline following --, we will absorb
997 * everything to the end of the input as a comment. This is correct. Older
998 * versions of Postgres failed to recognize -- as a comment if the input
999 * did not end with a newline.
1000 *
1001 * XXX perhaps \f (formfeed) should be treated as a newline as well?
1002 *
1003 * XXX if you change the set of whitespace characters, fix scanner_isspace()
1004 * to agree.
1005 */
1006 /*
1007 * SQL requires at least one newline in the whitespace separating
1008 * string literals that are to be concatenated. Silly, but who are we
1009 * to argue? Note that {whitespace_with_newline} should not have * after
1010 * it, whereas {whitespace} should generally have a * after it...
1011 */
1012 /*
1013 * To ensure that {quotecontinue} can be scanned without having to back up
1014 * if the full pattern isn't matched, we include trailing whitespace in
1015 * {quotestop}. This matches all cases where {quotecontinue} fails to match,
1016 * except for {quote} followed by whitespace and just one "-" (not two,
1017 * which would start a {comment}). To cover that we have {quotefail}.
1018 * The actions for {quotestop} and {quotefail} must throw back characters
1019 * beyond the quote proper.
1020 */
1021 /* Bit string
1022 * It is tempting to scan the string for only those characters
1023 * which are allowed. However, this leads to silently swallowed
1024 * characters if illegal characters are included in the string.
1025 * For example, if xbinside is [01] then B'ABCD' is interpreted
1026 * as a zero-length string, and the ABCD' is lost!
1027 * Better to pass the string forward and let the input routines
1028 * validate the contents.
1029 */
1030 /* Hexadecimal number */
1031 /* National character */
1032 /* Quoted string that allows backslash escapes */
1033 /* Extended quote
1034 * xqdouble implements embedded quote, ''''
1035 */
1036 /* $foo$ style quotes ("dollar quoting")
1037 * The quoted string starts with $foo$ where "foo" is an optional string
1038 * in the form of an identifier, except that it may not contain "$",
1039 * and extends to the first occurrence of an identical string.
1040 * There is *no* processing of the quoted text.
1041 *
1042 * {dolqfailed} is an error rule to avoid scanner backup when {dolqdelim}
1043 * fails to match its trailing "$".
1044 */
1045 /* Double quote
1046 * Allows embedded spaces and other special characters into identifiers.
1047 */
1048 /* Unicode escapes */
1049 /* error rule to avoid backup */
1050 /* Quoted identifier with Unicode escapes */
1051 /* Quoted string with Unicode escapes */
1052 /* Optional UESCAPE after a quoted string or identifier with Unicode escapes. */
1053 /* error rule to avoid backup */
1054 /* C-style comments
1055 *
1056 * The "extended comment" syntax closely resembles allowable operator syntax.
1057 * The tricky part here is to get lex to recognize a string starting with
1058 * slash-star as a comment, when interpreting it as an operator would produce
1059 * a longer match --- remember lex will prefer a longer match! Also, if we
1060 * have something like plus-slash-star, lex will think this is a 3-character
1061 * operator whereas we want to see it as a + operator and a comment start.
1062 * The solution is two-fold:
1063 * 1. append {op_chars}* to xcstart so that it matches as much text as
1064 * {operator} would. Then the tie-breaker (first matching rule of same
1065 * length) ensures xcstart wins. We put back the extra stuff with yyless()
1066 * in case it contains a star-slash that should terminate the comment.
1067 * 2. In the operator rule, check for slash-star within the operator, and
1068 * if found throw it back with yyless(). This handles the plus-slash-star
1069 * problem.
1070 * Dash-dash comments have similar interactions with the operator rule.
1071 */
1072 /* Assorted special-case operators and operator-like tokens */
1073 /*
1074 * These operator-like tokens (unlike the above ones) also match the {operator}
1075 * rule, which means that they might be overridden by a longer match if they
1076 * are followed by a comment start or a + or - character. Accordingly, if you
1077 * add to this list, you must also add corresponding code to the {operator}
1078 * block to return the correct token in such cases. (This is not needed in
1079 * psqlscan.l since the token value is ignored there.)
1080 */
1081 /*
1082 * "self" is the set of chars that should be returned as single-character
1083 * tokens. "op_chars" is the set of chars that can make up "Op" tokens,
1084 * which can be one or more characters long (but if a single-char token
1085 * appears in the "self" set, it is not to be returned as an Op). Note
1086 * that the sets overlap, but each has some chars that are not in the other.
1087 *
1088 * If you change either set, adjust the character lists appearing in the
1089 * rule for "operator"!
1090 */
1091 /* we no longer allow unary minus in numbers.
1092 * instead we pass it separately to parser. there it gets
1093 * coerced via doNegate() -- Leon aug 20 1999
1094 *
1095 * {decimalfail} is used because we would like "1..10" to lex as 1, dot_dot, 10.
1096 *
1097 * {realfail1} and {realfail2} are added to prevent the need for scanner
1098 * backup when the {real} rule fails to match completely.
1099 */
1100 /*
1101 * Dollar quoted strings are totally opaque, and no escaping is done on them.
1102 * Other quoted strings must allow some special characters such as single-quote
1103 * and newline.
1104 * Embedded single-quotes are implemented both in the SQL standard
1105 * style of two adjacent single quotes "''" and in the Postgres/Java style
1106 * of escaped-quote "\'".
1107 * Other embedded escaped characters are matched explicitly and the leading
1108 * backslash is dropped from the string.
1109 * Note that xcstart must appear before operator, as explained above!
1110 * Also whitespace (comment) must appear before operator.
1111 */
1112 #line 1113 "scan.c"
1113
1114 #define INITIAL 0
1115 #define xb 1
1116 #define xc 2
1117 #define xd 3
1118 #define xh 4
1119 #define xq 5
1120 #define xe 6
1121 #define xdolq 7
1122 #define xui 8
1123 #define xuiend 9
1124 #define xus 10
1125 #define xusend 11
1126 #define xeu 12
1127
1128 #ifndef YY_NO_UNISTD_H
1129 /* Special case for "unistd.h", since it is non-ANSI. We include it way
1130 * down here because we want the user's section 1 to have been scanned first.
1131 * The user has a chance to override it with an option.
1132 */
1133 #include <unistd.h>
1134 #endif
1135
1136 #ifndef YY_EXTRA_TYPE
1137 #define YY_EXTRA_TYPE void *
1138 #endif
1139
1140 /* Holds the entire state of the reentrant scanner. */
1141 struct yyguts_t
1142 {
1143
1144 /* User-defined. Not touched by flex. */
1145 YY_EXTRA_TYPE yyextra_r;
1146
1147 /* The rest are the same as the globals declared in the non-reentrant scanner. */
1148 FILE *yyin_r, *yyout_r;
1149 size_t yy_buffer_stack_top; /**< index of top of stack. */
1150 size_t yy_buffer_stack_max; /**< capacity of stack. */
1151 YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
1152 char yy_hold_char;
1153 yy_size_t yy_n_chars;
1154 yy_size_t yyleng_r;
1155 char *yy_c_buf_p;
1156 int yy_init;
1157 int yy_start;
1158 int yy_did_buffer_switch_on_eof;
1159 int yy_start_stack_ptr;
1160 int yy_start_stack_depth;
1161 int *yy_start_stack;
1162 yy_state_type yy_last_accepting_state;
1163 char* yy_last_accepting_cpos;
1164
1165 int yylineno_r;
1166 int yy_flex_debug_r;
1167
1168 char *yytext_r;
1169 int yy_more_flag;
1170 int yy_more_len;
1171
1172 YYSTYPE * yylval_r;
1173
1174 YYLTYPE * yylloc_r;
1175
1176 }; /* end struct yyguts_t */
1177
1178 static int yy_init_globals (yyscan_t yyscanner );
1179
1180 /* This must go here because YYSTYPE and YYLTYPE are included
1181 * from bison output in section 1.*/
1182 # define yylval yyg->yylval_r
1183
1184 # define yylloc yyg->yylloc_r
1185
1186 int core_yylex_init (yyscan_t* scanner);
1187
1188 int core_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
1189
1190 /* Accessor methods to globals.
1191 These are made visible to non-reentrant scanners for convenience. */
1192
1193 int core_yylex_destroy (yyscan_t yyscanner );
1194
1195 int core_yyget_debug (yyscan_t yyscanner );
1196
1197 void core_yyset_debug (int debug_flag ,yyscan_t yyscanner );
1198
1199 YY_EXTRA_TYPE core_yyget_extra (yyscan_t yyscanner );
1200
1201 void core_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
1202
1203 FILE *core_yyget_in (yyscan_t yyscanner );
1204
1205 void core_yyset_in (FILE * in_str ,yyscan_t yyscanner );
1206
1207 FILE *core_yyget_out (yyscan_t yyscanner );
1208
1209 void core_yyset_out (FILE * out_str ,yyscan_t yyscanner );
1210
1211 yy_size_t core_yyget_leng (yyscan_t yyscanner );
1212
1213 char *core_yyget_text (yyscan_t yyscanner );
1214
1215 int core_yyget_lineno (yyscan_t yyscanner );
1216
1217 void core_yyset_lineno (int line_number ,yyscan_t yyscanner );
1218
1219 int core_yyget_column (yyscan_t yyscanner );
1220
1221 void core_yyset_column (int column_no ,yyscan_t yyscanner );
1222
1223 YYSTYPE * core_yyget_lval (yyscan_t yyscanner );
1224
1225 void core_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
1226
1227 YYLTYPE *core_yyget_lloc (yyscan_t yyscanner );
1228
1229 void core_yyset_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
1230
1231 /* Macros after this point can all be overridden by user definitions in
1232 * section 1.
1233 */
1234
1235 #ifndef YY_SKIP_YYWRAP
1236 #ifdef __cplusplus
1237 extern "C" int core_yywrap (yyscan_t yyscanner );
1238 #else
1239 extern int core_yywrap (yyscan_t yyscanner );
1240 #endif
1241 #endif
1242
1243 #ifndef yytext_ptr
1244 static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
1245 #endif
1246
1247 #ifdef YY_NEED_STRLEN
1248 static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
1249 #endif
1250
1251 #ifndef YY_NO_INPUT
1252
1253 #ifdef __cplusplus
1254 static int yyinput (yyscan_t yyscanner );
1255 #else
1256 static int input (yyscan_t yyscanner );
1257 #endif
1258
1259 #endif
1260
1261 /* Amount of stuff to slurp up with each read. */
1262 #ifndef YY_READ_BUF_SIZE
1263 #define YY_READ_BUF_SIZE 8192
1264 #endif
1265
1266 /* Copy whatever the last rule matched to the standard output. */
1267 #ifndef ECHO
1268 /* This used to be an fputs(), but since the string might contain NUL's,
1269 * we now use fwrite().
1270 */
1271 #define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
1272 #endif
1273
1274 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
1275 * is returned in "result".
1276 */
1277 #ifndef YY_INPUT
1278 #define YY_INPUT(buf,result,max_size) \
1279 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
1280 { \
1281 int c = '*'; \
1282 size_t n; \
1283 for ( n = 0; n < max_size && \
1284 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
1285 buf[n] = (char) c; \
1286 if ( c == '\n' ) \
1287 buf[n++] = (char) c; \
1288 if ( c == EOF && ferror( yyin ) ) \
1289 YY_FATAL_ERROR( "input in flex scanner failed" ); \
1290 result = n; \
1291 } \
1292 else \
1293 { \
1294 errno=0; \
1295 while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
1296 { \
1297 if( errno != EINTR) \
1298 { \
1299 YY_FATAL_ERROR( "input in flex scanner failed" ); \
1300 break; \
1301 } \
1302 errno=0; \
1303 clearerr(yyin); \
1304 } \
1305 }\
1306 \
1307
1308 #endif
1309
1310 /* No semi-colon after return; correct usage is to write "yyterminate();" -
1311 * we don't want an extra ';' after the "return" because that will cause
1312 * some compilers to complain about unreachable statements.
1313 */
1314 #ifndef yyterminate
1315 #define yyterminate() return YY_NULL
1316 #endif
1317
1318 /* Number of entries by which start-condition stack grows. */
1319 #ifndef YY_START_STACK_INCR
1320 #define YY_START_STACK_INCR 25
1321 #endif
1322
1323 /* Report a fatal error. */
1324 #ifndef YY_FATAL_ERROR
1325 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
1326 #endif
1327
1328 /* end tables serialization structures and prototypes */
1329
1330 /* Default declaration of generated scanner - a define so the user can
1331 * easily add parameters.
1332 */
1333 #ifndef YY_DECL
1334 #define YY_DECL_IS_OURS 1
1335
1336 extern int core_yylex \
1337 (YYSTYPE * yylval_param,YYLTYPE * yylloc_param ,yyscan_t yyscanner);
1338
1339 #define YY_DECL int core_yylex \
1340 (YYSTYPE * yylval_param, YYLTYPE * yylloc_param , yyscan_t yyscanner)
1341 #endif /* !YY_DECL */
1342
1343 /* Code executed at the beginning of each rule, after yytext and yyleng
1344 * have been set up.
1345 */
1346 #ifndef YY_USER_ACTION
1347 #define YY_USER_ACTION
1348 #endif
1349
1350 /* Code executed at the end of each rule. */
1351 #ifndef YY_BREAK
1352 #define YY_BREAK break;
1353 #endif
1354
1355 #define YY_RULE_SETUP \
1356 YY_USER_ACTION
1357
1358 /** The main scanner function which does all the work.
1359 */
1360 YY_DECL
1361 {
1362 register yy_state_type yy_current_state;
1363 register char *yy_cp, *yy_bp;
1364 register int yy_act;
1365 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1366
1367 #line 427 "scan.l"
1368
1369
1370 #line 1371 "scan.c"
1371
1372 yylval = yylval_param;
1373
1374 yylloc = yylloc_param;
1375
1376 if ( !yyg->yy_init )
1377 {
1378 yyg->yy_init = 1;
1379
1380 #ifdef YY_USER_INIT
1381 YY_USER_INIT;
1382 #endif
1383
1384 if ( ! yyg->yy_start )
1385 yyg->yy_start = 1; /* first start state */
1386
1387 if ( ! yyin )
1388 yyin = stdin;
1389
1390 if ( ! yyout )
1391 yyout = stdout;
1392
1393 if ( ! YY_CURRENT_BUFFER ) {
1394 core_yyensure_buffer_stack (yyscanner);
1395 YY_CURRENT_BUFFER_LVALUE =
1396 core_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
1397 }
1398
1399 core_yy_load_buffer_state(yyscanner );
1400 }
1401
1402 while ( 1 ) /* loops until end-of-file is reached */
1403 {
1404 yy_cp = yyg->yy_c_buf_p;
1405
1406 /* Support of yytext. */
1407 *yy_cp = yyg->yy_hold_char;
1408
1409 /* yy_bp points to the position in yy_ch_buf of the start of
1410 * the current run.
1411 */
1412 yy_bp = yy_cp;
1413
1414 yy_current_state = yyg->yy_start;
1415 yy_match:
1416 do
1417 {
1418 register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
1419 if ( yy_accept[yy_current_state] )
1420 {
1421 yyg->yy_last_accepting_state = yy_current_state;
1422 yyg->yy_last_accepting_cpos = yy_cp;
1423 }
1424 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1425 {
1426 yy_current_state = (int) yy_def[yy_current_state];
1427 if ( yy_current_state >= 290 )
1428 yy_c = yy_meta[(unsigned int) yy_c];
1429 }
1430 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
1431 ++yy_cp;
1432 }
1433 while ( yy_current_state != 289 );
1434 yy_cp = yyg->yy_last_accepting_cpos;
1435 yy_current_state = yyg->yy_last_accepting_state;
1436
1437 yy_find_action:
1438 yy_act = yy_accept[yy_current_state];
1439
1440 YY_DO_BEFORE_ACTION;
1441
1442 do_action: /* This label is used only to access EOF actions. */
1443
1444 switch ( yy_act )
1445 { /* beginning of action switch */
1446 case 0: /* must back up */
1447 /* undo the effects of YY_DO_BEFORE_ACTION */
1448 *yy_cp = yyg->yy_hold_char;
1449 yy_cp = yyg->yy_last_accepting_cpos;
1450 yy_current_state = yyg->yy_last_accepting_state;
1451 goto yy_find_action;
1452
1453 case 1:
1454 /* rule 1 can match eol */
1455 YY_RULE_SETUP
1456 #line 429 "scan.l"
1457 {
1458 /* ignore */
1459 }
1460 YY_BREAK
1461 case 2:
1462 YY_RULE_SETUP
1463 #line 433 "scan.l"
1464 {
1465 /* Set location in case of syntax error in comment */
1466 SET_YYLLOC();
1467 yyextra->xcdepth = 0;
1468 BEGIN(xc);
1469 /* Put back any characters past slash-star; see above */
1470 yyless(2);
1471 }
1472 YY_BREAK
1473
1474 case 3:
1475 YY_RULE_SETUP
1476 #line 443 "scan.l"
1477 {
1478 (yyextra->xcdepth)++;
1479 /* Put back any characters past slash-star; see above */
1480 yyless(2);
1481 }
1482 YY_BREAK
1483 case 4:
1484 YY_RULE_SETUP
1485 #line 449 "scan.l"
1486 {
1487 if (yyextra->xcdepth <= 0)
1488 BEGIN(INITIAL);
1489 else
1490 (yyextra->xcdepth)--;
1491 }
1492 YY_BREAK
1493 case 5:
1494 /* rule 5 can match eol */
1495 YY_RULE_SETUP
1496 #line 456 "scan.l"
1497 {
1498 /* ignore */
1499 }
1500 YY_BREAK
1501 case 6:
1502 YY_RULE_SETUP
1503 #line 460 "scan.l"
1504 {
1505 /* ignore */
1506 }
1507 YY_BREAK
1508 case 7:
1509 YY_RULE_SETUP
1510 #line 464 "scan.l"
1511 {
1512 /* ignore */
1513 }
1514 YY_BREAK
1515 case YY_STATE_EOF(xc):
1516 #line 468 "scan.l"
1517 {
1518 yyerror("unterminated /* comment");
1519 }
1520 YY_BREAK
1521 /* <xc> */
1522 case 8:
1523 YY_RULE_SETUP
1524 #line 473 "scan.l"
1525 {
1526 /* Binary bit type.
1527 * At some point we should simply pass the string
1528 * forward to the parser and label it there.
1529 * In the meantime, place a leading "b" on the string
1530 * to mark it for the input routine as a binary string.
1531 */
1532 SET_YYLLOC();
1533 BEGIN(xb);
1534 startlit();
1535 addlitchar('b', yyscanner);
1536 }
1537 YY_BREAK
1538 case 9:
1539 /* rule 9 can match eol */
1540 #line 486 "scan.l"
1541 case 10:
1542 /* rule 10 can match eol */
1543 YY_RULE_SETUP
1544 #line 486 "scan.l"
1545 {
1546 yyless(1);
1547 BEGIN(INITIAL);
1548 yylval->str = litbufdup(yyscanner);
1549 return BCONST;
1550 }
1551 YY_BREAK
1552 case 11:
1553 /* rule 11 can match eol */
1554 #line 493 "scan.l"
1555 case 12:
1556 /* rule 12 can match eol */
1557 YY_RULE_SETUP
1558 #line 493 "scan.l"
1559 {
1560 addlit(yytext, yyleng, yyscanner);
1561 }
1562 YY_BREAK
1563 case 13:
1564 /* rule 13 can match eol */
1565 #line 497 "scan.l"
1566 case 14:
1567 /* rule 14 can match eol */
1568 YY_RULE_SETUP
1569 #line 497 "scan.l"
1570 {
1571 /* ignore */
1572 }
1573 YY_BREAK
1574 case YY_STATE_EOF(xb):
1575 #line 500 "scan.l"
1576 { yyerror("unterminated bit string literal"); }
1577 YY_BREAK
1578 case 15:
1579 YY_RULE_SETUP
1580 #line 502 "scan.l"
1581 {
1582 /* Hexadecimal bit type.
1583 * At some point we should simply pass the string
1584 * forward to the parser and label it there.
1585 * In the meantime, place a leading "x" on the string
1586 * to mark it for the input routine as a hex string.
1587 */
1588 SET_YYLLOC();
1589 BEGIN(xh);
1590 startlit();
1591 addlitchar('x', yyscanner);
1592 }
1593 YY_BREAK
1594 case 16:
1595 /* rule 16 can match eol */
1596 #line 515 "scan.l"
1597 case 17:
1598 /* rule 17 can match eol */
1599 YY_RULE_SETUP
1600 #line 515 "scan.l"
1601 {
1602 yyless(1);
1603 BEGIN(INITIAL);
1604 yylval->str = litbufdup(yyscanner);
1605 return XCONST;
1606 }
1607 YY_BREAK
1608 case YY_STATE_EOF(xh):
1609 #line 521 "scan.l"
1610 { yyerror("unterminated hexadecimal string literal"); }
1611 YY_BREAK
1612 case 18:
1613 YY_RULE_SETUP
1614 #line 523 "scan.l"
1615 {
1616 /* National character.
1617 * We will pass this along as a normal character string,
1618 * but preceded with an internally-generated "NCHAR".
1619 */
1620 int kwnum;
1621
1622 SET_YYLLOC();
1623 yyless(1); /* eat only 'n' this time */
1624
1625 kwnum = ScanKeywordLookup("nchar",
1626 yyextra->keywordlist);
1627 if (kwnum >= 0)
1628 {
1629 yylval->keyword = GetScanKeyword(kwnum,
1630 yyextra->keywordlist);
1631 return yyextra->keyword_tokens[kwnum];
1632 }
1633 else
1634 {
1635 /* If NCHAR isn't a keyword, just return "n" */
1636 yylval->str = pstrdup("n");
1637 return IDENT;
1638 }
1639 }
1640 YY_BREAK
1641 case 19:
1642 YY_RULE_SETUP
1643 #line 549 "scan.l"
1644 {
1645 yyextra->warn_on_first_escape = true;
1646 yyextra->saw_non_ascii = false;
1647 SET_YYLLOC();
1648 if (yyextra->standard_conforming_strings)
1649 BEGIN(xq);
1650 else
1651 BEGIN(xe);
1652 startlit();
1653 }
1654 YY_BREAK
1655 case 20:
1656 YY_RULE_SETUP
1657 #line 559 "scan.l"
1658 {
1659 yyextra->warn_on_first_escape = false;
1660 yyextra->saw_non_ascii = false;
1661 SET_YYLLOC();
1662 BEGIN(xe);
1663 startlit();
1664 }
1665 YY_BREAK
1666 case 21:
1667 YY_RULE_SETUP
1668 #line 566 "scan.l"
1669 {
1670 SET_YYLLOC();
1671 if (!yyextra->standard_conforming_strings)
1672 ereport(ERROR,
1673 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1674 errmsg("unsafe use of string constant with Unicode escapes"),
1675 errdetail("String constants with Unicode escapes cannot be used when standard_conforming_strings is off."),
1676 lexer_errposition()));
1677 BEGIN(xus);
1678 startlit();
1679 }
1680 YY_BREAK
1681 case 22:
1682 /* rule 22 can match eol */
1683 #line 578 "scan.l"
1684 case 23:
1685 /* rule 23 can match eol */
1686 YY_RULE_SETUP
1687 #line 578 "scan.l"
1688 {
1689 yyless(1);
1690 BEGIN(INITIAL);
1691 /*
1692 * check that the data remains valid if it might have been
1693 * made invalid by unescaping any chars.
1694 */
1695 if (yyextra->saw_non_ascii)
1696 pg_verifymbstr(yyextra->literalbuf,
1697 yyextra->literallen,
1698 false);
1699 yylval->str = litbufdup(yyscanner);
1700 return SCONST;
1701 }
1702 YY_BREAK
1703 case 24:
1704 /* rule 24 can match eol */
1705 #line 593 "scan.l"
1706 case 25:
1707 /* rule 25 can match eol */
1708 YY_RULE_SETUP
1709 #line 593 "scan.l"
1710 {
1711 /* throw back all but the quote */
1712 yyless(1);
1713 /* xusend state looks for possible UESCAPE */
1714 BEGIN(xusend);
1715 }
1716 YY_BREAK
1717 case 26:
1718 /* rule 26 can match eol */
1719 YY_RULE_SETUP
1720 #line 599 "scan.l"
1721 {
1722 /* stay in xusend state over whitespace */
1723 }
1724 YY_BREAK
1725 case YY_STATE_EOF(xusend):
1726 #line 602 "scan.l"
1727 case 27:
1728 /* rule 27 can match eol */
1729 #line 604 "scan.l"
1730 case 28:
1731 /* rule 28 can match eol */
1732 YY_RULE_SETUP
1733 #line 604 "scan.l"
1734 {
1735 /* no UESCAPE after the quote, throw back everything */
1736 yyless(0);
1737 BEGIN(INITIAL);
1738 yylval->str = litbuf_udeescape('\\', yyscanner);
1739 return SCONST;
1740 }
1741 YY_BREAK
1742 case 29:
1743 /* rule 29 can match eol */
1744 YY_RULE_SETUP
1745 #line 611 "scan.l"
1746 {
1747 /* found UESCAPE after the end quote */
1748 BEGIN(INITIAL);
1749 if (!check_uescapechar(yytext[yyleng - 2]))
1750 {
1751 SET_YYLLOC();
1752 ADVANCE_YYLLOC(yyleng - 2);
1753 yyerror("invalid Unicode escape character");
1754 }
1755 yylval->str = litbuf_udeescape(yytext[yyleng - 2],
1756 yyscanner);
1757 return SCONST;
1758 }
1759 YY_BREAK
1760 case 30:
1761 YY_RULE_SETUP
1762 #line 624 "scan.l"
1763 {
1764 addlitchar('\'', yyscanner);
1765 }
1766 YY_BREAK
1767 case 31:
1768 /* rule 31 can match eol */
1769 YY_RULE_SETUP
1770 #line 627 "scan.l"
1771 {
1772 addlit(yytext, yyleng, yyscanner);
1773 }
1774 YY_BREAK
1775 case 32:
1776 /* rule 32 can match eol */
1777 YY_RULE_SETUP
1778 #line 630 "scan.l"
1779 {
1780 addlit(yytext, yyleng, yyscanner);
1781 }
1782 YY_BREAK
1783 case 33:
1784 YY_RULE_SETUP
1785 #line 633 "scan.l"
1786 {
1787 pg_wchar c = strtoul(yytext + 2, NULL, 16);
1788
1789 check_escape_warning(yyscanner);
1790
1791 if (is_utf16_surrogate_first(c))
1792 {
1793 yyextra->utf16_first_part = c;
1794 BEGIN(xeu);
1795 }
1796 else if (is_utf16_surrogate_second(c))
1797 yyerror("invalid Unicode surrogate pair");
1798 else
1799 addunicode(c, yyscanner);
1800 }
1801 YY_BREAK
1802 case 34:
1803 YY_RULE_SETUP
1804 #line 648 "scan.l"
1805 {
1806 pg_wchar c = strtoul(yytext + 2, NULL, 16);
1807
1808 if (!is_utf16_surrogate_second(c))
1809 yyerror("invalid Unicode surrogate pair");
1810
1811 c = surrogate_pair_to_codepoint(yyextra->utf16_first_part, c);
1812
1813 addunicode(c, yyscanner);
1814
1815 BEGIN(xe);
1816 }
1817 YY_BREAK
1818 case 35:
1819 YY_RULE_SETUP
1820 #line 660 "scan.l"
1821 { yyerror("invalid Unicode surrogate pair"); }
1822 YY_BREAK
1823 case 36:
1824 /* rule 36 can match eol */
1825 YY_RULE_SETUP
1826 #line 661 "scan.l"
1827 { yyerror("invalid Unicode surrogate pair"); }
1828 YY_BREAK
1829 case YY_STATE_EOF(xeu):
1830 #line 662 "scan.l"
1831 { yyerror("invalid Unicode surrogate pair"); }
1832 YY_BREAK
1833 case 37:
1834 YY_RULE_SETUP
1835 #line 663 "scan.l"
1836 {
1837 ereport(ERROR,
1838 (errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
1839 errmsg("invalid Unicode escape"),
1840 errhint("Unicode escapes must be \\uXXXX or \\UXXXXXXXX."),
1841 lexer_errposition()));
1842 }
1843 YY_BREAK
1844 case 38:
1845 /* rule 38 can match eol */
1846 YY_RULE_SETUP
1847 #line 670 "scan.l"
1848 {
1849 #ifdef PGPOOL_NOT_USED
1850 if (yytext[1] == '\'')
1851 {
1852 if (yyextra->backslash_quote == BACKSLASH_QUOTE_OFF ||
1853 (yyextra->backslash_quote == BACKSLASH_QUOTE_SAFE_ENCODING &&
1854 PG_ENCODING_IS_CLIENT_ONLY(pg_get_client_encoding())))
1855 ereport(ERROR,
1856 (errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
1857 errmsg("unsafe use of \\' in a string literal"),
1858 errhint("Use '' to write quotes in strings. \\' is insecure in client-only encodings."),
1859 lexer_errposition()));
1860 }
1861 #endif
1862 check_string_escape_warning(yytext[1], yyscanner);
1863 addlitchar(unescape_single_char(yytext[1], yyscanner),
1864 yyscanner);
1865 }
1866 YY_BREAK
1867 case 39:
1868 YY_RULE_SETUP
1869 #line 688 "scan.l"
1870 {
1871 unsigned char c = strtoul(yytext + 1, NULL, 8);
1872
1873 check_escape_warning(yyscanner);
1874 addlitchar(c, yyscanner);
1875 if (c == '\0' || IS_HIGHBIT_SET(c))
1876 yyextra->saw_non_ascii = true;
1877 }
1878 YY_BREAK
1879 case 40:
1880 YY_RULE_SETUP
1881 #line 696 "scan.l"
1882 {
1883 unsigned char c = strtoul(yytext + 2, NULL, 16);
1884
1885 check_escape_warning(yyscanner);
1886 addlitchar(c, yyscanner);
1887 if (c == '\0' || IS_HIGHBIT_SET(c))
1888 yyextra->saw_non_ascii = true;
1889 }
1890 YY_BREAK
1891 case 41:
1892 /* rule 41 can match eol */
1893 YY_RULE_SETUP
1894 #line 704 "scan.l"
1895 {
1896 /* ignore */
1897 }
1898 YY_BREAK
1899 case 42:
1900 YY_RULE_SETUP
1901 #line 707 "scan.l"
1902 {
1903 /* This is only needed for \ just before EOF */
1904 addlitchar(yytext[0], yyscanner);
1905 }
1906 YY_BREAK
1907 case YY_STATE_EOF(xq):
1908 case YY_STATE_EOF(xe):
1909 case YY_STATE_EOF(xus):
1910 #line 711 "scan.l"
1911 { yyerror("unterminated quoted string"); }
1912 YY_BREAK
1913 case 43:
1914 YY_RULE_SETUP
1915 #line 713 "scan.l"
1916 {
1917 SET_YYLLOC();
1918 yyextra->dolqstart = pstrdup(yytext);
1919 BEGIN(xdolq);
1920 startlit();
1921 }
1922 YY_BREAK
1923 case 44:
1924 YY_RULE_SETUP
1925 #line 719 "scan.l"
1926 {
1927 SET_YYLLOC();
1928 /* throw back all but the initial "$" */
1929 yyless(1);
1930 /* and treat it as {other} */
1931 return yytext[0];
1932 }
1933 YY_BREAK
1934 case 45:
1935 YY_RULE_SETUP
1936 #line 726 "scan.l"
1937 {
1938 if (strcmp(yytext, yyextra->dolqstart) == 0)
1939 {
1940 pfree(yyextra->dolqstart);
1941 yyextra->dolqstart = NULL;
1942 BEGIN(INITIAL);
1943 yylval->str = litbufdup(yyscanner);
1944 return SCONST;
1945 }
1946 else
1947 {
1948 /*
1949 * When we fail to match $...$ to dolqstart, transfer
1950 * the $... part to the output, but put back the final
1951 * $ for rescanning. Consider $delim$...$junk$delim$
1952 */
1953 addlit(yytext, yyleng - 1, yyscanner);
1954 yyless(yyleng - 1);
1955 }
1956 }
1957 YY_BREAK
1958 case 46:
1959 /* rule 46 can match eol */
1960 YY_RULE_SETUP
1961 #line 746 "scan.l"
1962 {
1963 addlit(yytext, yyleng, yyscanner);
1964 }
1965 YY_BREAK
1966 case 47:
1967 YY_RULE_SETUP
1968 #line 749 "scan.l"
1969 {
1970 addlit(yytext, yyleng, yyscanner);
1971 }
1972 YY_BREAK
1973 case 48:
1974 YY_RULE_SETUP
1975 #line 752 "scan.l"
1976 {
1977 /* This is only needed for $ inside the quoted text */
1978 addlitchar(yytext[0], yyscanner);
1979 }
1980 YY_BREAK
1981 case YY_STATE_EOF(xdolq):
1982 #line 756 "scan.l"
1983 { yyerror("unterminated dollar-quoted string"); }
1984 YY_BREAK
1985 case 49:
1986 YY_RULE_SETUP
1987 #line 758 "scan.l"
1988 {
1989 SET_YYLLOC();
1990 BEGIN(xd);
1991 startlit();
1992 }
1993 YY_BREAK
1994 case 50:
1995 YY_RULE_SETUP
1996 #line 763 "scan.l"
1997 {
1998 SET_YYLLOC();
1999 BEGIN(xui);
2000 startlit();
2001 }
2002 YY_BREAK
2003 case 51:
2004 YY_RULE_SETUP
2005 #line 768 "scan.l"
2006 {
2007 char *ident;
2008
2009 BEGIN(INITIAL);
2010 if (yyextra->literallen == 0)
2011 yyerror("zero-length delimited identifier");
2012 ident = litbufdup(yyscanner);
2013 if (yyextra->literallen >= NAMEDATALEN)
2014 truncate_identifier(ident, yyextra->literallen, true);
2015 yylval->str = ident;
2016 return IDENT;
2017 }
2018 YY_BREAK
2019 case 52:
2020 YY_RULE_SETUP
2021 #line 780 "scan.l"
2022 {
2023 yyless(1);
2024 /* xuiend state looks for possible UESCAPE */
2025 BEGIN(xuiend);
2026 }
2027 YY_BREAK
2028 case 53:
2029 /* rule 53 can match eol */
2030 YY_RULE_SETUP
2031 #line 785 "scan.l"
2032 {
2033 /* stay in xuiend state over whitespace */
2034 }
2035 YY_BREAK
2036 case YY_STATE_EOF(xuiend):
2037 #line 788 "scan.l"
2038 case 54:
2039 /* rule 54 can match eol */
2040 #line 790 "scan.l"
2041 case 55:
2042 /* rule 55 can match eol */
2043 YY_RULE_SETUP
2044 #line 790 "scan.l"
2045 {
2046 /* no UESCAPE after the quote, throw back everything */
2047 char *ident;
2048 int identlen;
2049
2050 yyless(0);
2051
2052 BEGIN(INITIAL);
2053 if (yyextra->literallen == 0)
2054 yyerror("zero-length delimited identifier");
2055 ident = litbuf_udeescape('\\', yyscanner);
2056 identlen = strlen(ident);
2057 if (identlen >= NAMEDATALEN)
2058 truncate_identifier(ident, identlen, true);
2059 yylval->str = ident;
2060 return IDENT;
2061 }
2062 YY_BREAK
2063 case 56:
2064 /* rule 56 can match eol */
2065 YY_RULE_SETUP
2066 #line 807 "scan.l"
2067 {
2068 /* found UESCAPE after the end quote */
2069 char *ident;
2070 int identlen;
2071
2072 BEGIN(INITIAL);
2073 if (yyextra->literallen == 0)
2074 yyerror("zero-length delimited identifier");
2075 if (!check_uescapechar(yytext[yyleng - 2]))
2076 {
2077 SET_YYLLOC();
2078 ADVANCE_YYLLOC(yyleng - 2);
2079 yyerror("invalid Unicode escape character");
2080 }
2081 ident = litbuf_udeescape(yytext[yyleng - 2], yyscanner);
2082 identlen = strlen(ident);
2083 if (identlen >= NAMEDATALEN)
2084 truncate_identifier(ident, identlen, true);
2085 yylval->str = ident;
2086 return IDENT;
2087 }
2088 YY_BREAK
2089 case 57:
2090 YY_RULE_SETUP
2091 #line 828 "scan.l"
2092 {
2093 addlitchar('"', yyscanner);
2094 }
2095 YY_BREAK
2096 case 58:
2097 /* rule 58 can match eol */
2098 YY_RULE_SETUP
2099 #line 831 "scan.l"
2100 {
2101 addlit(yytext, yyleng, yyscanner);
2102 }
2103 YY_BREAK
2104 case YY_STATE_EOF(xd):
2105 case YY_STATE_EOF(xui):
2106 #line 834 "scan.l"
2107 { yyerror("unterminated quoted identifier"); }
2108 YY_BREAK
2109 case 59:
2110 YY_RULE_SETUP
2111 #line 836 "scan.l"
2112 {
2113 char *ident;
2114
2115 SET_YYLLOC();
2116 /* throw back all but the initial u/U */
2117 yyless(1);
2118 /* and treat it as {identifier} */
2119 ident = downcase_truncate_identifier(yytext, yyleng, true);
2120 yylval->str = ident;
2121 return IDENT;
2122 }
2123 YY_BREAK
2124 case 60:
2125 YY_RULE_SETUP
2126 #line 848 "scan.l"
2127 {
2128 SET_YYLLOC();
2129 return TYPECAST;
2130 }
2131 YY_BREAK
2132 case 61:
2133 YY_RULE_SETUP
2134 #line 853 "scan.l"
2135 {
2136 SET_YYLLOC();
2137 return DOT_DOT;
2138 }
2139 YY_BREAK
2140 case 62:
2141 YY_RULE_SETUP
2142 #line 858 "scan.l"
2143 {
2144 SET_YYLLOC();
2145 return COLON_EQUALS;
2146 }
2147 YY_BREAK
2148 case 63:
2149 YY_RULE_SETUP
2150 #line 863 "scan.l"
2151 {
2152 SET_YYLLOC();
2153 return EQUALS_GREATER;
2154 }
2155 YY_BREAK
2156 case 64:
2157 YY_RULE_SETUP
2158 #line 868 "scan.l"
2159 {
2160 SET_YYLLOC();
2161 return LESS_EQUALS;
2162 }
2163 YY_BREAK
2164 case 65:
2165 YY_RULE_SETUP
2166 #line 873 "scan.l"
2167 {
2168 SET_YYLLOC();
2169 return GREATER_EQUALS;
2170 }
2171 YY_BREAK
2172 case 66:
2173 YY_RULE_SETUP
2174 #line 878 "scan.l"
2175 {
2176 /* We accept both "<>" and "!=" as meaning NOT_EQUALS */
2177 SET_YYLLOC();
2178 return NOT_EQUALS;
2179 }
2180 YY_BREAK
2181 case 67:
2182 YY_RULE_SETUP
2183 #line 884 "scan.l"
2184 {
2185 /* We accept both "<>" and "!=" as meaning NOT_EQUALS */
2186 SET_YYLLOC();
2187 return NOT_EQUALS;
2188 }
2189 YY_BREAK
2190 case 68:
2191 YY_RULE_SETUP
2192 #line 890 "scan.l"
2193 {
2194 SET_YYLLOC();
2195 return yytext[0];
2196 }
2197 YY_BREAK
2198 case 69:
2199 YY_RULE_SETUP
2200 #line 895 "scan.l"
2201 {
2202 /*
2203 * Check for embedded slash-star or dash-dash; those
2204 * are comment starts, so operator must stop there.
2205 * Note that slash-star or dash-dash at the first
2206 * character will match a prior rule, not this one.
2207 */
2208 int nchars = yyleng;
2209 char *slashstar = strstr(yytext, "/*");
2210 char *dashdash = strstr(yytext, "--");
2211
2212 if (slashstar && dashdash)
2213 {
2214 /* if both appear, take the first one */
2215 if (slashstar > dashdash)
2216 slashstar = dashdash;
2217 }
2218 else if (!slashstar)
2219 slashstar = dashdash;
2220 if (slashstar)
2221 nchars = slashstar - yytext;
2222
2223 /*
2224 * For SQL compatibility, '+' and '-' cannot be the
2225 * last char of a multi-char operator unless the operator
2226 * contains chars that are not in SQL operators.
2227 * The idea is to lex '=-' as two operators, but not
2228 * to forbid operator names like '?-' that could not be
2229 * sequences of SQL operators.
2230 */
2231 if (nchars > 1 &&
2232 (yytext[nchars - 1] == '+' ||
2233 yytext[nchars - 1] == '-'))
2234 {
2235 int ic;
2236
2237 for (ic = nchars - 2; ic >= 0; ic--)
2238 {
2239 char c = yytext[ic];
2240 if (c == '~' || c == '!' || c == '@' ||
2241 c == '#' || c == '^' || c == '&' ||
2242 c == '|' || c == '`' || c == '?' ||
2243 c == '%')
2244 break;
2245 }
2246 if (ic < 0)
2247 {
2248 /*
2249 * didn't find a qualifying character, so remove
2250 * all trailing [+-]
2251 */
2252 do {
2253 nchars--;
2254 } while (nchars > 1 &&
2255 (yytext[nchars - 1] == '+' ||
2256 yytext[nchars - 1] == '-'));
2257 }
2258 }
2259
2260 SET_YYLLOC();
2261
2262 if (nchars < yyleng)
2263 {
2264 /* Strip the unwanted chars from the token */
2265 yyless(nchars);
2266 /*
2267 * If what we have left is only one char, and it's
2268 * one of the characters matching "self", then
2269 * return it as a character token the same way
2270 * that the "self" rule would have.
2271 */
2272 if (nchars == 1 &&
2273 strchr(",()[].;:+-*/%^<>=", yytext[0]))
2274 return yytext[0];
2275 /*
2276 * Likewise, if what we have left is two chars, and
2277 * those match the tokens ">=", "<=", "=>", "<>" or
2278 * "!=", then we must return the appropriate token
2279 * rather than the generic Op.
2280 */
2281 if (nchars == 2)
2282 {
2283 if (yytext[0] == '=' && yytext[1] == '>')
2284 return EQUALS_GREATER;
2285 if (yytext[0] == '>' && yytext[1] == '=')
2286 return GREATER_EQUALS;
2287 if (yytext[0] == '<' && yytext[1] == '=')
2288 return LESS_EQUALS;
2289 if (yytext[0] == '<' && yytext[1] == '>')
2290 return NOT_EQUALS;
2291 if (yytext[0] == '!' && yytext[1] == '=')
2292 return NOT_EQUALS;
2293 }
2294 }
2295
2296 /*
2297 * Complain if operator is too long. Unlike the case
2298 * for identifiers, we make this an error not a notice-
2299 * and-truncate, because the odds are we are looking at
2300 * a syntactic mistake anyway.
2301 */
2302 if (nchars >= NAMEDATALEN)
2303 yyerror("operator too long");
2304
2305 yylval->str = pstrdup(yytext);
2306 return Op;
2307 }
2308 YY_BREAK
2309 case 70:
2310 YY_RULE_SETUP
2311 #line 1003 "scan.l"
2312 {
2313 SET_YYLLOC();
2314 yylval->ival = atol(yytext + 1);
2315 return PARAM;
2316 }
2317 YY_BREAK
2318 case 71:
2319 YY_RULE_SETUP
2320 #line 1009 "scan.l"
2321 {
2322 SET_YYLLOC();
2323 return process_integer_literal(yytext, yylval);
2324 }
2325 YY_BREAK
2326 case 72:
2327 YY_RULE_SETUP
2328 #line 1013 "scan.l"
2329 {
2330 SET_YYLLOC();
2331 yylval->str = pstrdup(yytext);
2332 return FCONST;
2333 }
2334 YY_BREAK
2335 case 73:
2336 YY_RULE_SETUP
2337 #line 1018 "scan.l"
2338 {
2339 /* throw back the .., and treat as integer */
2340 yyless(yyleng - 2);
2341 SET_YYLLOC();
2342 return process_integer_literal(yytext, yylval);
2343 }
2344 YY_BREAK
2345 case 74:
2346 YY_RULE_SETUP
2347 #line 1024 "scan.l"
2348 {
2349 SET_YYLLOC();
2350 yylval->str = pstrdup(yytext);
2351 return FCONST;
2352 }
2353 YY_BREAK
2354 case 75:
2355 YY_RULE_SETUP
2356 #line 1029 "scan.l"
2357 {
2358 /*
2359 * throw back the [Ee], and figure out whether what
2360 * remains is an {integer} or {decimal}.
2361 */
2362 yyless(yyleng - 1);
2363 SET_YYLLOC();
2364 return process_integer_literal(yytext, yylval);
2365 }
2366 YY_BREAK
2367 case 76:
2368 YY_RULE_SETUP
2369 #line 1038 "scan.l"
2370 {
2371 /* throw back the [Ee][+-], and proceed as above */
2372 yyless(yyleng - 2);
2373 SET_YYLLOC();
2374 return process_integer_literal(yytext, yylval);
2375 }
2376 YY_BREAK
2377 case 77:
2378 YY_RULE_SETUP
2379 #line 1046 "scan.l"
2380 {
2381 int kwnum;
2382 char *ident;
2383
2384 SET_YYLLOC();
2385
2386 /* Is it a keyword? */
2387 kwnum = ScanKeywordLookup(yytext,
2388 yyextra->keywordlist);
2389 if (kwnum >= 0)
2390 {
2391 yylval->keyword = GetScanKeyword(kwnum,
2392 yyextra->keywordlist);
2393 return yyextra->keyword_tokens[kwnum];
2394 }
2395
2396 /*
2397 * No. Convert the identifier to lower case, and truncate
2398 * if necessary.
2399 */
2400 ident = downcase_truncate_identifier(yytext, yyleng, true);
2401 yylval->str = ident;
2402 return IDENT;
2403 }
2404 YY_BREAK
2405 case 78:
2406 YY_RULE_SETUP
2407 #line 1071 "scan.l"
2408 {
2409 SET_YYLLOC();
2410 return yytext[0];
2411 }
2412 YY_BREAK
2413 case YY_STATE_EOF(INITIAL):
2414 #line 1076 "scan.l"
2415 {
2416 SET_YYLLOC();
2417 yyterminate();
2418 }
2419 YY_BREAK
2420 case 79:
2421 YY_RULE_SETUP
2422 #line 1081 "scan.l"
2423 YY_FATAL_ERROR( "flex scanner jammed" );
2424 YY_BREAK
2425 #line 2426 "scan.c"
2426
2427 case YY_END_OF_BUFFER:
2428 {
2429 /* Amount of text matched not including the EOB char. */
2430 int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
2431
2432 /* Undo the effects of YY_DO_BEFORE_ACTION. */
2433 *yy_cp = yyg->yy_hold_char;
2434 YY_RESTORE_YY_MORE_OFFSET
2435
2436 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
2437 {
2438 /* We're scanning a new file or input source. It's
2439 * possible that this happened because the user
2440 * just pointed yyin at a new source and called
2441 * core_yylex(). If so, then we have to assure
2442 * consistency between YY_CURRENT_BUFFER and our
2443 * globals. Here is the right place to do so, because
2444 * this is the first action (other than possibly a
2445 * back-up) that will match for the new input source.
2446 */
2447 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2448 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
2449 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
2450 }
2451
2452 /* Note that here we test for yy_c_buf_p "<=" to the position
2453 * of the first EOB in the buffer, since yy_c_buf_p will
2454 * already have been incremented past the NUL character
2455 * (since all states make transitions on EOB to the
2456 * end-of-buffer state). Contrast this with the test
2457 * in input().
2458 */
2459 if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
2460 { /* This was really a NUL. */
2461 yy_state_type yy_next_state;
2462
2463 yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
2464
2465 yy_current_state = yy_get_previous_state( yyscanner );
2466
2467 /* Okay, we're now positioned to make the NUL
2468 * transition. We couldn't have
2469 * yy_get_previous_state() go ahead and do it
2470 * for us because it doesn't know how to deal
2471 * with the possibility of jamming (and we don't
2472 * want to build jamming into it because then it
2473 * will run more slowly).
2474 */
2475
2476 yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
2477
2478 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
2479
2480 if ( yy_next_state )
2481 {
2482 /* Consume the NUL. */
2483 yy_cp = ++yyg->yy_c_buf_p;
2484 yy_current_state = yy_next_state;
2485 goto yy_match;
2486 }
2487
2488 else
2489 {
2490 yy_cp = yyg->yy_last_accepting_cpos;
2491 yy_current_state = yyg->yy_last_accepting_state;
2492 goto yy_find_action;
2493 }
2494 }
2495
2496 else switch ( yy_get_next_buffer( yyscanner ) )
2497 {
2498 case EOB_ACT_END_OF_FILE:
2499 {
2500 yyg->yy_did_buffer_switch_on_eof = 0;
2501
2502 if ( core_yywrap(yyscanner ) )
2503 {
2504 /* Note: because we've taken care in
2505 * yy_get_next_buffer() to have set up
2506 * yytext, we can now set up
2507 * yy_c_buf_p so that if some total
2508 * hoser (like flex itself) wants to
2509 * call the scanner after we return the
2510 * YY_NULL, it'll still work - another
2511 * YY_NULL will get returned.
2512 */
2513 yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
2514
2515 yy_act = YY_STATE_EOF(YY_START);
2516 goto do_action;
2517 }
2518
2519 else
2520 {
2521 if ( ! yyg->yy_did_buffer_switch_on_eof )
2522 YY_NEW_FILE;
2523 }
2524 break;
2525 }
2526
2527 case EOB_ACT_CONTINUE_SCAN:
2528 yyg->yy_c_buf_p =
2529 yyg->yytext_ptr + yy_amount_of_matched_text;
2530
2531 yy_current_state = yy_get_previous_state( yyscanner );
2532
2533 yy_cp = yyg->yy_c_buf_p;
2534 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
2535 goto yy_match;
2536
2537 case EOB_ACT_LAST_MATCH:
2538 yyg->yy_c_buf_p =
2539 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
2540
2541 yy_current_state = yy_get_previous_state( yyscanner );
2542
2543 yy_cp = yyg->yy_c_buf_p;
2544 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
2545 goto yy_find_action;
2546 }
2547 break;
2548 }
2549
2550 default:
2551 YY_FATAL_ERROR(
2552 "fatal flex scanner internal error--no action found" );
2553 } /* end of action switch */
2554 } /* end of scanning one token */
2555 } /* end of core_yylex */
2556
2557 /* yy_get_next_buffer - try to read in a new buffer
2558 *
2559 * Returns a code representing an action:
2560 * EOB_ACT_LAST_MATCH -
2561 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
2562 * EOB_ACT_END_OF_FILE - end of file
2563 */
yy_get_next_buffer(yyscan_t yyscanner)2564 static int yy_get_next_buffer (yyscan_t yyscanner)
2565 {
2566 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2567 register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
2568 register char *source = yyg->yytext_ptr;
2569 register int number_to_move, i;
2570 int ret_val;
2571
2572 if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
2573 YY_FATAL_ERROR(
2574 "fatal flex scanner internal error--end of buffer missed" );
2575
2576 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
2577 { /* Don't try to fill the buffer, so this is an EOF. */
2578 if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
2579 {
2580 /* We matched a single character, the EOB, so
2581 * treat this as a final EOF.
2582 */
2583 return EOB_ACT_END_OF_FILE;
2584 }
2585
2586 else
2587 {
2588 /* We matched some text prior to the EOB, first
2589 * process it.
2590 */
2591 return EOB_ACT_LAST_MATCH;
2592 }
2593 }
2594
2595 /* Try to read more data. */
2596
2597 /* First move last chars to start of buffer. */
2598 number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1;
2599
2600 for ( i = 0; i < number_to_move; ++i )
2601 *(dest++) = *(source++);
2602
2603 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
2604 /* don't do the read, it's not guaranteed to return an EOF,
2605 * just force an EOF
2606 */
2607 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
2608
2609 else
2610 {
2611 yy_size_t num_to_read =
2612 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
2613
2614 while ( num_to_read <= 0 )
2615 { /* Not enough room in the buffer - grow it. */
2616
2617 /* just a shorter name for the current buffer */
2618 YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
2619
2620 int yy_c_buf_p_offset =
2621 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
2622
2623 if ( b->yy_is_our_buffer )
2624 {
2625 yy_size_t new_size = b->yy_buf_size * 2;
2626
2627 if ( new_size <= 0 )
2628 b->yy_buf_size += b->yy_buf_size / 8;
2629 else
2630 b->yy_buf_size *= 2;
2631
2632 b->yy_ch_buf = (char *)
2633 /* Include room in for 2 EOB chars. */
2634 core_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
2635 }
2636 else
2637 /* Can't grow it, we don't own it. */
2638 b->yy_ch_buf = 0;
2639
2640 if ( ! b->yy_ch_buf )
2641 YY_FATAL_ERROR(
2642 "fatal error - scanner input buffer overflow" );
2643
2644 yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
2645
2646 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
2647 number_to_move - 1;
2648
2649 }
2650
2651 if ( num_to_read > YY_READ_BUF_SIZE )
2652 num_to_read = YY_READ_BUF_SIZE;
2653
2654 /* Read in more data. */
2655 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
2656 yyg->yy_n_chars, num_to_read );
2657
2658 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2659 }
2660
2661 if ( yyg->yy_n_chars == 0 )
2662 {
2663 if ( number_to_move == YY_MORE_ADJ )
2664 {
2665 ret_val = EOB_ACT_END_OF_FILE;
2666 core_yyrestart(yyin ,yyscanner);
2667 }
2668
2669 else
2670 {
2671 ret_val = EOB_ACT_LAST_MATCH;
2672 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
2673 YY_BUFFER_EOF_PENDING;
2674 }
2675 }
2676
2677 else
2678 ret_val = EOB_ACT_CONTINUE_SCAN;
2679
2680 if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
2681 /* Extend the array by 50%, plus the number we really need. */
2682 yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
2683 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) core_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
2684 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
2685 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
2686 }
2687
2688 yyg->yy_n_chars += number_to_move;
2689 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
2690 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
2691
2692 yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
2693
2694 return ret_val;
2695 }
2696
2697 /* yy_get_previous_state - get the state just before the EOB char was reached */
2698
yy_get_previous_state(yyscan_t yyscanner)2699 static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
2700 {
2701 register yy_state_type yy_current_state;
2702 register char *yy_cp;
2703 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2704
2705 yy_current_state = yyg->yy_start;
2706
2707 for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
2708 {
2709 register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
2710 if ( yy_accept[yy_current_state] )
2711 {
2712 yyg->yy_last_accepting_state = yy_current_state;
2713 yyg->yy_last_accepting_cpos = yy_cp;
2714 }
2715 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
2716 {
2717 yy_current_state = (int) yy_def[yy_current_state];
2718 if ( yy_current_state >= 290 )
2719 yy_c = yy_meta[(unsigned int) yy_c];
2720 }
2721 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
2722 }
2723
2724 return yy_current_state;
2725 }
2726
2727 /* yy_try_NUL_trans - try to make a transition on the NUL character
2728 *
2729 * synopsis
2730 * next_state = yy_try_NUL_trans( current_state );
2731 */
yy_try_NUL_trans(yy_state_type yy_current_state,yyscan_t yyscanner)2732 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
2733 {
2734 register int yy_is_jam;
2735 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
2736 register char *yy_cp = yyg->yy_c_buf_p;
2737
2738 register YY_CHAR yy_c = 1;
2739 if ( yy_accept[yy_current_state] )
2740 {
2741 yyg->yy_last_accepting_state = yy_current_state;
2742 yyg->yy_last_accepting_cpos = yy_cp;
2743 }
2744 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
2745 {
2746 yy_current_state = (int) yy_def[yy_current_state];
2747 if ( yy_current_state >= 290 )
2748 yy_c = yy_meta[(unsigned int) yy_c];
2749 }
2750 yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
2751 yy_is_jam = (yy_current_state == 289);
2752
2753 (void)yyg;
2754 return yy_is_jam ? 0 : yy_current_state;
2755 }
2756
2757 #ifndef YY_NO_INPUT
2758 #ifdef __cplusplus
yyinput(yyscan_t yyscanner)2759 static int yyinput (yyscan_t yyscanner)
2760 #else
2761 static int input (yyscan_t yyscanner)
2762 #endif
2763
2764 {
2765 int c;
2766 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2767
2768 *yyg->yy_c_buf_p = yyg->yy_hold_char;
2769
2770 if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
2771 {
2772 /* yy_c_buf_p now points to the character we want to return.
2773 * If this occurs *before* the EOB characters, then it's a
2774 * valid NUL; if not, then we've hit the end of the buffer.
2775 */
2776 if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
2777 /* This was really a NUL. */
2778 *yyg->yy_c_buf_p = '\0';
2779
2780 else
2781 { /* need more input */
2782 yy_size_t offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
2783 ++yyg->yy_c_buf_p;
2784
2785 switch ( yy_get_next_buffer( yyscanner ) )
2786 {
2787 case EOB_ACT_LAST_MATCH:
2788 /* This happens because yy_g_n_b()
2789 * sees that we've accumulated a
2790 * token and flags that we need to
2791 * try matching the token before
2792 * proceeding. But for input(),
2793 * there's no matching to consider.
2794 * So convert the EOB_ACT_LAST_MATCH
2795 * to EOB_ACT_END_OF_FILE.
2796 */
2797
2798 /* Reset buffer status. */
2799 core_yyrestart(yyin ,yyscanner);
2800
2801 /*FALLTHROUGH*/
2802
2803 case EOB_ACT_END_OF_FILE:
2804 {
2805 if ( core_yywrap(yyscanner ) )
2806 return EOF;
2807
2808 if ( ! yyg->yy_did_buffer_switch_on_eof )
2809 YY_NEW_FILE;
2810 #ifdef __cplusplus
2811 return yyinput(yyscanner);
2812 #else
2813 return input(yyscanner);
2814 #endif
2815 }
2816
2817 case EOB_ACT_CONTINUE_SCAN:
2818 yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
2819 break;
2820 }
2821 }
2822 }
2823
2824 c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
2825 *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
2826 yyg->yy_hold_char = *++yyg->yy_c_buf_p;
2827
2828 return c;
2829 }
2830 #endif /* ifndef YY_NO_INPUT */
2831
2832 /** Immediately switch to a different input stream.
2833 * @param input_file A readable stream.
2834 * @param yyscanner The scanner object.
2835 * @note This function does not reset the start condition to @c INITIAL .
2836 */
core_yyrestart(FILE * input_file,yyscan_t yyscanner)2837 void core_yyrestart (FILE * input_file , yyscan_t yyscanner)
2838 {
2839 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2840
2841 if ( ! YY_CURRENT_BUFFER ){
2842 core_yyensure_buffer_stack (yyscanner);
2843 YY_CURRENT_BUFFER_LVALUE =
2844 core_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
2845 }
2846
2847 core_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
2848 core_yy_load_buffer_state(yyscanner );
2849 }
2850
2851 /** Switch to a different input buffer.
2852 * @param new_buffer The new input buffer.
2853 * @param yyscanner The scanner object.
2854 */
core_yy_switch_to_buffer(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)2855 void core_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
2856 {
2857 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2858
2859 /* TODO. We should be able to replace this entire function body
2860 * with
2861 * core_yypop_buffer_state();
2862 * core_yypush_buffer_state(new_buffer);
2863 */
2864 core_yyensure_buffer_stack (yyscanner);
2865 if ( YY_CURRENT_BUFFER == new_buffer )
2866 return;
2867
2868 if ( YY_CURRENT_BUFFER )
2869 {
2870 /* Flush out information for old buffer. */
2871 *yyg->yy_c_buf_p = yyg->yy_hold_char;
2872 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
2873 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2874 }
2875
2876 YY_CURRENT_BUFFER_LVALUE = new_buffer;
2877 core_yy_load_buffer_state(yyscanner );
2878
2879 /* We don't actually know whether we did this switch during
2880 * EOF (core_yywrap()) processing, but the only time this flag
2881 * is looked at is after core_yywrap() is called, so it's safe
2882 * to go ahead and always set it.
2883 */
2884 yyg->yy_did_buffer_switch_on_eof = 1;
2885 }
2886
core_yy_load_buffer_state(yyscan_t yyscanner)2887 static void core_yy_load_buffer_state (yyscan_t yyscanner)
2888 {
2889 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2890 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2891 yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
2892 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
2893 yyg->yy_hold_char = *yyg->yy_c_buf_p;
2894 }
2895
2896 /** Allocate and initialize an input buffer state.
2897 * @param file A readable stream.
2898 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
2899 * @param yyscanner The scanner object.
2900 * @return the allocated buffer state.
2901 */
core_yy_create_buffer(FILE * file,int size,yyscan_t yyscanner)2902 YY_BUFFER_STATE core_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
2903 {
2904 YY_BUFFER_STATE b;
2905
2906 b = (YY_BUFFER_STATE) core_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
2907 if ( ! b )
2908 YY_FATAL_ERROR( "out of dynamic memory in core_yy_create_buffer()" );
2909
2910 b->yy_buf_size = size;
2911
2912 /* yy_ch_buf has to be 2 characters longer than the size given because
2913 * we need to put in 2 end-of-buffer characters.
2914 */
2915 b->yy_ch_buf = (char *) core_yyalloc(b->yy_buf_size + 2 ,yyscanner );
2916 if ( ! b->yy_ch_buf )
2917 YY_FATAL_ERROR( "out of dynamic memory in core_yy_create_buffer()" );
2918
2919 b->yy_is_our_buffer = 1;
2920
2921 core_yy_init_buffer(b,file ,yyscanner);
2922
2923 return b;
2924 }
2925
2926 /** Destroy the buffer.
2927 * @param b a buffer created with core_yy_create_buffer()
2928 * @param yyscanner The scanner object.
2929 */
core_yy_delete_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)2930 void core_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
2931 {
2932 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2933
2934 if ( ! b )
2935 return;
2936
2937 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
2938 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
2939
2940 if ( b->yy_is_our_buffer )
2941 core_yyfree((void *) b->yy_ch_buf ,yyscanner );
2942
2943 core_yyfree((void *) b ,yyscanner );
2944 }
2945
2946 /* Initializes or reinitializes a buffer.
2947 * This function is sometimes called more than once on the same buffer,
2948 * such as during a core_yyrestart() or at EOF.
2949 */
core_yy_init_buffer(YY_BUFFER_STATE b,FILE * file,yyscan_t yyscanner)2950 static void core_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
2951
2952 {
2953 int oerrno = errno;
2954 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2955
2956 core_yy_flush_buffer(b ,yyscanner);
2957
2958 b->yy_input_file = file;
2959 b->yy_fill_buffer = 1;
2960
2961 /* If b is the current buffer, then core_yy_init_buffer was _probably_
2962 * called from core_yyrestart() or through yy_get_next_buffer.
2963 * In that case, we don't want to reset the lineno or column.
2964 */
2965 if (b != YY_CURRENT_BUFFER){
2966 b->yy_bs_lineno = 1;
2967 b->yy_bs_column = 0;
2968 }
2969
2970 b->yy_is_interactive = 0;
2971
2972 errno = oerrno;
2973 }
2974
2975 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
2976 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
2977 * @param yyscanner The scanner object.
2978 */
core_yy_flush_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)2979 void core_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
2980 {
2981 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2982 if ( ! b )
2983 return;
2984
2985 b->yy_n_chars = 0;
2986
2987 /* We always need two end-of-buffer characters. The first causes
2988 * a transition to the end-of-buffer state. The second causes
2989 * a jam in that state.
2990 */
2991 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
2992 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
2993
2994 b->yy_buf_pos = &b->yy_ch_buf[0];
2995
2996 b->yy_at_bol = 1;
2997 b->yy_buffer_status = YY_BUFFER_NEW;
2998
2999 if ( b == YY_CURRENT_BUFFER )
3000 core_yy_load_buffer_state(yyscanner );
3001 }
3002
3003 /** Pushes the new state onto the stack. The new state becomes
3004 * the current state. This function will allocate the stack
3005 * if necessary.
3006 * @param new_buffer The new state.
3007 * @param yyscanner The scanner object.
3008 */
core_yypush_buffer_state(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)3009 void core_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
3010 {
3011 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3012 if (new_buffer == NULL)
3013 return;
3014
3015 core_yyensure_buffer_stack(yyscanner);
3016
3017 /* This block is copied from core_yy_switch_to_buffer. */
3018 if ( YY_CURRENT_BUFFER )
3019 {
3020 /* Flush out information for old buffer. */
3021 *yyg->yy_c_buf_p = yyg->yy_hold_char;
3022 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
3023 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
3024 }
3025
3026 /* Only push if top exists. Otherwise, replace top. */
3027 if (YY_CURRENT_BUFFER)
3028 yyg->yy_buffer_stack_top++;
3029 YY_CURRENT_BUFFER_LVALUE = new_buffer;
3030
3031 /* copied from core_yy_switch_to_buffer. */
3032 core_yy_load_buffer_state(yyscanner );
3033 yyg->yy_did_buffer_switch_on_eof = 1;
3034 }
3035
3036 /** Removes and deletes the top of the stack, if present.
3037 * The next element becomes the new top.
3038 * @param yyscanner The scanner object.
3039 */
core_yypop_buffer_state(yyscan_t yyscanner)3040 void core_yypop_buffer_state (yyscan_t yyscanner)
3041 {
3042 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3043 if (!YY_CURRENT_BUFFER)
3044 return;
3045
3046 core_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
3047 YY_CURRENT_BUFFER_LVALUE = NULL;
3048 if (yyg->yy_buffer_stack_top > 0)
3049 --yyg->yy_buffer_stack_top;
3050
3051 if (YY_CURRENT_BUFFER) {
3052 core_yy_load_buffer_state(yyscanner );
3053 yyg->yy_did_buffer_switch_on_eof = 1;
3054 }
3055 }
3056
3057 /* Allocates the stack if it does not exist.
3058 * Guarantees space for at least one push.
3059 */
core_yyensure_buffer_stack(yyscan_t yyscanner)3060 static void core_yyensure_buffer_stack (yyscan_t yyscanner)
3061 {
3062 yy_size_t num_to_alloc;
3063 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3064
3065 if (!yyg->yy_buffer_stack) {
3066
3067 /* First allocation is just for 2 elements, since we don't know if this
3068 * scanner will even need a stack. We use 2 instead of 1 to avoid an
3069 * immediate realloc on the next call.
3070 */
3071 num_to_alloc = 1;
3072 yyg->yy_buffer_stack = (struct yy_buffer_state**)core_yyalloc
3073 (num_to_alloc * sizeof(struct yy_buffer_state*)
3074 , yyscanner);
3075 if ( ! yyg->yy_buffer_stack )
3076 YY_FATAL_ERROR( "out of dynamic memory in core_yyensure_buffer_stack()" );
3077
3078 memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
3079
3080 yyg->yy_buffer_stack_max = num_to_alloc;
3081 yyg->yy_buffer_stack_top = 0;
3082 return;
3083 }
3084
3085 if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
3086
3087 /* Increase the buffer to prepare for a possible push. */
3088 int grow_size = 8 /* arbitrary grow size */;
3089
3090 num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
3091 yyg->yy_buffer_stack = (struct yy_buffer_state**)core_yyrealloc
3092 (yyg->yy_buffer_stack,
3093 num_to_alloc * sizeof(struct yy_buffer_state*)
3094 , yyscanner);
3095 if ( ! yyg->yy_buffer_stack )
3096 YY_FATAL_ERROR( "out of dynamic memory in core_yyensure_buffer_stack()" );
3097
3098 /* zero only the new slots.*/
3099 memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
3100 yyg->yy_buffer_stack_max = num_to_alloc;
3101 }
3102 }
3103
3104 /** Setup the input buffer state to scan directly from a user-specified character buffer.
3105 * @param base the character buffer
3106 * @param size the size in bytes of the character buffer
3107 * @param yyscanner The scanner object.
3108 * @return the newly allocated buffer state object.
3109 */
core_yy_scan_buffer(char * base,yy_size_t size,yyscan_t yyscanner)3110 YY_BUFFER_STATE core_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
3111 {
3112 YY_BUFFER_STATE b;
3113
3114 if ( size < 2 ||
3115 base[size-2] != YY_END_OF_BUFFER_CHAR ||
3116 base[size-1] != YY_END_OF_BUFFER_CHAR )
3117 /* They forgot to leave room for the EOB's. */
3118 return 0;
3119
3120 b = (YY_BUFFER_STATE) core_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
3121 if ( ! b )
3122 YY_FATAL_ERROR( "out of dynamic memory in core_yy_scan_buffer()" );
3123
3124 b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
3125 b->yy_buf_pos = b->yy_ch_buf = base;
3126 b->yy_is_our_buffer = 0;
3127 b->yy_input_file = 0;
3128 b->yy_n_chars = b->yy_buf_size;
3129 b->yy_is_interactive = 0;
3130 b->yy_at_bol = 1;
3131 b->yy_fill_buffer = 0;
3132 b->yy_buffer_status = YY_BUFFER_NEW;
3133
3134 core_yy_switch_to_buffer(b ,yyscanner );
3135
3136 return b;
3137 }
3138
3139 /** Setup the input buffer state to scan a string. The next call to core_yylex() will
3140 * scan from a @e copy of @a str.
3141 * @param yystr a NUL-terminated string to scan
3142 * @param yyscanner The scanner object.
3143 * @return the newly allocated buffer state object.
3144 * @note If you want to scan bytes that may contain NUL values, then use
3145 * core_yy_scan_bytes() instead.
3146 */
core_yy_scan_string(yyconst char * yystr,yyscan_t yyscanner)3147 YY_BUFFER_STATE core_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
3148 {
3149
3150 return core_yy_scan_bytes(yystr,strlen(yystr) ,yyscanner);
3151 }
3152
3153 /** Setup the input buffer state to scan the given bytes. The next call to core_yylex() will
3154 * scan from a @e copy of @a bytes.
3155 * @param yybytes the byte buffer to scan
3156 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
3157 * @param yyscanner The scanner object.
3158 * @return the newly allocated buffer state object.
3159 */
core_yy_scan_bytes(yyconst char * yybytes,yy_size_t _yybytes_len,yyscan_t yyscanner)3160 YY_BUFFER_STATE core_yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len , yyscan_t yyscanner)
3161 {
3162 YY_BUFFER_STATE b;
3163 char *buf;
3164 yy_size_t n;
3165 int i;
3166
3167 /* Get memory for full buffer, including space for trailing EOB's. */
3168 n = _yybytes_len + 2;
3169 buf = (char *) core_yyalloc(n ,yyscanner );
3170 if ( ! buf )
3171 YY_FATAL_ERROR( "out of dynamic memory in core_yy_scan_bytes()" );
3172
3173 for ( i = 0; i < _yybytes_len; ++i )
3174 buf[i] = yybytes[i];
3175
3176 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
3177
3178 b = core_yy_scan_buffer(buf,n ,yyscanner);
3179 if ( ! b )
3180 YY_FATAL_ERROR( "bad buffer in core_yy_scan_bytes()" );
3181
3182 /* It's okay to grow etc. this buffer, and we should throw it
3183 * away when we're done.
3184 */
3185 b->yy_is_our_buffer = 1;
3186
3187 return b;
3188 }
3189
3190 #ifndef YY_EXIT_FAILURE
3191 #define YY_EXIT_FAILURE 2
3192 #endif
3193
yy_fatal_error(yyconst char * msg,yyscan_t yyscanner)3194 static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
3195 {
3196 (void) fprintf( stderr, "%s\n", msg );
3197 exit( YY_EXIT_FAILURE );
3198 }
3199
3200 /* Redefine yyless() so it works in section 3 code. */
3201
3202 #undef yyless
3203 #define yyless(n) \
3204 do \
3205 { \
3206 /* Undo effects of setting up yytext. */ \
3207 int yyless_macro_arg = (n); \
3208 YY_LESS_LINENO(yyless_macro_arg);\
3209 yytext[yyleng] = yyg->yy_hold_char; \
3210 yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
3211 yyg->yy_hold_char = *yyg->yy_c_buf_p; \
3212 *yyg->yy_c_buf_p = '\0'; \
3213 yyleng = yyless_macro_arg; \
3214 } \
3215 while ( 0 )
3216
3217 /* Accessor methods (get/set functions) to struct members. */
3218
3219 /** Get the user-defined data for this scanner.
3220 * @param yyscanner The scanner object.
3221 */
core_yyget_extra(yyscan_t yyscanner)3222 YY_EXTRA_TYPE core_yyget_extra (yyscan_t yyscanner)
3223 {
3224 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3225 return yyextra;
3226 }
3227
3228 /** Get the current line number.
3229 * @param yyscanner The scanner object.
3230 */
core_yyget_lineno(yyscan_t yyscanner)3231 int core_yyget_lineno (yyscan_t yyscanner)
3232 {
3233 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3234
3235 if (! YY_CURRENT_BUFFER)
3236 return 0;
3237
3238 return yylineno;
3239 }
3240
3241 /** Get the current column number.
3242 * @param yyscanner The scanner object.
3243 */
core_yyget_column(yyscan_t yyscanner)3244 int core_yyget_column (yyscan_t yyscanner)
3245 {
3246 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3247
3248 if (! YY_CURRENT_BUFFER)
3249 return 0;
3250
3251 return yycolumn;
3252 }
3253
3254 /** Get the input stream.
3255 * @param yyscanner The scanner object.
3256 */
core_yyget_in(yyscan_t yyscanner)3257 FILE *core_yyget_in (yyscan_t yyscanner)
3258 {
3259 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3260 return yyin;
3261 }
3262
3263 /** Get the output stream.
3264 * @param yyscanner The scanner object.
3265 */
core_yyget_out(yyscan_t yyscanner)3266 FILE *core_yyget_out (yyscan_t yyscanner)
3267 {
3268 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3269 return yyout;
3270 }
3271
3272 /** Get the length of the current token.
3273 * @param yyscanner The scanner object.
3274 */
core_yyget_leng(yyscan_t yyscanner)3275 yy_size_t core_yyget_leng (yyscan_t yyscanner)
3276 {
3277 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3278 return yyleng;
3279 }
3280
3281 /** Get the current token.
3282 * @param yyscanner The scanner object.
3283 */
3284
core_yyget_text(yyscan_t yyscanner)3285 char *core_yyget_text (yyscan_t yyscanner)
3286 {
3287 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3288 return yytext;
3289 }
3290
3291 /** Set the user-defined data. This data is never touched by the scanner.
3292 * @param user_defined The data to be associated with this scanner.
3293 * @param yyscanner The scanner object.
3294 */
core_yyset_extra(YY_EXTRA_TYPE user_defined,yyscan_t yyscanner)3295 void core_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
3296 {
3297 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3298 yyextra = user_defined ;
3299 }
3300
3301 /** Set the current line number.
3302 * @param line_number
3303 * @param yyscanner The scanner object.
3304 */
core_yyset_lineno(int line_number,yyscan_t yyscanner)3305 void core_yyset_lineno (int line_number , yyscan_t yyscanner)
3306 {
3307 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3308
3309 /* lineno is only valid if an input buffer exists. */
3310 if (! YY_CURRENT_BUFFER )
3311 YY_FATAL_ERROR( "core_yyset_lineno called with no buffer" );
3312
3313 yylineno = line_number;
3314 }
3315
3316 /** Set the current column.
3317 * @param line_number
3318 * @param yyscanner The scanner object.
3319 */
core_yyset_column(int column_no,yyscan_t yyscanner)3320 void core_yyset_column (int column_no , yyscan_t yyscanner)
3321 {
3322 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3323
3324 /* column is only valid if an input buffer exists. */
3325 if (! YY_CURRENT_BUFFER )
3326 YY_FATAL_ERROR( "core_yyset_column called with no buffer" );
3327
3328 yycolumn = column_no;
3329 }
3330
3331 /** Set the input stream. This does not discard the current
3332 * input buffer.
3333 * @param in_str A readable stream.
3334 * @param yyscanner The scanner object.
3335 * @see core_yy_switch_to_buffer
3336 */
core_yyset_in(FILE * in_str,yyscan_t yyscanner)3337 void core_yyset_in (FILE * in_str , yyscan_t yyscanner)
3338 {
3339 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3340 yyin = in_str ;
3341 }
3342
core_yyset_out(FILE * out_str,yyscan_t yyscanner)3343 void core_yyset_out (FILE * out_str , yyscan_t yyscanner)
3344 {
3345 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3346 yyout = out_str ;
3347 }
3348
core_yyget_debug(yyscan_t yyscanner)3349 int core_yyget_debug (yyscan_t yyscanner)
3350 {
3351 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3352 return yy_flex_debug;
3353 }
3354
core_yyset_debug(int bdebug,yyscan_t yyscanner)3355 void core_yyset_debug (int bdebug , yyscan_t yyscanner)
3356 {
3357 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3358 yy_flex_debug = bdebug ;
3359 }
3360
3361 /* Accessor methods for yylval and yylloc */
3362
core_yyget_lval(yyscan_t yyscanner)3363 YYSTYPE * core_yyget_lval (yyscan_t yyscanner)
3364 {
3365 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3366 return yylval;
3367 }
3368
core_yyset_lval(YYSTYPE * yylval_param,yyscan_t yyscanner)3369 void core_yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
3370 {
3371 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3372 yylval = yylval_param;
3373 }
3374
core_yyget_lloc(yyscan_t yyscanner)3375 YYLTYPE *core_yyget_lloc (yyscan_t yyscanner)
3376 {
3377 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3378 return yylloc;
3379 }
3380
core_yyset_lloc(YYLTYPE * yylloc_param,yyscan_t yyscanner)3381 void core_yyset_lloc (YYLTYPE * yylloc_param , yyscan_t yyscanner)
3382 {
3383 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3384 yylloc = yylloc_param;
3385 }
3386
3387 /* User-visible API */
3388
3389 /* core_yylex_init is special because it creates the scanner itself, so it is
3390 * the ONLY reentrant function that doesn't take the scanner as the last argument.
3391 * That's why we explicitly handle the declaration, instead of using our macros.
3392 */
3393
core_yylex_init(yyscan_t * ptr_yy_globals)3394 int core_yylex_init(yyscan_t* ptr_yy_globals)
3395
3396 {
3397 if (ptr_yy_globals == NULL){
3398 errno = EINVAL;
3399 return 1;
3400 }
3401
3402 *ptr_yy_globals = (yyscan_t) core_yyalloc ( sizeof( struct yyguts_t ), NULL );
3403
3404 if (*ptr_yy_globals == NULL){
3405 errno = ENOMEM;
3406 return 1;
3407 }
3408
3409 /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
3410 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
3411
3412 return yy_init_globals ( *ptr_yy_globals );
3413 }
3414
3415 /* core_yylex_init_extra has the same functionality as core_yylex_init, but follows the
3416 * convention of taking the scanner as the last argument. Note however, that
3417 * this is a *pointer* to a scanner, as it will be allocated by this call (and
3418 * is the reason, too, why this function also must handle its own declaration).
3419 * The user defined value in the first argument will be available to core_yyalloc in
3420 * the yyextra field.
3421 */
3422
core_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t * ptr_yy_globals)3423 int core_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
3424
3425 {
3426 struct yyguts_t dummy_yyguts;
3427
3428 core_yyset_extra (yy_user_defined, &dummy_yyguts);
3429
3430 if (ptr_yy_globals == NULL){
3431 errno = EINVAL;
3432 return 1;
3433 }
3434
3435 *ptr_yy_globals = (yyscan_t) core_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
3436
3437 if (*ptr_yy_globals == NULL){
3438 errno = ENOMEM;
3439 return 1;
3440 }
3441
3442 /* By setting to 0xAA, we expose bugs in
3443 yy_init_globals. Leave at 0x00 for releases. */
3444 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
3445
3446 core_yyset_extra (yy_user_defined, *ptr_yy_globals);
3447
3448 return yy_init_globals ( *ptr_yy_globals );
3449 }
3450
yy_init_globals(yyscan_t yyscanner)3451 static int yy_init_globals (yyscan_t yyscanner)
3452 {
3453 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3454 /* Initialization is the same as for the non-reentrant scanner.
3455 * This function is called from core_yylex_destroy(), so don't allocate here.
3456 */
3457
3458 yyg->yy_buffer_stack = 0;
3459 yyg->yy_buffer_stack_top = 0;
3460 yyg->yy_buffer_stack_max = 0;
3461 yyg->yy_c_buf_p = (char *) 0;
3462 yyg->yy_init = 0;
3463 yyg->yy_start = 0;
3464
3465 yyg->yy_start_stack_ptr = 0;
3466 yyg->yy_start_stack_depth = 0;
3467 yyg->yy_start_stack = NULL;
3468
3469 /* Defined in main.c */
3470 #ifdef YY_STDINIT
3471 yyin = stdin;
3472 yyout = stdout;
3473 #else
3474 yyin = (FILE *) 0;
3475 yyout = (FILE *) 0;
3476 #endif
3477
3478 /* For future reference: Set errno on error, since we are called by
3479 * core_yylex_init()
3480 */
3481 return 0;
3482 }
3483
3484 /* core_yylex_destroy is for both reentrant and non-reentrant scanners. */
core_yylex_destroy(yyscan_t yyscanner)3485 int core_yylex_destroy (yyscan_t yyscanner)
3486 {
3487 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3488
3489 /* Pop the buffer stack, destroying each element. */
3490 while(YY_CURRENT_BUFFER){
3491 core_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
3492 YY_CURRENT_BUFFER_LVALUE = NULL;
3493 core_yypop_buffer_state(yyscanner);
3494 }
3495
3496 /* Destroy the stack itself. */
3497 core_yyfree(yyg->yy_buffer_stack ,yyscanner);
3498 yyg->yy_buffer_stack = NULL;
3499
3500 /* Destroy the start condition stack. */
3501 core_yyfree(yyg->yy_start_stack ,yyscanner );
3502 yyg->yy_start_stack = NULL;
3503
3504 /* Reset the globals. This is important in a non-reentrant scanner so the next time
3505 * core_yylex() is called, initialization will occur. */
3506 yy_init_globals( yyscanner);
3507
3508 /* Destroy the main struct (reentrant only). */
3509 core_yyfree ( yyscanner , yyscanner );
3510 yyscanner = NULL;
3511 return 0;
3512 }
3513
3514 /*
3515 * Internal utility routines.
3516 */
3517
3518 #ifndef yytext_ptr
yy_flex_strncpy(char * s1,yyconst char * s2,int n,yyscan_t yyscanner)3519 static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
3520 {
3521 register int i;
3522 for ( i = 0; i < n; ++i )
3523 s1[i] = s2[i];
3524 }
3525 #endif
3526
3527 #ifdef YY_NEED_STRLEN
yy_flex_strlen(yyconst char * s,yyscan_t yyscanner)3528 static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
3529 {
3530 register int n;
3531 for ( n = 0; s[n]; ++n )
3532 ;
3533
3534 return n;
3535 }
3536 #endif
3537
3538 #define YYTABLES_NAME "yytables"
3539
3540 #line 1081 "scan.l"
3541
3542
3543
3544 /* LCOV_EXCL_STOP */
3545
3546 /*
3547 * Arrange access to yyextra for subroutines of the main core_yylex() function.
3548 * We expect each subroutine to have a yyscanner parameter. Rather than
3549 * use the yyget_xxx functions, which might or might not get inlined by the
3550 * compiler, we cheat just a bit and cast yyscanner to the right type.
3551 */
3552 #undef yyextra
3553 #define yyextra (((struct yyguts_t *) yyscanner)->yyextra_r)
3554
3555 /* Likewise for a couple of other things we need. */
3556 #undef yylloc
3557 #define yylloc (((struct yyguts_t *) yyscanner)->yylloc_r)
3558 #undef yyleng
3559 #define yyleng (((struct yyguts_t *) yyscanner)->yyleng_r)
3560
3561
3562 /*
3563 * scanner_errposition
3564 * Report a lexer or grammar error cursor position, if possible.
3565 *
3566 * This is expected to be used within an ereport() call. The return value
3567 * is a dummy (always 0, in fact).
3568 *
3569 * Note that this can only be used for messages emitted during raw parsing
3570 * (essentially, scan.l and gram.y), since it requires the yyscanner struct
3571 * to still be available.
3572 */
3573 int
scanner_errposition(int location,core_yyscan_t yyscanner)3574 scanner_errposition(int location, core_yyscan_t yyscanner)
3575 {
3576 #ifdef PGPOOL_NOT_USED
3577 int pos;
3578
3579 if (location < 0)
3580 return 0; /* no-op if location is unknown */
3581
3582 /* Convert byte offset to character number */
3583 pos = pg_mbstrlen_with_len(yyextra->scanbuf, location) + 1;
3584 /* And pass it to the ereport mechanism */
3585 return errposition(pos);
3586 #endif
3587 return 0;
3588 }
3589
3590 /*
3591 * scanner_yyerror
3592 * Report a lexer or grammar error.
3593 *
3594 * The message's cursor position is whatever YYLLOC was last set to,
3595 * ie, the start of the current token if called within core_yylex(), or the
3596 * most recently lexed token if called from the grammar.
3597 * This is OK for syntax error messages from the Bison parser, because Bison
3598 * parsers report error as soon as the first unparsable token is reached.
3599 * Beware of using yyerror for other purposes, as the cursor position might
3600 * be misleading!
3601 */
3602 void
scanner_yyerror(const char * message,core_yyscan_t yyscanner)3603 scanner_yyerror(const char *message, core_yyscan_t yyscanner)
3604 {
3605 const char *loc = yyextra->scanbuf + *yylloc;
3606
3607 if (*loc == YY_END_OF_BUFFER_CHAR)
3608 {
3609 ereport(ERROR,
3610 (errcode(ERRCODE_SYNTAX_ERROR),
3611 /* translator: %s is typically the translation of "syntax error" */
3612 errmsg("%s at end of input", _(message)),
3613 lexer_errposition()));
3614 }
3615 else
3616 {
3617 ereport(ERROR,
3618 (errcode(ERRCODE_SYNTAX_ERROR),
3619 /* translator: first %s is typically the translation of "syntax error" */
3620 errmsg("%s at or near \"%s\"", _(message), loc),
3621 lexer_errposition()));
3622 }
3623 }
3624
3625
3626 /*
3627 * Called before any actual parsing is done
3628 */
3629 core_yyscan_t
scanner_init(const char * str,int slen,core_yy_extra_type * yyext,const ScanKeywordList * keywordlist,const uint16 * keyword_tokens)3630 scanner_init(const char *str,
3631 int slen,
3632 core_yy_extra_type *yyext,
3633 const ScanKeywordList *keywordlist,
3634 const uint16 *keyword_tokens)
3635 {
3636 yyscan_t scanner;
3637
3638 if (core_yylex_init(&scanner) != 0)
3639 elog(ERROR, "core_yylex_init() failed: %m");
3640
3641 core_yyset_extra(yyext, scanner);
3642
3643 yyext->keywordlist = keywordlist;
3644 yyext->keyword_tokens = keyword_tokens;
3645
3646 yyext->backslash_quote = backslash_quote;
3647 yyext->escape_string_warning = escape_string_warning;
3648 yyext->standard_conforming_strings = standard_conforming_strings;
3649
3650 /*
3651 * Make a scan buffer with special termination needed by flex.
3652 */
3653 yyext->scanbuf = (char *) palloc(slen + 2);
3654 yyext->scanbuflen = slen;
3655 memcpy(yyext->scanbuf, str, slen);
3656 yyext->scanbuf[slen] = yyext->scanbuf[slen + 1] = YY_END_OF_BUFFER_CHAR;
3657 core_yy_scan_buffer(yyext->scanbuf,slen + 2,scanner);
3658
3659 /* initialize literal buffer to a reasonable but expansible size */
3660 yyext->literalalloc = 1024;
3661 yyext->literalbuf = (char *) palloc(yyext->literalalloc);
3662 yyext->literallen = 0;
3663
3664 return scanner;
3665 }
3666
3667
3668 /*
3669 * Called after parsing is done to clean up after scanner_init()
3670 */
3671 void
scanner_finish(core_yyscan_t yyscanner)3672 scanner_finish(core_yyscan_t yyscanner)
3673 {
3674 /*
3675 * We don't bother to call core_yylex_destroy(), because all it would do is
3676 * pfree a small amount of control storage. It's cheaper to leak the
3677 * storage until the parsing context is destroyed. The amount of space
3678 * involved is usually negligible compared to the output parse tree
3679 * anyway.
3680 *
3681 * We do bother to pfree the scanbuf and literal buffer, but only if they
3682 * represent a nontrivial amount of space. The 8K cutoff is arbitrary.
3683 */
3684 if (yyextra->scanbuflen >= 8192)
3685 pfree(yyextra->scanbuf);
3686 if (yyextra->literalalloc >= 8192)
3687 pfree(yyextra->literalbuf);
3688 }
3689
3690
3691 static void
addlit(char * ytext,int yleng,core_yyscan_t yyscanner)3692 addlit(char *ytext, int yleng, core_yyscan_t yyscanner)
3693 {
3694 /* enlarge buffer if needed */
3695 if ((yyextra->literallen + yleng) >= yyextra->literalalloc)
3696 {
3697 do
3698 {
3699 yyextra->literalalloc *= 2;
3700 } while ((yyextra->literallen + yleng) >= yyextra->literalalloc);
3701 yyextra->literalbuf = (char *) repalloc(yyextra->literalbuf,
3702 yyextra->literalalloc);
3703 }
3704 /* append new data */
3705 memcpy(yyextra->literalbuf + yyextra->literallen, ytext, yleng);
3706 yyextra->literallen += yleng;
3707 }
3708
3709
3710 static void
addlitchar(unsigned char ychar,core_yyscan_t yyscanner)3711 addlitchar(unsigned char ychar, core_yyscan_t yyscanner)
3712 {
3713 /* enlarge buffer if needed */
3714 if ((yyextra->literallen + 1) >= yyextra->literalalloc)
3715 {
3716 yyextra->literalalloc *= 2;
3717 yyextra->literalbuf = (char *) repalloc(yyextra->literalbuf,
3718 yyextra->literalalloc);
3719 }
3720 /* append new data */
3721 yyextra->literalbuf[yyextra->literallen] = ychar;
3722 yyextra->literallen += 1;
3723 }
3724
3725
3726 /*
3727 * Create a palloc'd copy of literalbuf, adding a trailing null.
3728 */
3729 static char *
litbufdup(core_yyscan_t yyscanner)3730 litbufdup(core_yyscan_t yyscanner)
3731 {
3732 int llen = yyextra->literallen;
3733 char *new;
3734
3735 new = palloc(llen + 1);
3736 memcpy(new, yyextra->literalbuf, llen);
3737 new[llen] = '\0';
3738 return new;
3739 }
3740
3741 /*
3742 * Process {integer}. Note this will also do the right thing with {decimal},
3743 * ie digits and a decimal point.
3744 */
3745 static int
process_integer_literal(const char * token,YYSTYPE * lval)3746 process_integer_literal(const char *token, YYSTYPE *lval)
3747 {
3748 int val;
3749 long val_long;
3750 char *endptr;
3751
3752 errno = 0;
3753 val_long = strtol(token, &endptr, 10);
3754 val = (int) val_long;
3755
3756 if (*endptr != '\0' || errno == ERANGE
3757 #ifdef HAVE_LONG_INT_64
3758 /* if long > 32 bits, check for overflow of int4 */
3759 || val != (int) val_long
3760 #endif
3761 )
3762 {
3763 /* integer too large (or contains decimal pt), treat it as a float */
3764 lval->str = pstrdup(token);
3765 return FCONST;
3766 }
3767 lval->ival = val;
3768 return ICONST;
3769 }
3770
3771 static unsigned int
hexval(unsigned char c)3772 hexval(unsigned char c)
3773 {
3774 if (c >= '0' && c <= '9')
3775 return c - '0';
3776 if (c >= 'a' && c <= 'f')
3777 return c - 'a' + 0xA;
3778 if (c >= 'A' && c <= 'F')
3779 return c - 'A' + 0xA;
3780 elog(ERROR, "invalid hexadecimal digit");
3781 return 0; /* not reached */
3782 }
3783
3784 static void
check_unicode_value(pg_wchar c,char * loc,core_yyscan_t yyscanner)3785 check_unicode_value(pg_wchar c, char *loc, core_yyscan_t yyscanner)
3786 {
3787 if (GetDatabaseEncoding() == PG_UTF8)
3788 return;
3789
3790 if (c > 0x7F)
3791 {
3792 ADVANCE_YYLLOC(loc - yyextra->literalbuf + 3); /* 3 for U&" */
3793 yyerror("Unicode escape values cannot be used for code point values above 007F when the server encoding is not UTF8");
3794 }
3795 }
3796
3797 static bool
is_utf16_surrogate_first(pg_wchar c)3798 is_utf16_surrogate_first(pg_wchar c)
3799 {
3800 return (c >= 0xD800 && c <= 0xDBFF);
3801 }
3802
3803 static bool
is_utf16_surrogate_second(pg_wchar c)3804 is_utf16_surrogate_second(pg_wchar c)
3805 {
3806 return (c >= 0xDC00 && c <= 0xDFFF);
3807 }
3808
3809 static pg_wchar
surrogate_pair_to_codepoint(pg_wchar first,pg_wchar second)3810 surrogate_pair_to_codepoint(pg_wchar first, pg_wchar second)
3811 {
3812 return ((first & 0x3FF) << 10) + 0x10000 + (second & 0x3FF);
3813 }
3814
3815 static void
addunicode(pg_wchar c,core_yyscan_t yyscanner)3816 addunicode(pg_wchar c, core_yyscan_t yyscanner)
3817 {
3818 char buf[8];
3819
3820 if (c == 0 || c > 0x10FFFF)
3821 yyerror("invalid Unicode escape value");
3822 if (c > 0x7F)
3823 {
3824 if (GetDatabaseEncoding() != PG_UTF8)
3825 yyerror("Unicode escape values cannot be used for code point values above 007F when the server encoding is not UTF8");
3826 yyextra->saw_non_ascii = true;
3827 }
3828 unicode_to_utf8(c, (unsigned char *) buf);
3829 addlit(buf, pg_mblen(buf), yyscanner);
3830 }
3831
3832 /* is 'escape' acceptable as Unicode escape character (UESCAPE syntax) ? */
3833 static bool
check_uescapechar(unsigned char escape)3834 check_uescapechar(unsigned char escape)
3835 {
3836 if (isxdigit(escape)
3837 || escape == '+'
3838 || escape == '\''
3839 || escape == '"'
3840 || scanner_isspace(escape))
3841 {
3842 return false;
3843 }
3844 else
3845 return true;
3846 }
3847
3848 /* like litbufdup, but handle unicode escapes */
3849 static char *
litbuf_udeescape(unsigned char escape,core_yyscan_t yyscanner)3850 litbuf_udeescape(unsigned char escape, core_yyscan_t yyscanner)
3851 {
3852 char *new;
3853 char *litbuf,
3854 *in,
3855 *out;
3856 pg_wchar pair_first = 0;
3857
3858 /* Make literalbuf null-terminated to simplify the scanning loop */
3859 litbuf = yyextra->literalbuf;
3860 litbuf[yyextra->literallen] = '\0';
3861
3862 /*
3863 * This relies on the subtle assumption that a UTF-8 expansion cannot be
3864 * longer than its escaped representation.
3865 */
3866 new = palloc(yyextra->literallen + 1);
3867
3868 in = litbuf;
3869 out = new;
3870 while (*in)
3871 {
3872 if (in[0] == escape)
3873 {
3874 if (in[1] == escape)
3875 {
3876 if (pair_first)
3877 {
3878 ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
3879 yyerror("invalid Unicode surrogate pair");
3880 }
3881 *out++ = escape;
3882 in += 2;
3883 }
3884 else if (isxdigit((unsigned char) in[1]) &&
3885 isxdigit((unsigned char) in[2]) &&
3886 isxdigit((unsigned char) in[3]) &&
3887 isxdigit((unsigned char) in[4]))
3888 {
3889 pg_wchar unicode;
3890
3891 unicode = (hexval(in[1]) << 12) +
3892 (hexval(in[2]) << 8) +
3893 (hexval(in[3]) << 4) +
3894 hexval(in[4]);
3895 check_unicode_value(unicode, in, yyscanner);
3896 if (pair_first)
3897 {
3898 if (is_utf16_surrogate_second(unicode))
3899 {
3900 unicode = surrogate_pair_to_codepoint(pair_first, unicode);
3901 pair_first = 0;
3902 }
3903 else
3904 {
3905 ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
3906 yyerror("invalid Unicode surrogate pair");
3907 }
3908 }
3909 else if (is_utf16_surrogate_second(unicode))
3910 yyerror("invalid Unicode surrogate pair");
3911
3912 if (is_utf16_surrogate_first(unicode))
3913 pair_first = unicode;
3914 else
3915 {
3916 unicode_to_utf8(unicode, (unsigned char *) out);
3917 out += pg_mblen(out);
3918 }
3919 in += 5;
3920 }
3921 else if (in[1] == '+' &&
3922 isxdigit((unsigned char) in[2]) &&
3923 isxdigit((unsigned char) in[3]) &&
3924 isxdigit((unsigned char) in[4]) &&
3925 isxdigit((unsigned char) in[5]) &&
3926 isxdigit((unsigned char) in[6]) &&
3927 isxdigit((unsigned char) in[7]))
3928 {
3929 pg_wchar unicode;
3930
3931 unicode = (hexval(in[2]) << 20) +
3932 (hexval(in[3]) << 16) +
3933 (hexval(in[4]) << 12) +
3934 (hexval(in[5]) << 8) +
3935 (hexval(in[6]) << 4) +
3936 hexval(in[7]);
3937 check_unicode_value(unicode, in, yyscanner);
3938 if (pair_first)
3939 {
3940 if (is_utf16_surrogate_second(unicode))
3941 {
3942 unicode = surrogate_pair_to_codepoint(pair_first, unicode);
3943 pair_first = 0;
3944 }
3945 else
3946 {
3947 ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
3948 yyerror("invalid Unicode surrogate pair");
3949 }
3950 }
3951 else if (is_utf16_surrogate_second(unicode))
3952 yyerror("invalid Unicode surrogate pair");
3953
3954 if (is_utf16_surrogate_first(unicode))
3955 pair_first = unicode;
3956 else
3957 {
3958 unicode_to_utf8(unicode, (unsigned char *) out);
3959 out += pg_mblen(out);
3960 }
3961 in += 8;
3962 }
3963 else
3964 {
3965 ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
3966 yyerror("invalid Unicode escape value");
3967 }
3968 }
3969 else
3970 {
3971 if (pair_first)
3972 {
3973 ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
3974 yyerror("invalid Unicode surrogate pair");
3975 }
3976 *out++ = *in++;
3977 }
3978 }
3979
3980 /* unfinished surrogate pair? */
3981 if (pair_first)
3982 {
3983 ADVANCE_YYLLOC(in - litbuf + 3); /* 3 for U&" */
3984 yyerror("invalid Unicode surrogate pair");
3985 }
3986
3987 *out = '\0';
3988
3989 /*
3990 * We could skip pg_verifymbstr if we didn't process any non-7-bit-ASCII
3991 * codes; but it's probably not worth the trouble, since this isn't likely
3992 * to be a performance-critical path.
3993 */
3994 pg_verifymbstr(new, out - new, false);
3995 return new;
3996 }
3997
3998 static unsigned char
unescape_single_char(unsigned char c,core_yyscan_t yyscanner)3999 unescape_single_char(unsigned char c, core_yyscan_t yyscanner)
4000 {
4001 switch (c)
4002 {
4003 case 'b':
4004 return '\b';
4005 case 'f':
4006 return '\f';
4007 case 'n':
4008 return '\n';
4009 case 'r':
4010 return '\r';
4011 case 't':
4012 return '\t';
4013 default:
4014 /* check for backslash followed by non-7-bit-ASCII */
4015 if (c == '\0' || IS_HIGHBIT_SET(c))
4016 yyextra->saw_non_ascii = true;
4017
4018 return c;
4019 }
4020 }
4021
4022 static void
check_string_escape_warning(unsigned char ychar,core_yyscan_t yyscanner)4023 check_string_escape_warning(unsigned char ychar, core_yyscan_t yyscanner)
4024 {
4025 if (ychar == '\'')
4026 {
4027 if (yyextra->warn_on_first_escape && yyextra->escape_string_warning)
4028 ereport(WARNING,
4029 (errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
4030 errmsg("nonstandard use of \\' in a string literal"),
4031 errhint("Use '' to write quotes in strings, or use the escape string syntax (E'...')."),
4032 lexer_errposition()));
4033 yyextra->warn_on_first_escape = false; /* warn only once per string */
4034 }
4035 else if (ychar == '\\')
4036 {
4037 if (yyextra->warn_on_first_escape && yyextra->escape_string_warning)
4038 ereport(WARNING,
4039 (errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
4040 errmsg("nonstandard use of \\\\ in a string literal"),
4041 errhint("Use the escape string syntax for backslashes, e.g., E'\\\\'."),
4042 lexer_errposition()));
4043 yyextra->warn_on_first_escape = false; /* warn only once per string */
4044 }
4045 else
4046 check_escape_warning(yyscanner);
4047 }
4048
4049 static void
check_escape_warning(core_yyscan_t yyscanner)4050 check_escape_warning(core_yyscan_t yyscanner)
4051 {
4052 if (yyextra->warn_on_first_escape && yyextra->escape_string_warning)
4053 ereport(WARNING,
4054 (errcode(ERRCODE_NONSTANDARD_USE_OF_ESCAPE_CHARACTER),
4055 errmsg("nonstandard use of escape in a string literal"),
4056 errhint("Use the escape string syntax for escapes, e.g., E'\\r\\n'."),
4057 lexer_errposition()));
4058 yyextra->warn_on_first_escape = false; /* warn only once per string */
4059 }
4060
4061 /*
4062 * Interface functions to make flex use palloc() instead of malloc().
4063 * It'd be better to make these static, but flex insists otherwise.
4064 */
4065
4066 void *
core_yyalloc(yy_size_t bytes,core_yyscan_t yyscanner)4067 core_yyalloc(yy_size_t bytes, core_yyscan_t yyscanner)
4068 {
4069 return palloc(bytes);
4070 }
4071
4072 void *
core_yyrealloc(void * ptr,yy_size_t bytes,core_yyscan_t yyscanner)4073 core_yyrealloc(void *ptr, yy_size_t bytes, core_yyscan_t yyscanner)
4074 {
4075 if (ptr)
4076 return repalloc(ptr, bytes);
4077 else
4078 return palloc(bytes);
4079 }
4080
4081 void
core_yyfree(void * ptr,core_yyscan_t yyscanner)4082 core_yyfree(void *ptr, core_yyscan_t yyscanner)
4083 {
4084 if (ptr)
4085 pfree(ptr);
4086 }
4087
4088