guardinari 0.1.0

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