1#line 2 "exprscan.c"
2
3#line 4 "exprscan.c"
4
5#define YY_INT_ALIGNED short int
6
7/* A lexical scanner generated by flex */
8
9#define FLEX_SCANNER
10#define YY_FLEX_MAJOR_VERSION 2
11#define YY_FLEX_MINOR_VERSION 6
12#define YY_FLEX_SUBMINOR_VERSION 1
13#if YY_FLEX_SUBMINOR_VERSION > 0
14#define FLEX_BETA
15#endif
16
17/* First, we deal with platform-specific or compiler-specific issues. */
18
19/* begin standard C headers. */
20#include <stdio.h>
21#include <string.h>
22#include <errno.h>
23#include <stdlib.h>
24
25/* end standard C headers. */
26
27/* flex integer type definitions */
28
29#ifndef FLEXINT_H
30#define FLEXINT_H
31
32/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
33
34#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
35
36/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
37 * if you want the limit (max/min) macros for int types.
38 */
39#ifndef __STDC_LIMIT_MACROS
40#define __STDC_LIMIT_MACROS 1
41#endif
42
43#include <inttypes.h>
44typedef int8_t flex_int8_t;
45typedef uint8_t flex_uint8_t;
46typedef int16_t flex_int16_t;
47typedef uint16_t flex_uint16_t;
48typedef int32_t flex_int32_t;
49typedef uint32_t flex_uint32_t;
50#else
51typedef signed char flex_int8_t;
52typedef short int flex_int16_t;
53typedef int flex_int32_t;
54typedef unsigned char flex_uint8_t;
55typedef unsigned short int flex_uint16_t;
56typedef unsigned int flex_uint32_t;
57
58/* Limits of integral types. */
59#ifndef INT8_MIN
60#define INT8_MIN (-128)
61#endif
62#ifndef INT16_MIN
63#define INT16_MIN (-32767-1)
64#endif
65#ifndef INT32_MIN
66#define INT32_MIN (-2147483647-1)
67#endif
68#ifndef INT8_MAX
69#define INT8_MAX (127)
70#endif
71#ifndef INT16_MAX
72#define INT16_MAX (32767)
73#endif
74#ifndef INT32_MAX
75#define INT32_MAX (2147483647)
76#endif
77#ifndef UINT8_MAX
78#define UINT8_MAX (255U)
79#endif
80#ifndef UINT16_MAX
81#define UINT16_MAX (65535U)
82#endif
83#ifndef UINT32_MAX
84#define UINT32_MAX (4294967295U)
85#endif
86
87#endif /* ! C99 */
88
89#endif /* ! FLEXINT_H */
90
91/* TODO: this is always defined, so inline it */
92#define yyconst const
93
94#if defined(__GNUC__) && __GNUC__ >= 3
95#define yynoreturn __attribute__((__noreturn__))
96#else
97#define yynoreturn
98#endif
99
100/* Returned upon end-of-file. */
101#define YY_NULL 0
102
103/* Promotes a possibly negative, possibly signed char to an unsigned
104 * integer for use as an array index. If the signed char is negative,
105 * we want to instead treat it as an 8-bit unsigned char, hence the
106 * double cast.
107 */
108#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
109
110/* An opaque pointer. */
111#ifndef YY_TYPEDEF_YY_SCANNER_T
112#define YY_TYPEDEF_YY_SCANNER_T
113typedef void* yyscan_t;
114#endif
115
116/* For convenience, these vars (plus the bison vars far below)
117 are macros in the reentrant scanner. */
118#define yyin yyg->yyin_r
119#define yyout yyg->yyout_r
120#define yyextra yyg->yyextra_r
121#define yyleng yyg->yyleng_r
122#define yytext yyg->yytext_r
123#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
124#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
125#define yy_flex_debug yyg->yy_flex_debug_r
126
127/* Enter a start condition. This macro really ought to take a parameter,
128 * but we do it the disgusting crufty way forced on us by the ()-less
129 * definition of BEGIN.
130 */
131#define BEGIN yyg->yy_start = 1 + 2 *
132
133/* Translate the current start state into a value that can be later handed
134 * to BEGIN to return to the state. The YYSTATE alias is for lex
135 * compatibility.
136 */
137#define YY_START ((yyg->yy_start - 1) / 2)
138#define YYSTATE YY_START
139
140/* Action number for EOF rule of a given start state. */
141#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
142
143/* Special action meaning "start processing a new file". */
144#define YY_NEW_FILE expr_yyrestart(yyin ,yyscanner )
145
146#define YY_END_OF_BUFFER_CHAR 0
147
148/* Size of default input buffer. */
149#ifndef YY_BUF_SIZE
150#ifdef __ia64__
151/* On IA-64, the buffer size is 16k, not 8k.
152 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
153 * Ditto for the __ia64__ case accordingly.
154 */
155#define YY_BUF_SIZE 32768
156#else
157#define YY_BUF_SIZE 16384
158#endif /* __ia64__ */
159#endif
160
161/* The state buf must be large enough to hold one state per character in the main buffer.
162 */
163#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
164
165#ifndef YY_TYPEDEF_YY_BUFFER_STATE
166#define YY_TYPEDEF_YY_BUFFER_STATE
167typedef struct yy_buffer_state *YY_BUFFER_STATE;
168#endif
169
170#ifndef YY_TYPEDEF_YY_SIZE_T
171#define YY_TYPEDEF_YY_SIZE_T
172typedef size_t yy_size_t;
173#endif
174
175#define EOB_ACT_CONTINUE_SCAN 0
176#define EOB_ACT_END_OF_FILE 1
177#define EOB_ACT_LAST_MATCH 2
178
179 #define YY_LESS_LINENO(n)
180 #define YY_LINENO_REWIND_TO(ptr)
181
182/* Return all but the first "n" matched characters back to the input stream. */
183#define yyless(n) \
184 do \
185 { \
186 /* Undo effects of setting up yytext. */ \
187 int yyless_macro_arg = (n); \
188 YY_LESS_LINENO(yyless_macro_arg);\
189 *yy_cp = yyg->yy_hold_char; \
190 YY_RESTORE_YY_MORE_OFFSET \
191 yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
192 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
193 } \
194 while ( 0 )
195
196#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
197
198#ifndef YY_STRUCT_YY_BUFFER_STATE
199#define YY_STRUCT_YY_BUFFER_STATE
200struct yy_buffer_state
201 {
202 FILE *yy_input_file;
203
204 char *yy_ch_buf; /* input buffer */
205 char *yy_buf_pos; /* current position in input buffer */
206
207 /* Size of input buffer in bytes, not including room for EOB
208 * characters.
209 */
210 int yy_buf_size;
211
212 /* Number of characters read into yy_ch_buf, not including EOB
213 * characters.
214 */
215 int yy_n_chars;
216
217 /* Whether we "own" the buffer - i.e., we know we created it,
218 * and can realloc() it to grow it, and should free() it to
219 * delete it.
220 */
221 int yy_is_our_buffer;
222
223 /* Whether this is an "interactive" input source; if so, and
224 * if we're using stdio for input, then we want to use getc()
225 * instead of fread(), to make sure we stop fetching input after
226 * each newline.
227 */
228 int yy_is_interactive;
229
230 /* Whether we're considered to be at the beginning of a line.
231 * If so, '^' rules will be active on the next match, otherwise
232 * not.
233 */
234 int yy_at_bol;
235
236 int yy_bs_lineno; /**< The line count. */
237 int yy_bs_column; /**< The column count. */
238
239 /* Whether to try to fill the input buffer when we reach the
240 * end of it.
241 */
242 int yy_fill_buffer;
243
244 int yy_buffer_status;
245
246#define YY_BUFFER_NEW 0
247#define YY_BUFFER_NORMAL 1
248 /* When an EOF's been seen but there's still some text to process
249 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
250 * shouldn't try reading from the input source any more. We might
251 * still have a bunch of tokens to match, though, because of
252 * possible backing-up.
253 *
254 * When we actually see the EOF, we change the status to "new"
255 * (via expr_yyrestart()), so that the user can continue scanning by
256 * just pointing yyin at a new input file.
257 */
258#define YY_BUFFER_EOF_PENDING 2
259
260 };
261#endif /* !YY_STRUCT_YY_BUFFER_STATE */
262
263/* We provide macros for accessing buffer states in case in the
264 * future we want to put the buffer states in a more general
265 * "scanner state".
266 *
267 * Returns the top of the stack, or NULL.
268 */
269#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
270 ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
271 : NULL)
272
273/* Same as previous macro, but useful when we know that the buffer stack is not
274 * NULL or when we need an lvalue. For internal use only.
275 */
276#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
277
278void expr_yyrestart (FILE *input_file ,yyscan_t yyscanner );
279void expr_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
280YY_BUFFER_STATE expr_yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner );
281void expr_yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
282void expr_yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner );
283void expr_yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner );
284void expr_yypop_buffer_state (yyscan_t yyscanner );
285
286static void expr_yyensure_buffer_stack (yyscan_t yyscanner );
287static void expr_yy_load_buffer_state (yyscan_t yyscanner );
288static void expr_yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner );
289
290#define YY_FLUSH_BUFFER expr_yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner)
291
292YY_BUFFER_STATE expr_yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner );
293YY_BUFFER_STATE expr_yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner );
294YY_BUFFER_STATE expr_yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner );
295
296void *expr_yyalloc (yy_size_t ,yyscan_t yyscanner );
297void *expr_yyrealloc (void *,yy_size_t ,yyscan_t yyscanner );
298void expr_yyfree (void * ,yyscan_t yyscanner );
299
300#define yy_new_buffer expr_yy_create_buffer
301
302#define yy_set_interactive(is_interactive) \
303 { \
304 if ( ! YY_CURRENT_BUFFER ){ \
305 expr_yyensure_buffer_stack (yyscanner); \
306 YY_CURRENT_BUFFER_LVALUE = \
307 expr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
308 } \
309 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
310 }
311
312#define yy_set_bol(at_bol) \
313 { \
314 if ( ! YY_CURRENT_BUFFER ){\
315 expr_yyensure_buffer_stack (yyscanner); \
316 YY_CURRENT_BUFFER_LVALUE = \
317 expr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \
318 } \
319 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
320 }
321
322#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
323
324/* Begin user sect3 */
325
326#define expr_yywrap(yyscanner) (/*CONSTCOND*/1)
327#define YY_SKIP_YYWRAP
328
329typedef unsigned char YY_CHAR;
330
331typedef int yy_state_type;
332
333#define yytext_ptr yytext_r
334
335static yy_state_type yy_get_previous_state (yyscan_t yyscanner );
336static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner);
337static int yy_get_next_buffer (yyscan_t yyscanner );
338static void yynoreturn yy_fatal_error (yyconst char* msg ,yyscan_t yyscanner );
339
340/* Done after the current pattern has been matched and before the
341 * corresponding action - sets up yytext.
342 */
343#define YY_DO_BEFORE_ACTION \
344 yyg->yytext_ptr = yy_bp; \
345 yyleng = (int) (yy_cp - yy_bp); \
346 yyg->yy_hold_char = *yy_cp; \
347 *yy_cp = '\0'; \
348 yyg->yy_c_buf_p = yy_cp;
349
350#define YY_NUM_RULES 51
351#define YY_END_OF_BUFFER 52
352/* This struct is not used in this scanner,
353 but its presence is necessary. */
354struct yy_trans_info
355 {
356 flex_int32_t yy_verify;
357 flex_int32_t yy_nxt;
358 };
359static yyconst flex_int16_t yy_accept[129] =
360 { 0,
361 0, 0, 0, 0, 52, 1, 3, 5, 1, 50,
362 47, 49, 50, 22, 10, 21, 24, 25, 8, 6,
363 26, 7, 50, 9, 43, 43, 50, 18, 11, 19,
364 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
365 50, 20, 23, 1, 1, 3, 4, 0, 47, 13,
366 45, 44, 43, 0, 43, 38, 16, 14, 12, 15,
367 17, 46, 46, 46, 46, 46, 46, 30, 46, 46,
368 28, 46, 46, 46, 48, 0, 2, 0, 0, 44,
369 0, 44, 43, 27, 46, 46, 37, 46, 46, 29,
370 46, 46, 46, 46, 0, 45, 43, 33, 36, 46,
371
372 46, 46, 39, 35, 40, 34, 43, 41, 46, 46,
373 43, 31, 46, 43, 32, 43, 43, 43, 43, 43,
374 43, 43, 43, 43, 43, 43, 42, 0
375 } ;
376
377static yyconst YY_CHAR yy_ec[256] =
378 { 0,
379 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
380 2, 2, 4, 1, 1, 1, 1, 1, 1, 1,
381 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
382 1, 2, 5, 1, 6, 1, 7, 8, 1, 9,
383 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
384 20, 21, 22, 23, 24, 25, 26, 27, 1, 28,
385 29, 30, 1, 1, 31, 32, 33, 34, 35, 36,
386 32, 37, 38, 32, 32, 39, 32, 40, 41, 32,
387 32, 42, 43, 44, 45, 32, 46, 32, 32, 32,
388 1, 47, 1, 1, 32, 1, 31, 32, 33, 34,
389
390 35, 36, 32, 37, 38, 32, 32, 39, 32, 40,
391 41, 32, 32, 42, 43, 44, 45, 32, 46, 32,
392 32, 32, 1, 48, 1, 49, 1, 32, 32, 32,
393 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
394 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
395 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
396 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
397 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
398 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
399 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
400
401 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
402 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
403 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
404 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
405 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
406 32, 32, 32, 32, 32
407 } ;
408
409static yyconst YY_CHAR yy_meta[50] =
410 { 0,
411 1, 2, 2, 2, 1, 1, 1, 1, 1, 1,
412 1, 3, 1, 3, 4, 1, 5, 5, 5, 5,
413 5, 5, 5, 5, 5, 5, 1, 1, 1, 1,
414 6, 6, 6, 6, 7, 6, 6, 6, 6, 6,
415 6, 6, 6, 6, 6, 6, 1, 1, 1
416 } ;
417
418static yyconst flex_uint16_t yy_base[138] =
419 { 0,
420 0, 3, 50, 0, 204, 156, 6, 205, 97, 205,
421 7, 205, 173, 205, 205, 205, 205, 205, 205, 205,
422 205, 205, 0, 205, 0, 1, 0, 0, 205, 2,
423 161, 0, 169, 0, 168, 155, 0, 155, 0, 159,
424 9, 205, 205, 148, 99, 15, 205, 191, 19, 205,
425 158, 157, 172, 10, 171, 0, 205, 205, 205, 205,
426 205, 0, 155, 145, 144, 152, 146, 144, 139, 143,
427 0, 146, 135, 143, 205, 172, 205, 169, 13, 128,
428 32, 0, 14, 0, 120, 110, 0, 100, 97, 101,
429 101, 99, 103, 97, 92, 0, 29, 0, 0, 101,
430
431 95, 88, 0, 0, 0, 0, 19, 0, 93, 92,
432 103, 0, 74, 88, 0, 89, 91, 92, 93, 97,
433 100, 101, 104, 102, 111, 110, 7, 205, 146, 153,
434 9, 157, 160, 163, 166, 171, 174
435 } ;
436
437static yyconst flex_int16_t yy_def[138] =
438 { 0,
439 129, 129, 128, 3, 128, 130, 128, 128, 130, 128,
440 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
441 128, 128, 131, 128, 132, 132, 133, 128, 128, 128,
442 134, 134, 134, 134, 134, 134, 134, 134, 134, 134,
443 128, 128, 128, 130, 130, 128, 128, 128, 128, 128,
444 131, 135, 26, 136, 26, 133, 128, 128, 128, 128,
445 128, 134, 134, 134, 134, 134, 134, 134, 134, 134,
446 134, 134, 134, 134, 128, 128, 128, 128, 137, 135,
447 136, 81, 26, 134, 134, 134, 134, 134, 134, 134,
448 134, 134, 134, 134, 137, 95, 26, 134, 134, 134,
449
450 134, 134, 134, 134, 134, 134, 26, 134, 134, 134,
451 26, 134, 134, 26, 134, 26, 26, 26, 26, 26,
452 26, 26, 26, 26, 26, 26, 26, 0, 128, 128,
453 128, 128, 128, 128, 128, 128, 128
454 } ;
455
456static yyconst flex_uint16_t yy_nxt[255] =
457 { 0,
458 128, 7, 8, 7, 7, 8, 7, 46, 49, 46,
459 49, 75, 76, 51, 52, 52, 46, 128, 46, 55,
460 49, 81, 49, 81, 95, 53, 95, 57, 58, 59,
461 60, 61, 53, 97, 54, 54, 72, 53, 65, 66,
462 69, 73, 111, 128, 70, 128, 9, 53, 107, 9,
463 10, 11, 12, 11, 13, 14, 15, 16, 17, 18,
464 19, 20, 21, 22, 23, 24, 25, 25, 25, 25,
465 25, 25, 25, 25, 25, 26, 27, 28, 29, 30,
466 31, 32, 33, 32, 34, 35, 32, 36, 32, 37,
467 38, 32, 32, 39, 32, 40, 41, 42, 43, 47,
468
469 48, 77, 78, 128, 116, 128, 53, 53, 117, 53,
470 53, 53, 115, 118, 120, 53, 119, 121, 53, 53,
471 53, 114, 53, 122, 123, 124, 125, 126, 53, 53,
472 113, 112, 110, 109, 127, 108, 106, 105, 104, 103,
473 102, 101, 100, 45, 99, 45, 6, 6, 6, 6,
474 6, 6, 6, 44, 98, 44, 44, 44, 44, 44,
475 53, 53, 54, 53, 56, 56, 56, 62, 62, 62,
476 80, 77, 80, 82, 75, 82, 96, 94, 96, 93,
477 92, 91, 90, 89, 88, 87, 86, 85, 84, 83,
478 53, 54, 79, 47, 45, 74, 71, 68, 67, 64,
479
480 63, 50, 45, 128, 5, 128, 128, 128, 128, 128,
481 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
482 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
483 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
484 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
485 128, 128, 128, 128
486 } ;
487
488static yyconst flex_int16_t yy_chk[255] =
489 { 0,
490 0, 1, 1, 1, 2, 2, 2, 7, 11, 7,
491 11, 41, 41, 131, 25, 26, 46, 0, 46, 26,
492 49, 54, 49, 54, 79, 127, 79, 28, 28, 28,
493 30, 30, 83, 83, 25, 26, 39, 107, 34, 34,
494 37, 39, 107, 81, 37, 81, 1, 97, 97, 2,
495 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
496 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
497 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
498 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
499 3, 3, 3, 3, 3, 3, 3, 3, 3, 9,
500
501 9, 45, 45, 95, 114, 95, 114, 116, 116, 117,
502 118, 119, 113, 117, 119, 120, 118, 120, 121, 122,
503 124, 111, 123, 121, 122, 123, 124, 125, 126, 125,
504 110, 109, 102, 101, 126, 100, 94, 93, 92, 91,
505 90, 89, 88, 9, 86, 45, 129, 129, 129, 129,
506 129, 129, 129, 130, 85, 130, 130, 130, 130, 130,
507 132, 132, 80, 132, 133, 133, 133, 134, 134, 134,
508 135, 78, 135, 136, 76, 136, 137, 74, 137, 73,
509 72, 70, 69, 68, 67, 66, 65, 64, 63, 55,
510 53, 52, 51, 48, 44, 40, 38, 36, 35, 33,
511
512 31, 13, 6, 5, 128, 128, 128, 128, 128, 128,
513 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
514 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
515 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
516 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
517 128, 128, 128, 128
518 } ;
519
520/* The intent behind this definition is that it'll catch
521 * any uses of REJECT which flex missed.
522 */
523#define REJECT reject_used_but_not_detected
524#define yymore() yymore_used_but_not_detected
525#define YY_MORE_ADJ 0
526#define YY_RESTORE_YY_MORE_OFFSET
527#line 1 "exprscan.l"
528#line 2 "exprscan.l"
529/*-------------------------------------------------------------------------
530 *
531 * exprscan.l
532 * lexical scanner for pgbench backslash commands
533 *
534 * This lexer supports two operating modes:
535 *
536 * In INITIAL state, just parse off whitespace-separated words (this mode
537 * is basically equivalent to strtok(), which is what we used to use).
538 *
539 * In EXPR state, lex for the simple expression syntax of exprparse.y.
540 *
541 * In either mode, stop upon hitting newline or end of string.
542 *
543 * Note that this lexer operates within the framework created by psqlscan.l,
544 *
545 * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
546 * Portions Copyright (c) 1994, Regents of the University of California
547 *
548 * src/bin/pgbench/exprscan.l
549 *
550 *-------------------------------------------------------------------------
551 */
552
553#include "fe_utils/psqlscan_int.h"
554
555/* context information for reporting errors in expressions */
556static const char *expr_source = NULL;
557static int expr_lineno = 0;
558static int expr_start_offset = 0;
559static const char *expr_command = NULL;
560
561/* indicates whether last expr_yylex() call read a newline */
562static bool last_was_newline = false;
563
564/*
565 * Work around a bug in flex 2.5.35: it emits a couple of functions that
566 * it forgets to emit declarations for. Since we use -Wmissing-prototypes,
567 * this would cause warnings. Providing our own declarations should be
568 * harmless even when the bug gets fixed.
569 */
570extern int expr_yyget_column(yyscan_t yyscanner);
571extern void expr_yyset_column(int column_no, yyscan_t yyscanner);
572
573/* LCOV_EXCL_START */
574
575/* Except for the prefix, these options should match psqlscan.l */
576#define YY_NO_INPUT 1
577/* Character classes */
578/* {space} + {nonspace} + {newline} should cover all characters */
579/* Line continuation marker */
580/* case insensitive keywords */
581/* Exclusive states */
582
583#line 584 "exprscan.c"
584
585#define INITIAL 0
586#define EXPR 1
587
588#ifndef YY_NO_UNISTD_H
589/* Special case for "unistd.h", since it is non-ANSI. We include it way
590 * down here because we want the user's section 1 to have been scanned first.
591 * The user has a chance to override it with an option.
592 */
593#include <unistd.h>
594#endif
595
596#ifndef YY_EXTRA_TYPE
597#define YY_EXTRA_TYPE void *
598#endif
599
600/* Holds the entire state of the reentrant scanner. */
601struct yyguts_t
602 {
603
604 /* User-defined. Not touched by flex. */
605 YY_EXTRA_TYPE yyextra_r;
606
607 /* The rest are the same as the globals declared in the non-reentrant scanner. */
608 FILE *yyin_r, *yyout_r;
609 size_t yy_buffer_stack_top; /**< index of top of stack. */
610 size_t yy_buffer_stack_max; /**< capacity of stack. */
611 YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
612 char yy_hold_char;
613 int yy_n_chars;
614 int yyleng_r;
615 char *yy_c_buf_p;
616 int yy_init;
617 int yy_start;
618 int yy_did_buffer_switch_on_eof;
619 int yy_start_stack_ptr;
620 int yy_start_stack_depth;
621 int *yy_start_stack;
622 yy_state_type yy_last_accepting_state;
623 char* yy_last_accepting_cpos;
624
625 int yylineno_r;
626 int yy_flex_debug_r;
627
628 char *yytext_r;
629 int yy_more_flag;
630 int yy_more_len;
631
632 YYSTYPE * yylval_r;
633
634 }; /* end struct yyguts_t */
635
636static int yy_init_globals (yyscan_t yyscanner );
637
638 /* This must go here because YYSTYPE and YYLTYPE are included
639 * from bison output in section 1.*/
640 # define yylval yyg->yylval_r
641
642int expr_yylex_init (yyscan_t* scanner);
643
644int expr_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
645
646/* Accessor methods to globals.
647 These are made visible to non-reentrant scanners for convenience. */
648
649int expr_yylex_destroy (yyscan_t yyscanner );
650
651int expr_yyget_debug (yyscan_t yyscanner );
652
653void expr_yyset_debug (int debug_flag ,yyscan_t yyscanner );
654
655YY_EXTRA_TYPE expr_yyget_extra (yyscan_t yyscanner );
656
657void expr_yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner );
658
659FILE *expr_yyget_in (yyscan_t yyscanner );
660
661void expr_yyset_in (FILE * _in_str ,yyscan_t yyscanner );
662
663FILE *expr_yyget_out (yyscan_t yyscanner );
664
665void expr_yyset_out (FILE * _out_str ,yyscan_t yyscanner );
666
667 int expr_yyget_leng (yyscan_t yyscanner );
668
669char *expr_yyget_text (yyscan_t yyscanner );
670
671int expr_yyget_lineno (yyscan_t yyscanner );
672
673void expr_yyset_lineno (int _line_number ,yyscan_t yyscanner );
674
675int expr_yyget_column (yyscan_t yyscanner );
676
677void expr_yyset_column (int _column_no ,yyscan_t yyscanner );
678
679YYSTYPE * expr_yyget_lval (yyscan_t yyscanner );
680
681void expr_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
682
683/* Macros after this point can all be overridden by user definitions in
684 * section 1.
685 */
686
687#ifndef YY_SKIP_YYWRAP
688#ifdef __cplusplus
689extern "C" int expr_yywrap (yyscan_t yyscanner );
690#else
691extern int expr_yywrap (yyscan_t yyscanner );
692#endif
693#endif
694
695#ifndef YY_NO_UNPUT
696
697#endif
698
699#ifndef yytext_ptr
700static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
701#endif
702
703#ifdef YY_NEED_STRLEN
704static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner);
705#endif
706
707#ifndef YY_NO_INPUT
708
709#ifdef __cplusplus
710static int yyinput (yyscan_t yyscanner );
711#else
712static int input (yyscan_t yyscanner );
713#endif
714
715#endif
716
717/* Amount of stuff to slurp up with each read. */
718#ifndef YY_READ_BUF_SIZE
719#ifdef __ia64__
720/* On IA-64, the buffer size is 16k, not 8k */
721#define YY_READ_BUF_SIZE 16384
722#else
723#define YY_READ_BUF_SIZE 8192
724#endif /* __ia64__ */
725#endif
726
727/* Copy whatever the last rule matched to the standard output. */
728#ifndef ECHO
729/* This used to be an fputs(), but since the string might contain NUL's,
730 * we now use fwrite().
731 */
732#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
733#endif
734
735/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
736 * is returned in "result".
737 */
738#ifndef YY_INPUT
739#define YY_INPUT(buf,result,max_size) \
740 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
741 { \
742 int c = '*'; \
743 size_t n; \
744 for ( n = 0; n < max_size && \
745 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
746 buf[n] = (char) c; \
747 if ( c == '\n' ) \
748 buf[n++] = (char) c; \
749 if ( c == EOF && ferror( yyin ) ) \
750 YY_FATAL_ERROR( "input in flex scanner failed" ); \
751 result = n; \
752 } \
753 else \
754 { \
755 errno=0; \
756 while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
757 { \
758 if( errno != EINTR) \
759 { \
760 YY_FATAL_ERROR( "input in flex scanner failed" ); \
761 break; \
762 } \
763 errno=0; \
764 clearerr(yyin); \
765 } \
766 }\
767\
768
769#endif
770
771/* No semi-colon after return; correct usage is to write "yyterminate();" -
772 * we don't want an extra ';' after the "return" because that will cause
773 * some compilers to complain about unreachable statements.
774 */
775#ifndef yyterminate
776#define yyterminate() return YY_NULL
777#endif
778
779/* Number of entries by which start-condition stack grows. */
780#ifndef YY_START_STACK_INCR
781#define YY_START_STACK_INCR 25
782#endif
783
784/* Report a fatal error. */
785#ifndef YY_FATAL_ERROR
786#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
787#endif
788
789/* end tables serialization structures and prototypes */
790
791/* Default declaration of generated scanner - a define so the user can
792 * easily add parameters.
793 */
794#ifndef YY_DECL
795#define YY_DECL_IS_OURS 1
796
797extern int expr_yylex \
798 (YYSTYPE * yylval_param ,yyscan_t yyscanner);
799
800#define YY_DECL int expr_yylex \
801 (YYSTYPE * yylval_param , yyscan_t yyscanner)
802#endif /* !YY_DECL */
803
804/* Code executed at the beginning of each rule, after yytext and yyleng
805 * have been set up.
806 */
807#ifndef YY_USER_ACTION
808#define YY_USER_ACTION
809#endif
810
811/* Code executed at the end of each rule. */
812#ifndef YY_BREAK
813#define YY_BREAK /*LINTED*/break;
814#endif
815
816#define YY_RULE_SETUP \
817 YY_USER_ACTION
818
819/** The main scanner function which does all the work.
820 */
821YY_DECL
822{
823 yy_state_type yy_current_state;
824 char *yy_cp, *yy_bp;
825 int yy_act;
826 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
827
828 yylval = yylval_param;
829
830 if ( !yyg->yy_init )
831 {
832 yyg->yy_init = 1;
833
834#ifdef YY_USER_INIT
835 YY_USER_INIT;
836#endif
837
838 if ( ! yyg->yy_start )
839 yyg->yy_start = 1; /* first start state */
840
841 if ( ! yyin )
842 yyin = stdin;
843
844 if ( ! yyout )
845 yyout = stdout;
846
847 if ( ! YY_CURRENT_BUFFER ) {
848 expr_yyensure_buffer_stack (yyscanner);
849 YY_CURRENT_BUFFER_LVALUE =
850 expr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
851 }
852
853 expr_yy_load_buffer_state(yyscanner );
854 }
855
856 {
857#line 93 "exprscan.l"
858
859
860
861 /* Declare some local variables inside expr_yylex(), for convenience */
862 PsqlScanState cur_state = yyextra;
863
864 /*
865 * Force flex into the state indicated by start_state. This has a
866 * couple of purposes: it lets some of the functions below set a new
867 * starting state without ugly direct access to flex variables, and it
868 * allows us to transition from one flex lexer to another so that we
869 * can lex different parts of the source string using separate lexers.
870 */
871 BEGIN(cur_state->start_state);
872
873 /* Reset was-newline flag */
874 last_was_newline = false;
875
876
877 /* INITIAL state */
878
879#line 880 "exprscan.c"
880
881 while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
882 {
883 yy_cp = yyg->yy_c_buf_p;
884
885 /* Support of yytext. */
886 *yy_cp = yyg->yy_hold_char;
887
888 /* yy_bp points to the position in yy_ch_buf of the start of
889 * the current run.
890 */
891 yy_bp = yy_cp;
892
893 yy_current_state = yyg->yy_start;
894yy_match:
895 do
896 {
897 YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
898 if ( yy_accept[yy_current_state] )
899 {
900 yyg->yy_last_accepting_state = yy_current_state;
901 yyg->yy_last_accepting_cpos = yy_cp;
902 }
903 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
904 {
905 yy_current_state = (int) yy_def[yy_current_state];
906 if ( yy_current_state >= 129 )
907 yy_c = yy_meta[(unsigned int) yy_c];
908 }
909 yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
910 ++yy_cp;
911 }
912 while ( yy_current_state != 128 );
913 yy_cp = yyg->yy_last_accepting_cpos;
914 yy_current_state = yyg->yy_last_accepting_state;
915
916yy_find_action:
917 yy_act = yy_accept[yy_current_state];
918
919 YY_DO_BEFORE_ACTION;
920
921do_action: /* This label is used only to access EOF actions. */
922
923 switch ( yy_act )
924 { /* beginning of action switch */
925 case 0: /* must back up */
926 /* undo the effects of YY_DO_BEFORE_ACTION */
927 *yy_cp = yyg->yy_hold_char;
928 yy_cp = yyg->yy_last_accepting_cpos;
929 yy_current_state = yyg->yy_last_accepting_state;
930 goto yy_find_action;
931
932case 1:
933YY_RULE_SETUP
934#line 114 "exprscan.l"
935{
936 /* Found a word, emit and return it */
937 psqlscan_emit(cur_state, yytext, yyleng);
938 return 1;
939 }
940 YY_BREAK
941/*
942 * We need this rule to avoid returning "word\" instead of recognizing
943 * a continuation marker just after a word:
944 */
945case 2:
946/* rule 2 can match eol */
947YY_RULE_SETUP
948#line 124 "exprscan.l"
949{
950 /* Found "word\\\r?\n", emit and return just "word" */
951 int wordlen = yyleng - 2;
952 if (yytext[wordlen] == '\r')
953 wordlen--;
954 Assert(yytext[wordlen] == '\\');
955 psqlscan_emit(cur_state, yytext, wordlen);
956 return 1;
957 }
958 YY_BREAK
959case 3:
960YY_RULE_SETUP
961#line 134 "exprscan.l"
962{ /* ignore */ }
963 YY_BREAK
964case 4:
965/* rule 4 can match eol */
966YY_RULE_SETUP
967#line 136 "exprscan.l"
968{ /* ignore */ }
969 YY_BREAK
970case 5:
971/* rule 5 can match eol */
972YY_RULE_SETUP
973#line 138 "exprscan.l"
974{
975 /* report end of command */
976 last_was_newline = true;
977 return 0;
978 }
979 YY_BREAK
980/* EXPR state */
981
982case 6:
983YY_RULE_SETUP
984#line 148 "exprscan.l"
985{ return '+'; }
986 YY_BREAK
987case 7:
988YY_RULE_SETUP
989#line 149 "exprscan.l"
990{ return '-'; }
991 YY_BREAK
992case 8:
993YY_RULE_SETUP
994#line 150 "exprscan.l"
995{ return '*'; }
996 YY_BREAK
997case 9:
998YY_RULE_SETUP
999#line 151 "exprscan.l"
1000{ return '/'; }
1001 YY_BREAK
1002case 10:
1003YY_RULE_SETUP
1004#line 152 "exprscan.l"
1005{ return '%'; } /* C version, also in Pg SQL */
1006 YY_BREAK
1007case 11:
1008YY_RULE_SETUP
1009#line 153 "exprscan.l"
1010{ return '='; }
1011 YY_BREAK
1012case 12:
1013YY_RULE_SETUP
1014#line 154 "exprscan.l"
1015{ return NE_OP; }
1016 YY_BREAK
1017case 13:
1018YY_RULE_SETUP
1019#line 155 "exprscan.l"
1020{ return NE_OP; } /* C version, also in Pg SQL */
1021 YY_BREAK
1022case 14:
1023YY_RULE_SETUP
1024#line 156 "exprscan.l"
1025{ return LE_OP; }
1026 YY_BREAK
1027case 15:
1028YY_RULE_SETUP
1029#line 157 "exprscan.l"
1030{ return GE_OP; }
1031 YY_BREAK
1032case 16:
1033YY_RULE_SETUP
1034#line 158 "exprscan.l"
1035{ return LS_OP; }
1036 YY_BREAK
1037case 17:
1038YY_RULE_SETUP
1039#line 159 "exprscan.l"
1040{ return RS_OP; }
1041 YY_BREAK
1042case 18:
1043YY_RULE_SETUP
1044#line 160 "exprscan.l"
1045{ return '<'; }
1046 YY_BREAK
1047case 19:
1048YY_RULE_SETUP
1049#line 161 "exprscan.l"
1050{ return '>'; }
1051 YY_BREAK
1052case 20:
1053YY_RULE_SETUP
1054#line 162 "exprscan.l"
1055{ return '|'; }
1056 YY_BREAK
1057case 21:
1058YY_RULE_SETUP
1059#line 163 "exprscan.l"
1060{ return '&'; }
1061 YY_BREAK
1062case 22:
1063YY_RULE_SETUP
1064#line 164 "exprscan.l"
1065{ return '#'; }
1066 YY_BREAK
1067case 23:
1068YY_RULE_SETUP
1069#line 165 "exprscan.l"
1070{ return '~'; }
1071 YY_BREAK
1072case 24:
1073YY_RULE_SETUP
1074#line 167 "exprscan.l"
1075{ return '('; }
1076 YY_BREAK
1077case 25:
1078YY_RULE_SETUP
1079#line 168 "exprscan.l"
1080{ return ')'; }
1081 YY_BREAK
1082case 26:
1083YY_RULE_SETUP
1084#line 169 "exprscan.l"
1085{ return ','; }
1086 YY_BREAK
1087case 27:
1088YY_RULE_SETUP
1089#line 171 "exprscan.l"
1090{ return AND_OP; }
1091 YY_BREAK
1092case 28:
1093YY_RULE_SETUP
1094#line 172 "exprscan.l"
1095{ return OR_OP; }
1096 YY_BREAK
1097case 29:
1098YY_RULE_SETUP
1099#line 173 "exprscan.l"
1100{ return NOT_OP; }
1101 YY_BREAK
1102case 30:
1103YY_RULE_SETUP
1104#line 174 "exprscan.l"
1105{ return IS_OP; }
1106 YY_BREAK
1107case 31:
1108YY_RULE_SETUP
1109#line 175 "exprscan.l"
1110{ return ISNULL_OP; }
1111 YY_BREAK
1112case 32:
1113YY_RULE_SETUP
1114#line 176 "exprscan.l"
1115{ return NOTNULL_OP; }
1116 YY_BREAK
1117case 33:
1118YY_RULE_SETUP
1119#line 178 "exprscan.l"
1120{ return CASE_KW; }
1121 YY_BREAK
1122case 34:
1123YY_RULE_SETUP
1124#line 179 "exprscan.l"
1125{ return WHEN_KW; }
1126 YY_BREAK
1127case 35:
1128YY_RULE_SETUP
1129#line 180 "exprscan.l"
1130{ return THEN_KW; }
1131 YY_BREAK
1132case 36:
1133YY_RULE_SETUP
1134#line 181 "exprscan.l"
1135{ return ELSE_KW; }
1136 YY_BREAK
1137case 37:
1138YY_RULE_SETUP
1139#line 182 "exprscan.l"
1140{ return END_KW; }
1141 YY_BREAK
1142case 38:
1143YY_RULE_SETUP
1144#line 184 "exprscan.l"
1145{
1146 yylval->str = pg_strdup(yytext + 1);
1147 return VARIABLE;
1148 }
1149 YY_BREAK
1150case 39:
1151YY_RULE_SETUP
1152#line 189 "exprscan.l"
1153{ return NULL_CONST; }
1154 YY_BREAK
1155case 40:
1156YY_RULE_SETUP
1157#line 190 "exprscan.l"
1158{
1159 yylval->bval = true;
1160 return BOOLEAN_CONST;
1161 }
1162 YY_BREAK
1163case 41:
1164YY_RULE_SETUP
1165#line 194 "exprscan.l"
1166{
1167 yylval->bval = false;
1168 return BOOLEAN_CONST;
1169 }
1170 YY_BREAK
1171case 42:
1172YY_RULE_SETUP
1173#line 198 "exprscan.l"
1174{
1175 /*
1176 * Special handling for PG_INT64_MIN, which can't
1177 * accurately be represented here, as the minus sign is
1178 * lexed separately and INT64_MIN can't be represented as
1179 * a positive integer.
1180 */
1181 return MAXINT_PLUS_ONE_CONST;
1182 }
1183 YY_BREAK
1184case 43:
1185YY_RULE_SETUP
1186#line 207 "exprscan.l"
1187{
1188 if (!strtoint64(yytext, true, &yylval->ival))
1189 expr_yyerror_more(yyscanner, "bigint constant overflow",
1190 strdup(yytext));
1191 return INTEGER_CONST;
1192 }
1193 YY_BREAK
1194case 44:
1195YY_RULE_SETUP
1196#line 213 "exprscan.l"
1197{
1198 if (!strtodouble(yytext, true, &yylval->dval))
1199 expr_yyerror_more(yyscanner, "double constant overflow",
1200 strdup(yytext));
1201 return DOUBLE_CONST;
1202 }
1203 YY_BREAK
1204case 45:
1205YY_RULE_SETUP
1206#line 219 "exprscan.l"
1207{
1208 if (!strtodouble(yytext, true, &yylval->dval))
1209 expr_yyerror_more(yyscanner, "double constant overflow",
1210 strdup(yytext));
1211 return DOUBLE_CONST;
1212 }
1213 YY_BREAK
1214case 46:
1215YY_RULE_SETUP
1216#line 225 "exprscan.l"
1217{
1218 yylval->str = pg_strdup(yytext);
1219 return FUNCTION;
1220 }
1221 YY_BREAK
1222case 47:
1223YY_RULE_SETUP
1224#line 230 "exprscan.l"
1225{ /* ignore */ }
1226 YY_BREAK
1227case 48:
1228/* rule 48 can match eol */
1229YY_RULE_SETUP
1230#line 232 "exprscan.l"
1231{ /* ignore */ }
1232 YY_BREAK
1233case 49:
1234/* rule 49 can match eol */
1235YY_RULE_SETUP
1236#line 234 "exprscan.l"
1237{
1238 /* report end of command */
1239 last_was_newline = true;
1240 return 0;
1241 }
1242 YY_BREAK
1243case 50:
1244YY_RULE_SETUP
1245#line 240 "exprscan.l"
1246{
1247 /*
1248 * must strdup yytext so that expr_yyerror_more doesn't
1249 * change it while finding end of line
1250 */
1251 expr_yyerror_more(yyscanner, "unexpected character",
1252 pg_strdup(yytext));
1253 /* NOTREACHED, syntax_error calls exit() */
1254 return 0;
1255 }
1256 YY_BREAK
1257
1258case YY_STATE_EOF(INITIAL):
1259case YY_STATE_EOF(EXPR):
1260#line 253 "exprscan.l"
1261{
1262 if (cur_state->buffer_stack == NULL)
1263 return 0; /* end of input reached */
1264
1265 /*
1266 * We were expanding a variable, so pop the inclusion
1267 * stack and keep lexing
1268 */
1269 psqlscan_pop_buffer_stack(cur_state);
1270 psqlscan_select_top_buffer(cur_state);
1271 }
1272 YY_BREAK
1273case 51:
1274YY_RULE_SETUP
1275#line 265 "exprscan.l"
1276YY_FATAL_ERROR( "flex scanner jammed" );
1277 YY_BREAK
1278#line 1279 "exprscan.c"
1279
1280 case YY_END_OF_BUFFER:
1281 {
1282 /* Amount of text matched not including the EOB char. */
1283 int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1284
1285 /* Undo the effects of YY_DO_BEFORE_ACTION. */
1286 *yy_cp = yyg->yy_hold_char;
1287 YY_RESTORE_YY_MORE_OFFSET
1288
1289 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1290 {
1291 /* We're scanning a new file or input source. It's
1292 * possible that this happened because the user
1293 * just pointed yyin at a new source and called
1294 * expr_yylex(). If so, then we have to assure
1295 * consistency between YY_CURRENT_BUFFER and our
1296 * globals. Here is the right place to do so, because
1297 * this is the first action (other than possibly a
1298 * back-up) that will match for the new input source.
1299 */
1300 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1301 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1302 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1303 }
1304
1305 /* Note that here we test for yy_c_buf_p "<=" to the position
1306 * of the first EOB in the buffer, since yy_c_buf_p will
1307 * already have been incremented past the NUL character
1308 * (since all states make transitions on EOB to the
1309 * end-of-buffer state). Contrast this with the test
1310 * in input().
1311 */
1312 if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1313 { /* This was really a NUL. */
1314 yy_state_type yy_next_state;
1315
1316 yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
1317
1318 yy_current_state = yy_get_previous_state( yyscanner );
1319
1320 /* Okay, we're now positioned to make the NUL
1321 * transition. We couldn't have
1322 * yy_get_previous_state() go ahead and do it
1323 * for us because it doesn't know how to deal
1324 * with the possibility of jamming (and we don't
1325 * want to build jamming into it because then it
1326 * will run more slowly).
1327 */
1328
1329 yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
1330
1331 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1332
1333 if ( yy_next_state )
1334 {
1335 /* Consume the NUL. */
1336 yy_cp = ++yyg->yy_c_buf_p;
1337 yy_current_state = yy_next_state;
1338 goto yy_match;
1339 }
1340
1341 else
1342 {
1343 yy_cp = yyg->yy_last_accepting_cpos;
1344 yy_current_state = yyg->yy_last_accepting_state;
1345 goto yy_find_action;
1346 }
1347 }
1348
1349 else switch ( yy_get_next_buffer( yyscanner ) )
1350 {
1351 case EOB_ACT_END_OF_FILE:
1352 {
1353 yyg->yy_did_buffer_switch_on_eof = 0;
1354
1355 if ( expr_yywrap(yyscanner ) )
1356 {
1357 /* Note: because we've taken care in
1358 * yy_get_next_buffer() to have set up
1359 * yytext, we can now set up
1360 * yy_c_buf_p so that if some total
1361 * hoser (like flex itself) wants to
1362 * call the scanner after we return the
1363 * YY_NULL, it'll still work - another
1364 * YY_NULL will get returned.
1365 */
1366 yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1367
1368 yy_act = YY_STATE_EOF(YY_START);
1369 goto do_action;
1370 }
1371
1372 else
1373 {
1374 if ( ! yyg->yy_did_buffer_switch_on_eof )
1375 YY_NEW_FILE;
1376 }
1377 break;
1378 }
1379
1380 case EOB_ACT_CONTINUE_SCAN:
1381 yyg->yy_c_buf_p =
1382 yyg->yytext_ptr + yy_amount_of_matched_text;
1383
1384 yy_current_state = yy_get_previous_state( yyscanner );
1385
1386 yy_cp = yyg->yy_c_buf_p;
1387 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1388 goto yy_match;
1389
1390 case EOB_ACT_LAST_MATCH:
1391 yyg->yy_c_buf_p =
1392 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1393
1394 yy_current_state = yy_get_previous_state( yyscanner );
1395
1396 yy_cp = yyg->yy_c_buf_p;
1397 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1398 goto yy_find_action;
1399 }
1400 break;
1401 }
1402
1403 default:
1404 YY_FATAL_ERROR(
1405 "fatal flex scanner internal error--no action found" );
1406 } /* end of action switch */
1407 } /* end of scanning one token */
1408 } /* end of user's declarations */
1409} /* end of expr_yylex */
1410
1411/* yy_get_next_buffer - try to read in a new buffer
1412 *
1413 * Returns a code representing an action:
1414 * EOB_ACT_LAST_MATCH -
1415 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1416 * EOB_ACT_END_OF_FILE - end of file
1417 */
1418static int yy_get_next_buffer (yyscan_t yyscanner)
1419{
1420 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1421 char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1422 char *source = yyg->yytext_ptr;
1423 int number_to_move, i;
1424 int ret_val;
1425
1426 if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1427 YY_FATAL_ERROR(
1428 "fatal flex scanner internal error--end of buffer missed" );
1429
1430 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1431 { /* Don't try to fill the buffer, so this is an EOF. */
1432 if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1433 {
1434 /* We matched a single character, the EOB, so
1435 * treat this as a final EOF.
1436 */
1437 return EOB_ACT_END_OF_FILE;
1438 }
1439
1440 else
1441 {
1442 /* We matched some text prior to the EOB, first
1443 * process it.
1444 */
1445 return EOB_ACT_LAST_MATCH;
1446 }
1447 }
1448
1449 /* Try to read more data. */
1450
1451 /* First move last chars to start of buffer. */
1452 number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
1453
1454 for ( i = 0; i < number_to_move; ++i )
1455 *(dest++) = *(source++);
1456
1457 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1458 /* don't do the read, it's not guaranteed to return an EOF,
1459 * just force an EOF
1460 */
1461 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
1462
1463 else
1464 {
1465 int num_to_read =
1466 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1467
1468 while ( num_to_read <= 0 )
1469 { /* Not enough room in the buffer - grow it. */
1470
1471 /* just a shorter name for the current buffer */
1472 YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1473
1474 int yy_c_buf_p_offset =
1475 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
1476
1477 if ( b->yy_is_our_buffer )
1478 {
1479 int new_size = b->yy_buf_size * 2;
1480
1481 if ( new_size <= 0 )
1482 b->yy_buf_size += b->yy_buf_size / 8;
1483 else
1484 b->yy_buf_size *= 2;
1485
1486 b->yy_ch_buf = (char *)
1487 /* Include room in for 2 EOB chars. */
1488 expr_yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner );
1489 }
1490 else
1491 /* Can't grow it, we don't own it. */
1492 b->yy_ch_buf = NULL;
1493
1494 if ( ! b->yy_ch_buf )
1495 YY_FATAL_ERROR(
1496 "fatal error - scanner input buffer overflow" );
1497
1498 yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
1499
1500 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1501 number_to_move - 1;
1502
1503 }
1504
1505 if ( num_to_read > YY_READ_BUF_SIZE )
1506 num_to_read = YY_READ_BUF_SIZE;
1507
1508 /* Read in more data. */
1509 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1510 yyg->yy_n_chars, num_to_read );
1511
1512 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1513 }
1514
1515 if ( yyg->yy_n_chars == 0 )
1516 {
1517 if ( number_to_move == YY_MORE_ADJ )
1518 {
1519 ret_val = EOB_ACT_END_OF_FILE;
1520 expr_yyrestart(yyin ,yyscanner);
1521 }
1522
1523 else
1524 {
1525 ret_val = EOB_ACT_LAST_MATCH;
1526 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1527 YY_BUFFER_EOF_PENDING;
1528 }
1529 }
1530
1531 else
1532 ret_val = EOB_ACT_CONTINUE_SCAN;
1533
1534 if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1535 /* Extend the array by 50%, plus the number we really need. */
1536 int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
1537 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) expr_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner );
1538 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1539 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1540 }
1541
1542 yyg->yy_n_chars += number_to_move;
1543 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1544 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1545
1546 yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1547
1548 return ret_val;
1549}
1550
1551/* yy_get_previous_state - get the state just before the EOB char was reached */
1552
1553 static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
1554{
1555 yy_state_type yy_current_state;
1556 char *yy_cp;
1557 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1558
1559 yy_current_state = yyg->yy_start;
1560
1561 for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1562 {
1563 YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1564 if ( yy_accept[yy_current_state] )
1565 {
1566 yyg->yy_last_accepting_state = yy_current_state;
1567 yyg->yy_last_accepting_cpos = yy_cp;
1568 }
1569 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1570 {
1571 yy_current_state = (int) yy_def[yy_current_state];
1572 if ( yy_current_state >= 129 )
1573 yy_c = yy_meta[(unsigned int) yy_c];
1574 }
1575 yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1576 }
1577
1578 return yy_current_state;
1579}
1580
1581/* yy_try_NUL_trans - try to make a transition on the NUL character
1582 *
1583 * synopsis
1584 * next_state = yy_try_NUL_trans( current_state );
1585 */
1586 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
1587{
1588 int yy_is_jam;
1589 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
1590 char *yy_cp = yyg->yy_c_buf_p;
1591
1592 YY_CHAR yy_c = 1;
1593 if ( yy_accept[yy_current_state] )
1594 {
1595 yyg->yy_last_accepting_state = yy_current_state;
1596 yyg->yy_last_accepting_cpos = yy_cp;
1597 }
1598 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1599 {
1600 yy_current_state = (int) yy_def[yy_current_state];
1601 if ( yy_current_state >= 129 )
1602 yy_c = yy_meta[(unsigned int) yy_c];
1603 }
1604 yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];
1605 yy_is_jam = (yy_current_state == 128);
1606
1607 (void)yyg;
1608 return yy_is_jam ? 0 : yy_current_state;
1609}
1610
1611#ifndef YY_NO_UNPUT
1612
1613#endif
1614
1615#ifndef YY_NO_INPUT
1616#ifdef __cplusplus
1617 static int yyinput (yyscan_t yyscanner)
1618#else
1619 static int input (yyscan_t yyscanner)
1620#endif
1621
1622{
1623 int c;
1624 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1625
1626 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1627
1628 if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1629 {
1630 /* yy_c_buf_p now points to the character we want to return.
1631 * If this occurs *before* the EOB characters, then it's a
1632 * valid NUL; if not, then we've hit the end of the buffer.
1633 */
1634 if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1635 /* This was really a NUL. */
1636 *yyg->yy_c_buf_p = '\0';
1637
1638 else
1639 { /* need more input */
1640 int offset = yyg->yy_c_buf_p - yyg->yytext_ptr;
1641 ++yyg->yy_c_buf_p;
1642
1643 switch ( yy_get_next_buffer( yyscanner ) )
1644 {
1645 case EOB_ACT_LAST_MATCH:
1646 /* This happens because yy_g_n_b()
1647 * sees that we've accumulated a
1648 * token and flags that we need to
1649 * try matching the token before
1650 * proceeding. But for input(),
1651 * there's no matching to consider.
1652 * So convert the EOB_ACT_LAST_MATCH
1653 * to EOB_ACT_END_OF_FILE.
1654 */
1655
1656 /* Reset buffer status. */
1657 expr_yyrestart(yyin ,yyscanner);
1658
1659 /*FALLTHROUGH*/
1660
1661 case EOB_ACT_END_OF_FILE:
1662 {
1663 if ( expr_yywrap(yyscanner ) )
1664 return 0;
1665
1666 if ( ! yyg->yy_did_buffer_switch_on_eof )
1667 YY_NEW_FILE;
1668#ifdef __cplusplus
1669 return yyinput(yyscanner);
1670#else
1671 return input(yyscanner);
1672#endif
1673 }
1674
1675 case EOB_ACT_CONTINUE_SCAN:
1676 yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
1677 break;
1678 }
1679 }
1680 }
1681
1682 c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
1683 *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
1684 yyg->yy_hold_char = *++yyg->yy_c_buf_p;
1685
1686 return c;
1687}
1688#endif /* ifndef YY_NO_INPUT */
1689
1690/** Immediately switch to a different input stream.
1691 * @param input_file A readable stream.
1692 * @param yyscanner The scanner object.
1693 * @note This function does not reset the start condition to @c INITIAL .
1694 */
1695 void expr_yyrestart (FILE * input_file , yyscan_t yyscanner)
1696{
1697 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1698
1699 if ( ! YY_CURRENT_BUFFER ){
1700 expr_yyensure_buffer_stack (yyscanner);
1701 YY_CURRENT_BUFFER_LVALUE =
1702 expr_yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner);
1703 }
1704
1705 expr_yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner);
1706 expr_yy_load_buffer_state(yyscanner );
1707}
1708
1709/** Switch to a different input buffer.
1710 * @param new_buffer The new input buffer.
1711 * @param yyscanner The scanner object.
1712 */
1713 void expr_yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1714{
1715 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1716
1717 /* TODO. We should be able to replace this entire function body
1718 * with
1719 * expr_yypop_buffer_state();
1720 * expr_yypush_buffer_state(new_buffer);
1721 */
1722 expr_yyensure_buffer_stack (yyscanner);
1723 if ( YY_CURRENT_BUFFER == new_buffer )
1724 return;
1725
1726 if ( YY_CURRENT_BUFFER )
1727 {
1728 /* Flush out information for old buffer. */
1729 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1730 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1731 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1732 }
1733
1734 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1735 expr_yy_load_buffer_state(yyscanner );
1736
1737 /* We don't actually know whether we did this switch during
1738 * EOF (expr_yywrap()) processing, but the only time this flag
1739 * is looked at is after expr_yywrap() is called, so it's safe
1740 * to go ahead and always set it.
1741 */
1742 yyg->yy_did_buffer_switch_on_eof = 1;
1743}
1744
1745static void expr_yy_load_buffer_state (yyscan_t yyscanner)
1746{
1747 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1748 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1749 yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1750 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1751 yyg->yy_hold_char = *yyg->yy_c_buf_p;
1752}
1753
1754/** Allocate and initialize an input buffer state.
1755 * @param file A readable stream.
1756 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1757 * @param yyscanner The scanner object.
1758 * @return the allocated buffer state.
1759 */
1760 YY_BUFFER_STATE expr_yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
1761{
1762 YY_BUFFER_STATE b;
1763
1764 b = (YY_BUFFER_STATE) expr_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
1765 if ( ! b )
1766 YY_FATAL_ERROR( "out of dynamic memory in expr_yy_create_buffer()" );
1767
1768 b->yy_buf_size = (yy_size_t)size;
1769
1770 /* yy_ch_buf has to be 2 characters longer than the size given because
1771 * we need to put in 2 end-of-buffer characters.
1772 */
1773 b->yy_ch_buf = (char *) expr_yyalloc(b->yy_buf_size + 2 ,yyscanner );
1774 if ( ! b->yy_ch_buf )
1775 YY_FATAL_ERROR( "out of dynamic memory in expr_yy_create_buffer()" );
1776
1777 b->yy_is_our_buffer = 1;
1778
1779 expr_yy_init_buffer(b,file ,yyscanner);
1780
1781 return b;
1782}
1783
1784/** Destroy the buffer.
1785 * @param b a buffer created with expr_yy_create_buffer()
1786 * @param yyscanner The scanner object.
1787 */
1788 void expr_yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1789{
1790 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1791
1792 if ( ! b )
1793 return;
1794
1795 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1796 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1797
1798 if ( b->yy_is_our_buffer )
1799 expr_yyfree((void *) b->yy_ch_buf ,yyscanner );
1800
1801 expr_yyfree((void *) b ,yyscanner );
1802}
1803
1804/* Initializes or reinitializes a buffer.
1805 * This function is sometimes called more than once on the same buffer,
1806 * such as during a expr_yyrestart() or at EOF.
1807 */
1808 static void expr_yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
1809
1810{
1811 int oerrno = errno;
1812 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1813
1814 expr_yy_flush_buffer(b ,yyscanner);
1815
1816 b->yy_input_file = file;
1817 b->yy_fill_buffer = 1;
1818
1819 /* If b is the current buffer, then expr_yy_init_buffer was _probably_
1820 * called from expr_yyrestart() or through yy_get_next_buffer.
1821 * In that case, we don't want to reset the lineno or column.
1822 */
1823 if (b != YY_CURRENT_BUFFER){
1824 b->yy_bs_lineno = 1;
1825 b->yy_bs_column = 0;
1826 }
1827
1828 b->yy_is_interactive = 0;
1829
1830 errno = oerrno;
1831}
1832
1833/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1834 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1835 * @param yyscanner The scanner object.
1836 */
1837 void expr_yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
1838{
1839 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1840 if ( ! b )
1841 return;
1842
1843 b->yy_n_chars = 0;
1844
1845 /* We always need two end-of-buffer characters. The first causes
1846 * a transition to the end-of-buffer state. The second causes
1847 * a jam in that state.
1848 */
1849 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1850 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1851
1852 b->yy_buf_pos = &b->yy_ch_buf[0];
1853
1854 b->yy_at_bol = 1;
1855 b->yy_buffer_status = YY_BUFFER_NEW;
1856
1857 if ( b == YY_CURRENT_BUFFER )
1858 expr_yy_load_buffer_state(yyscanner );
1859}
1860
1861/** Pushes the new state onto the stack. The new state becomes
1862 * the current state. This function will allocate the stack
1863 * if necessary.
1864 * @param new_buffer The new state.
1865 * @param yyscanner The scanner object.
1866 */
1867void expr_yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1868{
1869 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1870 if (new_buffer == NULL)
1871 return;
1872
1873 expr_yyensure_buffer_stack(yyscanner);
1874
1875 /* This block is copied from expr_yy_switch_to_buffer. */
1876 if ( YY_CURRENT_BUFFER )
1877 {
1878 /* Flush out information for old buffer. */
1879 *yyg->yy_c_buf_p = yyg->yy_hold_char;
1880 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1881 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1882 }
1883
1884 /* Only push if top exists. Otherwise, replace top. */
1885 if (YY_CURRENT_BUFFER)
1886 yyg->yy_buffer_stack_top++;
1887 YY_CURRENT_BUFFER_LVALUE = new_buffer;
1888
1889 /* copied from expr_yy_switch_to_buffer. */
1890 expr_yy_load_buffer_state(yyscanner );
1891 yyg->yy_did_buffer_switch_on_eof = 1;
1892}
1893
1894/** Removes and deletes the top of the stack, if present.
1895 * The next element becomes the new top.
1896 * @param yyscanner The scanner object.
1897 */
1898void expr_yypop_buffer_state (yyscan_t yyscanner)
1899{
1900 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1901 if (!YY_CURRENT_BUFFER)
1902 return;
1903
1904 expr_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner);
1905 YY_CURRENT_BUFFER_LVALUE = NULL;
1906 if (yyg->yy_buffer_stack_top > 0)
1907 --yyg->yy_buffer_stack_top;
1908
1909 if (YY_CURRENT_BUFFER) {
1910 expr_yy_load_buffer_state(yyscanner );
1911 yyg->yy_did_buffer_switch_on_eof = 1;
1912 }
1913}
1914
1915/* Allocates the stack if it does not exist.
1916 * Guarantees space for at least one push.
1917 */
1918static void expr_yyensure_buffer_stack (yyscan_t yyscanner)
1919{
1920 int num_to_alloc;
1921 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1922
1923 if (!yyg->yy_buffer_stack) {
1924
1925 /* First allocation is just for 2 elements, since we don't know if this
1926 * scanner will even need a stack. We use 2 instead of 1 to avoid an
1927 * immediate realloc on the next call.
1928 */
1929 num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1930 yyg->yy_buffer_stack = (struct yy_buffer_state**)expr_yyalloc
1931 (num_to_alloc * sizeof(struct yy_buffer_state*)
1932 , yyscanner);
1933 if ( ! yyg->yy_buffer_stack )
1934 YY_FATAL_ERROR( "out of dynamic memory in expr_yyensure_buffer_stack()" );
1935
1936 memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1937
1938 yyg->yy_buffer_stack_max = num_to_alloc;
1939 yyg->yy_buffer_stack_top = 0;
1940 return;
1941 }
1942
1943 if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
1944
1945 /* Increase the buffer to prepare for a possible push. */
1946 yy_size_t grow_size = 8 /* arbitrary grow size */;
1947
1948 num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
1949 yyg->yy_buffer_stack = (struct yy_buffer_state**)expr_yyrealloc
1950 (yyg->yy_buffer_stack,
1951 num_to_alloc * sizeof(struct yy_buffer_state*)
1952 , yyscanner);
1953 if ( ! yyg->yy_buffer_stack )
1954 YY_FATAL_ERROR( "out of dynamic memory in expr_yyensure_buffer_stack()" );
1955
1956 /* zero only the new slots.*/
1957 memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
1958 yyg->yy_buffer_stack_max = num_to_alloc;
1959 }
1960}
1961
1962/** Setup the input buffer state to scan directly from a user-specified character buffer.
1963 * @param base the character buffer
1964 * @param size the size in bytes of the character buffer
1965 * @param yyscanner The scanner object.
1966 * @return the newly allocated buffer state object.
1967 */
1968YY_BUFFER_STATE expr_yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
1969{
1970 YY_BUFFER_STATE b;
1971
1972 if ( size < 2 ||
1973 base[size-2] != YY_END_OF_BUFFER_CHAR ||
1974 base[size-1] != YY_END_OF_BUFFER_CHAR )
1975 /* They forgot to leave room for the EOB's. */
1976 return NULL;
1977
1978 b = (YY_BUFFER_STATE) expr_yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner );
1979 if ( ! b )
1980 YY_FATAL_ERROR( "out of dynamic memory in expr_yy_scan_buffer()" );
1981
1982 b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */
1983 b->yy_buf_pos = b->yy_ch_buf = base;
1984 b->yy_is_our_buffer = 0;
1985 b->yy_input_file = NULL;
1986 b->yy_n_chars = b->yy_buf_size;
1987 b->yy_is_interactive = 0;
1988 b->yy_at_bol = 1;
1989 b->yy_fill_buffer = 0;
1990 b->yy_buffer_status = YY_BUFFER_NEW;
1991
1992 expr_yy_switch_to_buffer(b ,yyscanner );
1993
1994 return b;
1995}
1996
1997/** Setup the input buffer state to scan a string. The next call to expr_yylex() will
1998 * scan from a @e copy of @a str.
1999 * @param yystr a NUL-terminated string to scan
2000 * @param yyscanner The scanner object.
2001 * @return the newly allocated buffer state object.
2002 * @note If you want to scan bytes that may contain NUL values, then use
2003 * expr_yy_scan_bytes() instead.
2004 */
2005YY_BUFFER_STATE expr_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
2006{
2007
2008 return expr_yy_scan_bytes(yystr,(int) strlen(yystr) ,yyscanner);
2009}
2010
2011/** Setup the input buffer state to scan the given bytes. The next call to expr_yylex() will
2012 * scan from a @e copy of @a bytes.
2013 * @param yybytes the byte buffer to scan
2014 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2015 * @param yyscanner The scanner object.
2016 * @return the newly allocated buffer state object.
2017 */
2018YY_BUFFER_STATE expr_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner)
2019{
2020 YY_BUFFER_STATE b;
2021 char *buf;
2022 yy_size_t n;
2023 int i;
2024
2025 /* Get memory for full buffer, including space for trailing EOB's. */
2026 n = (yy_size_t) (_yybytes_len + 2);
2027 buf = (char *) expr_yyalloc(n ,yyscanner );
2028 if ( ! buf )
2029 YY_FATAL_ERROR( "out of dynamic memory in expr_yy_scan_bytes()" );
2030
2031 for ( i = 0; i < _yybytes_len; ++i )
2032 buf[i] = yybytes[i];
2033
2034 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2035
2036 b = expr_yy_scan_buffer(buf,n ,yyscanner);
2037 if ( ! b )
2038 YY_FATAL_ERROR( "bad buffer in expr_yy_scan_bytes()" );
2039
2040 /* It's okay to grow etc. this buffer, and we should throw it
2041 * away when we're done.
2042 */
2043 b->yy_is_our_buffer = 1;
2044
2045 return b;
2046}
2047
2048#ifndef YY_EXIT_FAILURE
2049#define YY_EXIT_FAILURE 2
2050#endif
2051
2052static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner)
2053{
2054 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2055 (void)yyg;
2056 (void) fprintf( stderr, "%s\n", msg );
2057 exit( YY_EXIT_FAILURE );
2058}
2059
2060/* Redefine yyless() so it works in section 3 code. */
2061
2062#undef yyless
2063#define yyless(n) \
2064 do \
2065 { \
2066 /* Undo effects of setting up yytext. */ \
2067 int yyless_macro_arg = (n); \
2068 YY_LESS_LINENO(yyless_macro_arg);\
2069 yytext[yyleng] = yyg->yy_hold_char; \
2070 yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
2071 yyg->yy_hold_char = *yyg->yy_c_buf_p; \
2072 *yyg->yy_c_buf_p = '\0'; \
2073 yyleng = yyless_macro_arg; \
2074 } \
2075 while ( 0 )
2076
2077/* Accessor methods (get/set functions) to struct members. */
2078
2079/** Get the user-defined data for this scanner.
2080 * @param yyscanner The scanner object.
2081 */
2082YY_EXTRA_TYPE expr_yyget_extra (yyscan_t yyscanner)
2083{
2084 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2085 return yyextra;
2086}
2087
2088/** Get the current line number.
2089 * @param yyscanner The scanner object.
2090 */
2091int expr_yyget_lineno (yyscan_t yyscanner)
2092{
2093 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2094
2095 if (! YY_CURRENT_BUFFER)
2096 return 0;
2097
2098 return yylineno;
2099}
2100
2101/** Get the current column number.
2102 * @param yyscanner The scanner object.
2103 */
2104int expr_yyget_column (yyscan_t yyscanner)
2105{
2106 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2107
2108 if (! YY_CURRENT_BUFFER)
2109 return 0;
2110
2111 return yycolumn;
2112}
2113
2114/** Get the input stream.
2115 * @param yyscanner The scanner object.
2116 */
2117FILE *expr_yyget_in (yyscan_t yyscanner)
2118{
2119 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2120 return yyin;
2121}
2122
2123/** Get the output stream.
2124 * @param yyscanner The scanner object.
2125 */
2126FILE *expr_yyget_out (yyscan_t yyscanner)
2127{
2128 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2129 return yyout;
2130}
2131
2132/** Get the length of the current token.
2133 * @param yyscanner The scanner object.
2134 */
2135int expr_yyget_leng (yyscan_t yyscanner)
2136{
2137 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2138 return yyleng;
2139}
2140
2141/** Get the current token.
2142 * @param yyscanner The scanner object.
2143 */
2144
2145char *expr_yyget_text (yyscan_t yyscanner)
2146{
2147 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2148 return yytext;
2149}
2150
2151/** Set the user-defined data. This data is never touched by the scanner.
2152 * @param user_defined The data to be associated with this scanner.
2153 * @param yyscanner The scanner object.
2154 */
2155void expr_yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
2156{
2157 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2158 yyextra = user_defined ;
2159}
2160
2161/** Set the current line number.
2162 * @param _line_number line number
2163 * @param yyscanner The scanner object.
2164 */
2165void expr_yyset_lineno (int _line_number , yyscan_t yyscanner)
2166{
2167 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2168
2169 /* lineno is only valid if an input buffer exists. */
2170 if (! YY_CURRENT_BUFFER )
2171 YY_FATAL_ERROR( "expr_yyset_lineno called with no buffer" );
2172
2173 yylineno = _line_number;
2174}
2175
2176/** Set the current column.
2177 * @param _column_no column number
2178 * @param yyscanner The scanner object.
2179 */
2180void expr_yyset_column (int _column_no , yyscan_t yyscanner)
2181{
2182 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2183
2184 /* column is only valid if an input buffer exists. */
2185 if (! YY_CURRENT_BUFFER )
2186 YY_FATAL_ERROR( "expr_yyset_column called with no buffer" );
2187
2188 yycolumn = _column_no;
2189}
2190
2191/** Set the input stream. This does not discard the current
2192 * input buffer.
2193 * @param _in_str A readable stream.
2194 * @param yyscanner The scanner object.
2195 * @see expr_yy_switch_to_buffer
2196 */
2197void expr_yyset_in (FILE * _in_str , yyscan_t yyscanner)
2198{
2199 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2200 yyin = _in_str ;
2201}
2202
2203void expr_yyset_out (FILE * _out_str , yyscan_t yyscanner)
2204{
2205 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2206 yyout = _out_str ;
2207}
2208
2209int expr_yyget_debug (yyscan_t yyscanner)
2210{
2211 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2212 return yy_flex_debug;
2213}
2214
2215void expr_yyset_debug (int _bdebug , yyscan_t yyscanner)
2216{
2217 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2218 yy_flex_debug = _bdebug ;
2219}
2220
2221/* Accessor methods for yylval and yylloc */
2222
2223YYSTYPE * expr_yyget_lval (yyscan_t yyscanner)
2224{
2225 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2226 return yylval;
2227}
2228
2229void expr_yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
2230{
2231 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2232 yylval = yylval_param;
2233}
2234
2235/* User-visible API */
2236
2237/* expr_yylex_init is special because it creates the scanner itself, so it is
2238 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2239 * That's why we explicitly handle the declaration, instead of using our macros.
2240 */
2241
2242int expr_yylex_init(yyscan_t* ptr_yy_globals)
2243
2244{
2245 if (ptr_yy_globals == NULL){
2246 errno = EINVAL;
2247 return 1;
2248 }
2249
2250 *ptr_yy_globals = (yyscan_t) expr_yyalloc ( sizeof( struct yyguts_t ), NULL );
2251
2252 if (*ptr_yy_globals == NULL){
2253 errno = ENOMEM;
2254 return 1;
2255 }
2256
2257 /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2258 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2259
2260 return yy_init_globals ( *ptr_yy_globals );
2261}
2262
2263/* expr_yylex_init_extra has the same functionality as expr_yylex_init, but follows the
2264 * convention of taking the scanner as the last argument. Note however, that
2265 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2266 * is the reason, too, why this function also must handle its own declaration).
2267 * The user defined value in the first argument will be available to expr_yyalloc in
2268 * the yyextra field.
2269 */
2270
2271int expr_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals )
2272
2273{
2274 struct yyguts_t dummy_yyguts;
2275
2276 expr_yyset_extra (yy_user_defined, &dummy_yyguts);
2277
2278 if (ptr_yy_globals == NULL){
2279 errno = EINVAL;
2280 return 1;
2281 }
2282
2283 *ptr_yy_globals = (yyscan_t) expr_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2284
2285 if (*ptr_yy_globals == NULL){
2286 errno = ENOMEM;
2287 return 1;
2288 }
2289
2290 /* By setting to 0xAA, we expose bugs in
2291 yy_init_globals. Leave at 0x00 for releases. */
2292 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2293
2294 expr_yyset_extra (yy_user_defined, *ptr_yy_globals);
2295
2296 return yy_init_globals ( *ptr_yy_globals );
2297}
2298
2299static int yy_init_globals (yyscan_t yyscanner)
2300{
2301 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2302 /* Initialization is the same as for the non-reentrant scanner.
2303 * This function is called from expr_yylex_destroy(), so don't allocate here.
2304 */
2305
2306 yyg->yy_buffer_stack = NULL;
2307 yyg->yy_buffer_stack_top = 0;
2308 yyg->yy_buffer_stack_max = 0;
2309 yyg->yy_c_buf_p = NULL;
2310 yyg->yy_init = 0;
2311 yyg->yy_start = 0;
2312
2313 yyg->yy_start_stack_ptr = 0;
2314 yyg->yy_start_stack_depth = 0;
2315 yyg->yy_start_stack = NULL;
2316
2317/* Defined in main.c */
2318#ifdef YY_STDINIT
2319 yyin = stdin;
2320 yyout = stdout;
2321#else
2322 yyin = NULL;
2323 yyout = NULL;
2324#endif
2325
2326 /* For future reference: Set errno on error, since we are called by
2327 * expr_yylex_init()
2328 */
2329 return 0;
2330}
2331
2332/* expr_yylex_destroy is for both reentrant and non-reentrant scanners. */
2333int expr_yylex_destroy (yyscan_t yyscanner)
2334{
2335 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2336
2337 /* Pop the buffer stack, destroying each element. */
2338 while(YY_CURRENT_BUFFER){
2339 expr_yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner );
2340 YY_CURRENT_BUFFER_LVALUE = NULL;
2341 expr_yypop_buffer_state(yyscanner);
2342 }
2343
2344 /* Destroy the stack itself. */
2345 expr_yyfree(yyg->yy_buffer_stack ,yyscanner);
2346 yyg->yy_buffer_stack = NULL;
2347
2348 /* Destroy the start condition stack. */
2349 expr_yyfree(yyg->yy_start_stack ,yyscanner );
2350 yyg->yy_start_stack = NULL;
2351
2352 /* Reset the globals. This is important in a non-reentrant scanner so the next time
2353 * expr_yylex() is called, initialization will occur. */
2354 yy_init_globals( yyscanner);
2355
2356 /* Destroy the main struct (reentrant only). */
2357 expr_yyfree ( yyscanner , yyscanner );
2358 yyscanner = NULL;
2359 return 0;
2360}
2361
2362/*
2363 * Internal utility routines.
2364 */
2365
2366#ifndef yytext_ptr
2367static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner)
2368{
2369 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2370 (void)yyg;
2371
2372 int i;
2373 for ( i = 0; i < n; ++i )
2374 s1[i] = s2[i];
2375}
2376#endif
2377
2378#ifdef YY_NEED_STRLEN
2379static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
2380{
2381 int n;
2382 for ( n = 0; s[n]; ++n )
2383 ;
2384
2385 return n;
2386}
2387#endif
2388
2389void *expr_yyalloc (yy_size_t size , yyscan_t yyscanner)
2390{
2391 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2392 (void)yyg;
2393 return malloc(size);
2394}
2395
2396void *expr_yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
2397{
2398 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2399 (void)yyg;
2400
2401 /* The cast to (char *) in the following accommodates both
2402 * implementations that use char* generic pointers, and those
2403 * that use void* generic pointers. It works with the latter
2404 * because both ANSI C and C++ allow castless assignment from
2405 * any pointer type to void*, and deal with argument conversions
2406 * as though doing an assignment.
2407 */
2408 return realloc(ptr, size);
2409}
2410
2411void expr_yyfree (void * ptr , yyscan_t yyscanner)
2412{
2413 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2414 (void)yyg;
2415 free( (char *) ptr ); /* see expr_yyrealloc() for (char *) cast */
2416}
2417
2418#define YYTABLES_NAME "yytables"
2419
2420#line 265 "exprscan.l"
2421
2422
2423
2424/* LCOV_EXCL_STOP */
2425
2426void
2427expr_yyerror_more(yyscan_t yyscanner, const char *message, const char *more)
2428{
2429 PsqlScanState state = expr_yyget_extra(yyscanner);
2430 int error_detection_offset = expr_scanner_offset(state) - 1;
2431 YYSTYPE lval;
2432 char *full_line;
2433
2434 /*
2435 * While parsing an expression, we may not have collected the whole line
2436 * yet from the input source. Lex till EOL so we can report whole line.
2437 * (If we're at EOF, it's okay to call expr_yylex() an extra time.)
2438 */
2439 if (!last_was_newline)
2440 {
2441 while (expr_yylex(&lval,yyscanner))
2442 /* skip */ ;
2443 }
2444
2445 /* Extract the line, trimming trailing newline if any */
2446 full_line = expr_scanner_get_substring(state,
2447 expr_start_offset,
2448 expr_scanner_offset(state),
2449 true);
2450
2451 syntax_error(expr_source, expr_lineno, full_line, expr_command,
2452 message, more, error_detection_offset - expr_start_offset);
2453}
2454
2455void
2456expr_yyerror(yyscan_t yyscanner, const char *message)
2457{
2458 expr_yyerror_more(yyscanner, message, NULL);
2459}
2460
2461/*
2462 * Collect a space-separated word from a backslash command and return it
2463 * in word_buf, along with its starting string offset in *offset.
2464 * Returns true if successful, false if at end of command.
2465 */
2466bool
2467expr_lex_one_word(PsqlScanState state, PQExpBuffer word_buf, int *offset)
2468{
2469 int lexresult;
2470 YYSTYPE lval;
2471
2472 /* Must be scanning already */
2473 Assert(state->scanbufhandle != NULL);
2474
2475 /* Set current output target */
2476 state->output_buf = word_buf;
2477 resetPQExpBuffer(word_buf);
2478
2479 /* Set input source */
2480 if (state->buffer_stack != NULL)
2481 expr_yy_switch_to_buffer(state->buffer_stack->buf,state->scanner);
2482 else
2483 expr_yy_switch_to_buffer(state->scanbufhandle,state->scanner);
2484
2485 /* Set start state */
2486 state->start_state = INITIAL;
2487
2488 /* And lex. */
2489 lexresult = expr_yylex(&lval,state->scanner);
2490
2491 /*
2492 * Save start offset of word, if any. We could do this more efficiently,
2493 * but for now this seems fine.
2494 */
2495 if (lexresult)
2496 *offset = expr_scanner_offset(state) - word_buf->len;
2497 else
2498 *offset = -1;
2499
2500 /*
2501 * In case the caller returns to using the regular SQL lexer, reselect the
2502 * appropriate initial state.
2503 */
2504 psql_scan_reselect_sql_lexer(state);
2505
2506 return (bool) lexresult;
2507}
2508
2509/*
2510 * Prepare to lex an expression via expr_yyparse().
2511 *
2512 * Returns the yyscan_t that is to be passed to expr_yyparse().
2513 * (This is just state->scanner, but callers don't need to know that.)
2514 */
2515yyscan_t
2516expr_scanner_init(PsqlScanState state,
2517 const char *source, int lineno, int start_offset,
2518 const char *command)
2519{
2520 /* Save error context info */
2521 expr_source = source;
2522 expr_lineno = lineno;
2523 expr_start_offset = start_offset;
2524 expr_command = command;
2525
2526 /* Must be scanning already */
2527 Assert(state->scanbufhandle != NULL);
2528
2529 /* Set current output target */
2530 state->output_buf = NULL;
2531
2532 /* Set input source */
2533 if (state->buffer_stack != NULL)
2534 expr_yy_switch_to_buffer(state->buffer_stack->buf,state->scanner);
2535 else
2536 expr_yy_switch_to_buffer(state->scanbufhandle,state->scanner);
2537
2538 /* Set start state */
2539 state->start_state = EXPR;
2540
2541 return state->scanner;
2542}
2543
2544/*
2545 * Finish lexing an expression.
2546 */
2547void
2548expr_scanner_finish(yyscan_t yyscanner)
2549{
2550 PsqlScanState state = expr_yyget_extra(yyscanner);
2551
2552 /*
2553 * Reselect appropriate initial state for SQL lexer.
2554 */
2555 psql_scan_reselect_sql_lexer(state);
2556}
2557
2558/*
2559 * Get offset from start of string to end of current lexer token.
2560 *
2561 * We rely on the knowledge that flex modifies the scan buffer by storing
2562 * a NUL at the end of the current token (yytext). Note that this might
2563 * not work quite right if we were parsing a sub-buffer, but since pgbench
2564 * never invokes that functionality, it doesn't matter.
2565 */
2566int
2567expr_scanner_offset(PsqlScanState state)
2568{
2569 return strlen(state->scanbuf);
2570}
2571
2572/*
2573 * Get a malloc'd copy of the lexer input string from start_offset
2574 * to just before end_offset. If chomp is true, drop any trailing
2575 * newline(s).
2576 */
2577char *
2578expr_scanner_get_substring(PsqlScanState state,
2579 int start_offset, int end_offset,
2580 bool chomp)
2581{
2582 char *result;
2583 const char *scanptr = state->scanbuf + start_offset;
2584 int slen = end_offset - start_offset;
2585
2586 Assert(slen >= 0);
2587 Assert(end_offset <= strlen(state->scanbuf));
2588
2589 if (chomp)
2590 {
2591 while (slen > 0 &&
2592 (scanptr[slen - 1] == '\n' || scanptr[slen - 1] == '\r'))
2593 slen--;
2594 }
2595
2596 result = (char *) pg_malloc(slen + 1);
2597 memcpy(result, scanptr, slen);
2598 result[slen] = '\0';
2599
2600 return result;
2601}
2602
2603/*
2604 * Get the line number associated with the given string offset
2605 * (which must not be past the end of where we've lexed to).
2606 */
2607int
2608expr_scanner_get_lineno(PsqlScanState state, int offset)
2609{
2610 int lineno = 1;
2611 const char *p = state->scanbuf;
2612
2613 while (*p && offset > 0)
2614 {
2615 if (*p == '\n')
2616 lineno++;
2617 p++, offset--;
2618 }
2619 return lineno;
2620}
2621
2622