1 /* This file is automatically generated by Lemon from input grammar
2 ** source file "fts5parse.y". */
3 /*
4 ** 2000-05-29
5 **
6 ** The author disclaims copyright to this source code.  In place of
7 ** a legal notice, here is a blessing:
8 **
9 **    May you do good and not evil.
10 **    May you find forgiveness for yourself and forgive others.
11 **    May you share freely, never taking more than you give.
12 **
13 *************************************************************************
14 ** Driver template for the LEMON parser generator.
15 **
16 ** The "lemon" program processes an LALR(1) input grammar file, then uses
17 ** this template to construct a parser.  The "lemon" program inserts text
18 ** at each "%%" line.  Also, any "P-a-r-s-e" identifer prefix (without the
19 ** interstitial "-" characters) contained in this template is changed into
20 ** the value of the %name directive from the grammar.  Otherwise, the content
21 ** of this template is copied straight through into the generate parser
22 ** source file.
23 **
24 ** The following is the concatenation of all %include directives from the
25 ** input grammar file:
26 */
27 /************ Begin %include sections from the grammar ************************/
28 #line 47 "fts5parse.y"
29 
30 #include "fts5Int.h"
31 #include "fts5parse.h"
32 
33 /*
34 ** Disable all error recovery processing in the parser push-down
35 ** automaton.
36 */
37 #define YYNOERRORRECOVERY 1
38 
39 /*
40 ** Make yytestcase() the same as testcase()
41 */
42 #define yytestcase(X) testcase(X)
43 
44 /*
45 ** Indicate that sqlite3ParserFree() will never be called with a null
46 ** pointer.
47 */
48 #define YYPARSEFREENOTNULL 1
49 
50 /*
51 ** Alternative datatype for the argument to the malloc() routine passed
52 ** into sqlite3ParserAlloc().  The default is size_t.
53 */
54 #define YYMALLOCARGTYPE  u64
55 
56 #line 57 "fts5parse.sql"
57 /**************** End of %include directives **********************************/
58 /* These constants specify the various numeric values for terminal symbols.
59 ***************** Begin token definitions *************************************/
60 #ifndef FTS5_OR
61 #define FTS5_OR                              1
62 #define FTS5_AND                             2
63 #define FTS5_NOT                             3
64 #define FTS5_TERM                            4
65 #define FTS5_COLON                           5
66 #define FTS5_MINUS                           6
67 #define FTS5_LCP                             7
68 #define FTS5_RCP                             8
69 #define FTS5_STRING                          9
70 #define FTS5_LP                             10
71 #define FTS5_RP                             11
72 #define FTS5_CARET                          12
73 #define FTS5_COMMA                          13
74 #define FTS5_PLUS                           14
75 #define FTS5_STAR                           15
76 #endif
77 /**************** End token definitions ***************************************/
78 
79 /* The next sections is a series of control #defines.
80 ** various aspects of the generated parser.
81 **    YYCODETYPE         is the data type used to store the integer codes
82 **                       that represent terminal and non-terminal symbols.
83 **                       "unsigned char" is used if there are fewer than
84 **                       256 symbols.  Larger types otherwise.
85 **    YYNOCODE           is a number of type YYCODETYPE that is not used for
86 **                       any terminal or nonterminal symbol.
87 **    YYFALLBACK         If defined, this indicates that one or more tokens
88 **                       (also known as: "terminal symbols") have fall-back
89 **                       values which should be used if the original symbol
90 **                       would not parse.  This permits keywords to sometimes
91 **                       be used as identifiers, for example.
92 **    YYACTIONTYPE       is the data type used for "action codes" - numbers
93 **                       that indicate what to do in response to the next
94 **                       token.
95 **    sqlite3Fts5ParserTOKENTYPE     is the data type used for minor type for terminal
96 **                       symbols.  Background: A "minor type" is a semantic
97 **                       value associated with a terminal or non-terminal
98 **                       symbols.  For example, for an "ID" terminal symbol,
99 **                       the minor type might be the name of the identifier.
100 **                       Each non-terminal can have a different minor type.
101 **                       Terminal symbols all have the same minor type, though.
102 **                       This macros defines the minor type for terminal
103 **                       symbols.
104 **    YYMINORTYPE        is the data type used for all minor types.
105 **                       This is typically a union of many types, one of
106 **                       which is sqlite3Fts5ParserTOKENTYPE.  The entry in the union
107 **                       for terminal symbols is called "yy0".
108 **    YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
109 **                       zero the stack is dynamically sized using realloc()
110 **    sqlite3Fts5ParserARG_SDECL     A static variable declaration for the %extra_argument
111 **    sqlite3Fts5ParserARG_PDECL     A parameter declaration for the %extra_argument
112 **    sqlite3Fts5ParserARG_PARAM     Code to pass %extra_argument as a subroutine parameter
113 **    sqlite3Fts5ParserARG_STORE     Code to store %extra_argument into yypParser
114 **    sqlite3Fts5ParserARG_FETCH     Code to extract %extra_argument from yypParser
115 **    sqlite3Fts5ParserCTX_*         As sqlite3Fts5ParserARG_ except for %extra_context
116 **    YYERRORSYMBOL      is the code number of the error symbol.  If not
117 **                       defined, then do no error processing.
118 **    YYNSTATE           the combined number of states.
119 **    YYNRULE            the number of rules in the grammar
120 **    YYNTOKEN           Number of terminal symbols
121 **    YY_MAX_SHIFT       Maximum value for shift actions
122 **    YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
123 **    YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
124 **    YY_ERROR_ACTION    The yy_action[] code for syntax error
125 **    YY_ACCEPT_ACTION   The yy_action[] code for accept
126 **    YY_NO_ACTION       The yy_action[] code for no-op
127 **    YY_MIN_REDUCE      Minimum value for reduce actions
128 **    YY_MAX_REDUCE      Maximum value for reduce actions
129 */
130 #ifndef INTERFACE
131 # define INTERFACE 1
132 #endif
133 /************* Begin control #defines *****************************************/
134 #define YYCODETYPE unsigned char
135 #define YYNOCODE 27
136 #define YYACTIONTYPE unsigned char
137 #define sqlite3Fts5ParserTOKENTYPE Fts5Token
138 typedef union {
139   int yyinit;
140   sqlite3Fts5ParserTOKENTYPE yy0;
141   int yy4;
142   Fts5Colset* yy11;
143   Fts5ExprNode* yy24;
144   Fts5ExprNearset* yy46;
145   Fts5ExprPhrase* yy53;
146 } YYMINORTYPE;
147 #ifndef YYSTACKDEPTH
148 #define YYSTACKDEPTH 100
149 #endif
150 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
151 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
152 #define sqlite3Fts5ParserARG_PARAM ,pParse
153 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse=yypParser->pParse;
154 #define sqlite3Fts5ParserARG_STORE yypParser->pParse=pParse;
155 #define sqlite3Fts5ParserCTX_SDECL
156 #define sqlite3Fts5ParserCTX_PDECL
157 #define sqlite3Fts5ParserCTX_PARAM
158 #define sqlite3Fts5ParserCTX_FETCH
159 #define sqlite3Fts5ParserCTX_STORE
160 #define YYNSTATE             35
161 #define YYNRULE              28
162 #define YYNRULE_WITH_ACTION  28
163 #define YYNTOKEN             16
164 #define YY_MAX_SHIFT         34
165 #define YY_MIN_SHIFTREDUCE   52
166 #define YY_MAX_SHIFTREDUCE   79
167 #define YY_ERROR_ACTION      80
168 #define YY_ACCEPT_ACTION     81
169 #define YY_NO_ACTION         82
170 #define YY_MIN_REDUCE        83
171 #define YY_MAX_REDUCE        110
172 /************* End control #defines *******************************************/
173 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
174 
175 /* Define the yytestcase() macro to be a no-op if is not already defined
176 ** otherwise.
177 **
178 ** Applications can choose to define yytestcase() in the %include section
179 ** to a macro that can assist in verifying code coverage.  For production
180 ** code the yytestcase() macro should be turned off.  But it is useful
181 ** for testing.
182 */
183 #ifndef yytestcase
184 # define yytestcase(X)
185 #endif
186 
187 
188 /* Next are the tables used to determine what action to take based on the
189 ** current state and lookahead token.  These tables are used to implement
190 ** functions that take a state number and lookahead value and return an
191 ** action integer.
192 **
193 ** Suppose the action integer is N.  Then the action is determined as
194 ** follows
195 **
196 **   0 <= N <= YY_MAX_SHIFT             Shift N.  That is, push the lookahead
197 **                                      token onto the stack and goto state N.
198 **
199 **   N between YY_MIN_SHIFTREDUCE       Shift to an arbitrary state then
200 **     and YY_MAX_SHIFTREDUCE           reduce by rule N-YY_MIN_SHIFTREDUCE.
201 **
202 **   N == YY_ERROR_ACTION               A syntax error has occurred.
203 **
204 **   N == YY_ACCEPT_ACTION              The parser accepts its input.
205 **
206 **   N == YY_NO_ACTION                  No such action.  Denotes unused
207 **                                      slots in the yy_action[] table.
208 **
209 **   N between YY_MIN_REDUCE            Reduce by rule N-YY_MIN_REDUCE
210 **     and YY_MAX_REDUCE
211 **
212 ** The action table is constructed as a single large table named yy_action[].
213 ** Given state S and lookahead X, the action is computed as either:
214 **
215 **    (A)   N = yy_action[ yy_shift_ofst[S] + X ]
216 **    (B)   N = yy_default[S]
217 **
218 ** The (A) formula is preferred.  The B formula is used instead if
219 ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X.
220 **
221 ** The formulas above are for computing the action when the lookahead is
222 ** a terminal symbol.  If the lookahead is a non-terminal (as occurs after
223 ** a reduce action) then the yy_reduce_ofst[] array is used in place of
224 ** the yy_shift_ofst[] array.
225 **
226 ** The following are the tables generated in this section:
227 **
228 **  yy_action[]        A single table containing all actions.
229 **  yy_lookahead[]     A table containing the lookahead for each entry in
230 **                     yy_action.  Used to detect hash collisions.
231 **  yy_shift_ofst[]    For each state, the offset into yy_action for
232 **                     shifting terminals.
233 **  yy_reduce_ofst[]   For each state, the offset into yy_action for
234 **                     shifting non-terminals after a reduce.
235 **  yy_default[]       Default action for each state.
236 **
237 *********** Begin parsing tables **********************************************/
238 #define YY_ACTTAB_COUNT (105)
239 static const YYACTIONTYPE yy_action[] = {
240  /*     0 */    81,   20,   96,    6,   28,   99,   98,   26,   26,   18,
241  /*    10 */    96,    6,   28,   17,   98,   56,   26,   19,   96,    6,
242  /*    20 */    28,   14,   98,   14,   26,   31,   92,   96,    6,   28,
243  /*    30 */   108,   98,   25,   26,   21,   96,    6,   28,   78,   98,
244  /*    40 */    58,   26,   29,   96,    6,   28,  107,   98,   22,   26,
245  /*    50 */    24,   16,   12,   11,    1,   13,   13,   24,   16,   23,
246  /*    60 */    11,   33,   34,   13,   97,    8,   27,   32,   98,    7,
247  /*    70 */    26,    3,    4,    5,    3,    4,    5,    3,   83,    4,
248  /*    80 */     5,    3,   63,    5,    3,   62,   12,    2,   86,   13,
249  /*    90 */     9,   30,   10,   10,   54,   57,   75,   78,   78,   53,
250  /*   100 */    57,   15,   82,   82,   71,
251 };
252 static const YYCODETYPE yy_lookahead[] = {
253  /*     0 */    16,   17,   18,   19,   20,   22,   22,   24,   24,   17,
254  /*    10 */    18,   19,   20,    7,   22,    9,   24,   17,   18,   19,
255  /*    20 */    20,    9,   22,    9,   24,   13,   17,   18,   19,   20,
256  /*    30 */    26,   22,   24,   24,   17,   18,   19,   20,   15,   22,
257  /*    40 */     9,   24,   17,   18,   19,   20,   26,   22,   21,   24,
258  /*    50 */     6,    7,    9,    9,   10,   12,   12,    6,    7,   21,
259  /*    60 */     9,   24,   25,   12,   18,    5,   20,   14,   22,    5,
260  /*    70 */    24,    3,    1,    2,    3,    1,    2,    3,    0,    1,
261  /*    80 */     2,    3,   11,    2,    3,   11,    9,   10,    5,   12,
262  /*    90 */    23,   24,   10,   10,    8,    9,    9,   15,   15,    8,
263  /*   100 */     9,    9,   27,   27,   11,   27,   27,   27,   27,   27,
264  /*   110 */    27,   27,   27,   27,   27,   27,   27,   27,   27,   27,
265  /*   120 */    27,
266 };
267 #define YY_SHIFT_COUNT    (34)
268 #define YY_SHIFT_MIN      (0)
269 #define YY_SHIFT_MAX      (93)
270 static const unsigned char yy_shift_ofst[] = {
271  /*     0 */    44,   44,   44,   44,   44,   44,   51,   77,   43,   12,
272  /*    10 */    14,   83,   82,   14,   23,   23,   31,   31,   71,   74,
273  /*    20 */    78,   81,   86,   91,    6,   53,   53,   60,   64,   68,
274  /*    30 */    53,   87,   92,   53,   93,
275 };
276 #define YY_REDUCE_COUNT (17)
277 #define YY_REDUCE_MIN   (-17)
278 #define YY_REDUCE_MAX   (67)
279 static const signed char yy_reduce_ofst[] = {
280  /*     0 */   -16,   -8,    0,    9,   17,   25,   46,  -17,  -17,   37,
281  /*    10 */    67,    4,    4,    8,    4,   20,   27,   38,
282 };
283 static const YYACTIONTYPE yy_default[] = {
284  /*     0 */    80,   80,   80,   80,   80,   80,   95,   80,   80,  105,
285  /*    10 */    80,  110,  110,   80,  110,  110,   80,   80,   80,   80,
286  /*    20 */    80,   91,   80,   80,   80,  101,  100,   80,   80,   90,
287  /*    30 */   103,   80,   80,  104,   80,
288 };
289 /********** End of lemon-generated parsing tables *****************************/
290 
291 /* The next table maps tokens (terminal symbols) into fallback tokens.
292 ** If a construct like the following:
293 **
294 **      %fallback ID X Y Z.
295 **
296 ** appears in the grammar, then ID becomes a fallback token for X, Y,
297 ** and Z.  Whenever one of the tokens X, Y, or Z is input to the parser
298 ** but it does not parse, the type of the token is changed to ID and
299 ** the parse is retried before an error is thrown.
300 **
301 ** This feature can be used, for example, to cause some keywords in a language
302 ** to revert to identifiers if they keyword does not apply in the context where
303 ** it appears.
304 */
305 #ifdef YYFALLBACK
306 static const YYCODETYPE yyFallback[] = {
307 };
308 #endif /* YYFALLBACK */
309 
310 /* The following structure represents a single element of the
311 ** parser's stack.  Information stored includes:
312 **
313 **   +  The state number for the parser at this level of the stack.
314 **
315 **   +  The value of the token stored at this level of the stack.
316 **      (In other words, the "major" token.)
317 **
318 **   +  The semantic value stored at this level of the stack.  This is
319 **      the information used by the action routines in the grammar.
320 **      It is sometimes called the "minor" token.
321 **
322 ** After the "shift" half of a SHIFTREDUCE action, the stateno field
323 ** actually contains the reduce action for the second half of the
324 ** SHIFTREDUCE.
325 */
326 struct yyStackEntry {
327   YYACTIONTYPE stateno;  /* The state-number, or reduce action in SHIFTREDUCE */
328   YYCODETYPE major;      /* The major token value.  This is the code
329                          ** number for the token at this stack level */
330   YYMINORTYPE minor;     /* The user-supplied minor token value.  This
331                          ** is the value of the token  */
332 };
333 typedef struct yyStackEntry yyStackEntry;
334 
335 /* The state of the parser is completely contained in an instance of
336 ** the following structure */
337 struct yyParser {
338   yyStackEntry *yytos;          /* Pointer to top element of the stack */
339 #ifdef YYTRACKMAXSTACKDEPTH
340   int yyhwm;                    /* High-water mark of the stack */
341 #endif
342 #ifndef YYNOERRORRECOVERY
343   int yyerrcnt;                 /* Shifts left before out of the error */
344 #endif
345   sqlite3Fts5ParserARG_SDECL                /* A place to hold %extra_argument */
346   sqlite3Fts5ParserCTX_SDECL                /* A place to hold %extra_context */
347 #if YYSTACKDEPTH<=0
348   int yystksz;                  /* Current side of the stack */
349   yyStackEntry *yystack;        /* The parser's stack */
350   yyStackEntry yystk0;          /* First stack entry */
351 #else
352   yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
353   yyStackEntry *yystackEnd;            /* Last entry in the stack */
354 #endif
355 };
356 typedef struct yyParser yyParser;
357 
358 #include <assert.h>
359 #ifndef NDEBUG
360 #include <stdio.h>
361 static FILE *yyTraceFILE = 0;
362 static char *yyTracePrompt = 0;
363 #endif /* NDEBUG */
364 
365 #ifndef NDEBUG
366 /*
367 ** Turn parser tracing on by giving a stream to which to write the trace
368 ** and a prompt to preface each trace message.  Tracing is turned off
369 ** by making either argument NULL
370 **
371 ** Inputs:
372 ** <ul>
373 ** <li> A FILE* to which trace output should be written.
374 **      If NULL, then tracing is turned off.
375 ** <li> A prefix string written at the beginning of every
376 **      line of trace output.  If NULL, then tracing is
377 **      turned off.
378 ** </ul>
379 **
380 ** Outputs:
381 ** None.
382 */
383 void sqlite3Fts5ParserTrace(FILE *TraceFILE, char *zTracePrompt){
384   yyTraceFILE = TraceFILE;
385   yyTracePrompt = zTracePrompt;
386   if( yyTraceFILE==0 ) yyTracePrompt = 0;
387   else if( yyTracePrompt==0 ) yyTraceFILE = 0;
388 }
389 #endif /* NDEBUG */
390 
391 #if defined(YYCOVERAGE) || !defined(NDEBUG)
392 /* For tracing shifts, the names of all terminals and nonterminals
393 ** are required.  The following table supplies these names */
394 static const char *const yyTokenName[] = {
395   /*    0 */ "$",
396   /*    1 */ "OR",
397   /*    2 */ "AND",
398   /*    3 */ "NOT",
399   /*    4 */ "TERM",
400   /*    5 */ "COLON",
401   /*    6 */ "MINUS",
402   /*    7 */ "LCP",
403   /*    8 */ "RCP",
404   /*    9 */ "STRING",
405   /*   10 */ "LP",
406   /*   11 */ "RP",
407   /*   12 */ "CARET",
408   /*   13 */ "COMMA",
409   /*   14 */ "PLUS",
410   /*   15 */ "STAR",
411   /*   16 */ "input",
412   /*   17 */ "expr",
413   /*   18 */ "cnearset",
414   /*   19 */ "exprlist",
415   /*   20 */ "colset",
416   /*   21 */ "colsetlist",
417   /*   22 */ "nearset",
418   /*   23 */ "nearphrases",
419   /*   24 */ "phrase",
420   /*   25 */ "neardist_opt",
421   /*   26 */ "star_opt",
422 };
423 #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
424 
425 #ifndef NDEBUG
426 /* For tracing reduce actions, the names of all rules are required.
427 */
428 static const char *const yyRuleName[] = {
429  /*   0 */ "input ::= expr",
430  /*   1 */ "colset ::= MINUS LCP colsetlist RCP",
431  /*   2 */ "colset ::= LCP colsetlist RCP",
432  /*   3 */ "colset ::= STRING",
433  /*   4 */ "colset ::= MINUS STRING",
434  /*   5 */ "colsetlist ::= colsetlist STRING",
435  /*   6 */ "colsetlist ::= STRING",
436  /*   7 */ "expr ::= expr AND expr",
437  /*   8 */ "expr ::= expr OR expr",
438  /*   9 */ "expr ::= expr NOT expr",
439  /*  10 */ "expr ::= colset COLON LP expr RP",
440  /*  11 */ "expr ::= LP expr RP",
441  /*  12 */ "expr ::= exprlist",
442  /*  13 */ "exprlist ::= cnearset",
443  /*  14 */ "exprlist ::= exprlist cnearset",
444  /*  15 */ "cnearset ::= nearset",
445  /*  16 */ "cnearset ::= colset COLON nearset",
446  /*  17 */ "nearset ::= phrase",
447  /*  18 */ "nearset ::= CARET phrase",
448  /*  19 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
449  /*  20 */ "nearphrases ::= phrase",
450  /*  21 */ "nearphrases ::= nearphrases phrase",
451  /*  22 */ "neardist_opt ::=",
452  /*  23 */ "neardist_opt ::= COMMA STRING",
453  /*  24 */ "phrase ::= phrase PLUS STRING star_opt",
454  /*  25 */ "phrase ::= STRING star_opt",
455  /*  26 */ "star_opt ::= STAR",
456  /*  27 */ "star_opt ::=",
457 };
458 #endif /* NDEBUG */
459 
460 
461 #if YYSTACKDEPTH<=0
462 /*
463 ** Try to increase the size of the parser stack.  Return the number
464 ** of errors.  Return 0 on success.
465 */
466 static int yyGrowStack(yyParser *p){
467   int newSize;
468   int idx;
469   yyStackEntry *pNew;
470 
471   newSize = p->yystksz*2 + 100;
472   idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
473   if( p->yystack==&p->yystk0 ){
474     pNew = malloc(newSize*sizeof(pNew[0]));
475     if( pNew ) pNew[0] = p->yystk0;
476   }else{
477     pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
478   }
479   if( pNew ){
480     p->yystack = pNew;
481     p->yytos = &p->yystack[idx];
482 #ifndef NDEBUG
483     if( yyTraceFILE ){
484       fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
485               yyTracePrompt, p->yystksz, newSize);
486     }
487 #endif
488     p->yystksz = newSize;
489   }
490   return pNew==0;
491 }
492 #endif
493 
494 /* Datatype of the argument to the memory allocated passed as the
495 ** second argument to sqlite3Fts5ParserAlloc() below.  This can be changed by
496 ** putting an appropriate #define in the %include section of the input
497 ** grammar.
498 */
499 #ifndef YYMALLOCARGTYPE
500 # define YYMALLOCARGTYPE size_t
501 #endif
502 
503 /* Initialize a new parser that has already been allocated.
504 */
505 void sqlite3Fts5ParserInit(void *yypRawParser sqlite3Fts5ParserCTX_PDECL){
506   yyParser *yypParser = (yyParser*)yypRawParser;
507   sqlite3Fts5ParserCTX_STORE
508 #ifdef YYTRACKMAXSTACKDEPTH
509   yypParser->yyhwm = 0;
510 #endif
511 #if YYSTACKDEPTH<=0
512   yypParser->yytos = NULL;
513   yypParser->yystack = NULL;
514   yypParser->yystksz = 0;
515   if( yyGrowStack(yypParser) ){
516     yypParser->yystack = &yypParser->yystk0;
517     yypParser->yystksz = 1;
518   }
519 #endif
520 #ifndef YYNOERRORRECOVERY
521   yypParser->yyerrcnt = -1;
522 #endif
523   yypParser->yytos = yypParser->yystack;
524   yypParser->yystack[0].stateno = 0;
525   yypParser->yystack[0].major = 0;
526 #if YYSTACKDEPTH>0
527   yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1];
528 #endif
529 }
530 
531 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
532 /*
533 ** This function allocates a new parser.
534 ** The only argument is a pointer to a function which works like
535 ** malloc.
536 **
537 ** Inputs:
538 ** A pointer to the function used to allocate memory.
539 **
540 ** Outputs:
541 ** A pointer to a parser.  This pointer is used in subsequent calls
542 ** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
543 */
544 void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) sqlite3Fts5ParserCTX_PDECL){
545   yyParser *yypParser;
546   yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) );
547   if( yypParser ){
548     sqlite3Fts5ParserCTX_STORE
549     sqlite3Fts5ParserInit(yypParser sqlite3Fts5ParserCTX_PARAM);
550   }
551   return (void*)yypParser;
552 }
553 #endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */
554 
555 
556 /* The following function deletes the "minor type" or semantic value
557 ** associated with a symbol.  The symbol can be either a terminal
558 ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is
559 ** a pointer to the value to be deleted.  The code used to do the
560 ** deletions is derived from the %destructor and/or %token_destructor
561 ** directives of the input grammar.
562 */
563 static void yy_destructor(
564   yyParser *yypParser,    /* The parser */
565   YYCODETYPE yymajor,     /* Type code for object to destroy */
566   YYMINORTYPE *yypminor   /* The object to be destroyed */
567 ){
568   sqlite3Fts5ParserARG_FETCH
569   sqlite3Fts5ParserCTX_FETCH
570   switch( yymajor ){
571     /* Here is inserted the actions which take place when a
572     ** terminal or non-terminal is destroyed.  This can happen
573     ** when the symbol is popped from the stack during a
574     ** reduce or during error processing or when a parser is
575     ** being destroyed before it is finished parsing.
576     **
577     ** Note: during a reduce, the only symbols destroyed are those
578     ** which appear on the RHS of the rule, but which are *not* used
579     ** inside the C code.
580     */
581 /********* Begin destructor definitions ***************************************/
582     case 16: /* input */
583 {
584 #line 83 "fts5parse.y"
585  (void)pParse;
586 #line 586 "fts5parse.sql"
587 }
588       break;
589     case 17: /* expr */
590     case 18: /* cnearset */
591     case 19: /* exprlist */
592 {
593 #line 89 "fts5parse.y"
594  sqlite3Fts5ParseNodeFree((yypminor->yy24));
595 #line 595 "fts5parse.sql"
596 }
597       break;
598     case 20: /* colset */
599     case 21: /* colsetlist */
600 {
601 #line 93 "fts5parse.y"
602  sqlite3_free((yypminor->yy11));
603 #line 603 "fts5parse.sql"
604 }
605       break;
606     case 22: /* nearset */
607     case 23: /* nearphrases */
608 {
609 #line 148 "fts5parse.y"
610  sqlite3Fts5ParseNearsetFree((yypminor->yy46));
611 #line 611 "fts5parse.sql"
612 }
613       break;
614     case 24: /* phrase */
615 {
616 #line 183 "fts5parse.y"
617  sqlite3Fts5ParsePhraseFree((yypminor->yy53));
618 #line 618 "fts5parse.sql"
619 }
620       break;
621 /********* End destructor definitions *****************************************/
622     default:  break;   /* If no destructor action specified: do nothing */
623   }
624 }
625 
626 /*
627 ** Pop the parser's stack once.
628 **
629 ** If there is a destructor routine associated with the token which
630 ** is popped from the stack, then call it.
631 */
632 static void yy_pop_parser_stack(yyParser *pParser){
633   yyStackEntry *yytos;
634   assert( pParser->yytos!=0 );
635   assert( pParser->yytos > pParser->yystack );
636   yytos = pParser->yytos--;
637 #ifndef NDEBUG
638   if( yyTraceFILE ){
639     fprintf(yyTraceFILE,"%sPopping %s\n",
640       yyTracePrompt,
641       yyTokenName[yytos->major]);
642   }
643 #endif
644   yy_destructor(pParser, yytos->major, &yytos->minor);
645 }
646 
647 /*
648 ** Clear all secondary memory allocations from the parser
649 */
650 void sqlite3Fts5ParserFinalize(void *p){
651   yyParser *pParser = (yyParser*)p;
652   while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
653 #if YYSTACKDEPTH<=0
654   if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
655 #endif
656 }
657 
658 #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK
659 /*
660 ** Deallocate and destroy a parser.  Destructors are called for
661 ** all stack elements before shutting the parser down.
662 **
663 ** If the YYPARSEFREENEVERNULL macro exists (for example because it
664 ** is defined in a %include section of the input grammar) then it is
665 ** assumed that the input pointer is never NULL.
666 */
667 void sqlite3Fts5ParserFree(
668   void *p,                    /* The parser to be deleted */
669   void (*freeProc)(void*)     /* Function used to reclaim memory */
670 ){
671 #ifndef YYPARSEFREENEVERNULL
672   if( p==0 ) return;
673 #endif
674   sqlite3Fts5ParserFinalize(p);
675   (*freeProc)(p);
676 }
677 #endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */
678 
679 /*
680 ** Return the peak depth of the stack for a parser.
681 */
682 #ifdef YYTRACKMAXSTACKDEPTH
683 int sqlite3Fts5ParserStackPeak(void *p){
684   yyParser *pParser = (yyParser*)p;
685   return pParser->yyhwm;
686 }
687 #endif
688 
689 /* This array of booleans keeps track of the parser statement
690 ** coverage.  The element yycoverage[X][Y] is set when the parser
691 ** is in state X and has a lookahead token Y.  In a well-tested
692 ** systems, every element of this matrix should end up being set.
693 */
694 #if defined(YYCOVERAGE)
695 static unsigned char yycoverage[YYNSTATE][YYNTOKEN];
696 #endif
697 
698 /*
699 ** Write into out a description of every state/lookahead combination that
700 **
701 **   (1)  has not been used by the parser, and
702 **   (2)  is not a syntax error.
703 **
704 ** Return the number of missed state/lookahead combinations.
705 */
706 #if defined(YYCOVERAGE)
707 int sqlite3Fts5ParserCoverage(FILE *out){
708   int stateno, iLookAhead, i;
709   int nMissed = 0;
710   for(stateno=0; stateno<YYNSTATE; stateno++){
711     i = yy_shift_ofst[stateno];
712     for(iLookAhead=0; iLookAhead<YYNTOKEN; iLookAhead++){
713       if( yy_lookahead[i+iLookAhead]!=iLookAhead ) continue;
714       if( yycoverage[stateno][iLookAhead]==0 ) nMissed++;
715       if( out ){
716         fprintf(out,"State %d lookahead %s %s\n", stateno,
717                 yyTokenName[iLookAhead],
718                 yycoverage[stateno][iLookAhead] ? "ok" : "missed");
719       }
720     }
721   }
722   return nMissed;
723 }
724 #endif
725 
726 /*
727 ** Find the appropriate action for a parser given the terminal
728 ** look-ahead token iLookAhead.
729 */
730 static YYACTIONTYPE yy_find_shift_action(
731   YYCODETYPE iLookAhead,    /* The look-ahead token */
732   YYACTIONTYPE stateno      /* Current state number */
733 ){
734   int i;
735 
736   if( stateno>YY_MAX_SHIFT ) return stateno;
737   assert( stateno <= YY_SHIFT_COUNT );
738 #if defined(YYCOVERAGE)
739   yycoverage[stateno][iLookAhead] = 1;
740 #endif
741   do{
742     i = yy_shift_ofst[stateno];
743     assert( i>=0 );
744     assert( i<=YY_ACTTAB_COUNT );
745     assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD );
746     assert( iLookAhead!=YYNOCODE );
747     assert( iLookAhead < YYNTOKEN );
748     i += iLookAhead;
749     assert( i<(int)YY_NLOOKAHEAD );
750     if( yy_lookahead[i]!=iLookAhead ){
751 #ifdef YYFALLBACK
752       YYCODETYPE iFallback;            /* Fallback token */
753       assert( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0]) );
754       iFallback = yyFallback[iLookAhead];
755       if( iFallback!=0 ){
756 #ifndef NDEBUG
757         if( yyTraceFILE ){
758           fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
759              yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
760         }
761 #endif
762         assert( yyFallback[iFallback]==0 ); /* Fallback loop must terminate */
763         iLookAhead = iFallback;
764         continue;
765       }
766 #endif
767 #ifdef YYWILDCARD
768       {
769         int j = i - iLookAhead + YYWILDCARD;
770         assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) );
771         if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){
772 #ifndef NDEBUG
773           if( yyTraceFILE ){
774             fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
775                yyTracePrompt, yyTokenName[iLookAhead],
776                yyTokenName[YYWILDCARD]);
777           }
778 #endif /* NDEBUG */
779           return yy_action[j];
780         }
781       }
782 #endif /* YYWILDCARD */
783       return yy_default[stateno];
784     }else{
785       assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) );
786       return yy_action[i];
787     }
788   }while(1);
789 }
790 
791 /*
792 ** Find the appropriate action for a parser given the non-terminal
793 ** look-ahead token iLookAhead.
794 */
795 static YYACTIONTYPE yy_find_reduce_action(
796   YYACTIONTYPE stateno,     /* Current state number */
797   YYCODETYPE iLookAhead     /* The look-ahead token */
798 ){
799   int i;
800 #ifdef YYERRORSYMBOL
801   if( stateno>YY_REDUCE_COUNT ){
802     return yy_default[stateno];
803   }
804 #else
805   assert( stateno<=YY_REDUCE_COUNT );
806 #endif
807   i = yy_reduce_ofst[stateno];
808   assert( iLookAhead!=YYNOCODE );
809   i += iLookAhead;
810 #ifdef YYERRORSYMBOL
811   if( i<0 || i>=YY_ACTTAB_COUNT || yy_lookahead[i]!=iLookAhead ){
812     return yy_default[stateno];
813   }
814 #else
815   assert( i>=0 && i<YY_ACTTAB_COUNT );
816   assert( yy_lookahead[i]==iLookAhead );
817 #endif
818   return yy_action[i];
819 }
820 
821 /*
822 ** The following routine is called if the stack overflows.
823 */
824 static void yyStackOverflow(yyParser *yypParser){
825    sqlite3Fts5ParserARG_FETCH
826    sqlite3Fts5ParserCTX_FETCH
827 #ifndef NDEBUG
828    if( yyTraceFILE ){
829      fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
830    }
831 #endif
832    while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
833    /* Here code is inserted which will execute if the parser
834    ** stack every overflows */
835 /******** Begin %stack_overflow code ******************************************/
836 #line 36 "fts5parse.y"
837 
838   sqlite3Fts5ParseError(pParse, "fts5: parser stack overflow");
839 #line 839 "fts5parse.sql"
840 /******** End %stack_overflow code ********************************************/
841    sqlite3Fts5ParserARG_STORE /* Suppress warning about unused %extra_argument var */
842    sqlite3Fts5ParserCTX_STORE
843 }
844 
845 /*
846 ** Print tracing information for a SHIFT action
847 */
848 #ifndef NDEBUG
849 static void yyTraceShift(yyParser *yypParser, int yyNewState, const char *zTag){
850   if( yyTraceFILE ){
851     if( yyNewState<YYNSTATE ){
852       fprintf(yyTraceFILE,"%s%s '%s', go to state %d\n",
853          yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
854          yyNewState);
855     }else{
856       fprintf(yyTraceFILE,"%s%s '%s', pending reduce %d\n",
857          yyTracePrompt, zTag, yyTokenName[yypParser->yytos->major],
858          yyNewState - YY_MIN_REDUCE);
859     }
860   }
861 }
862 #else
863 # define yyTraceShift(X,Y,Z)
864 #endif
865 
866 /*
867 ** Perform a shift action.
868 */
869 static void yy_shift(
870   yyParser *yypParser,          /* The parser to be shifted */
871   YYACTIONTYPE yyNewState,      /* The new state to shift in */
872   YYCODETYPE yyMajor,           /* The major token to shift in */
873   sqlite3Fts5ParserTOKENTYPE yyMinor        /* The minor token to shift in */
874 ){
875   yyStackEntry *yytos;
876   yypParser->yytos++;
877 #ifdef YYTRACKMAXSTACKDEPTH
878   if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
879     yypParser->yyhwm++;
880     assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) );
881   }
882 #endif
883 #if YYSTACKDEPTH>0
884   if( yypParser->yytos>yypParser->yystackEnd ){
885     yypParser->yytos--;
886     yyStackOverflow(yypParser);
887     return;
888   }
889 #else
890   if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
891     if( yyGrowStack(yypParser) ){
892       yypParser->yytos--;
893       yyStackOverflow(yypParser);
894       return;
895     }
896   }
897 #endif
898   if( yyNewState > YY_MAX_SHIFT ){
899     yyNewState += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
900   }
901   yytos = yypParser->yytos;
902   yytos->stateno = yyNewState;
903   yytos->major = yyMajor;
904   yytos->minor.yy0 = yyMinor;
905   yyTraceShift(yypParser, yyNewState, "Shift");
906 }
907 
908 /* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
909 ** of that rule */
910 static const YYCODETYPE yyRuleInfoLhs[] = {
911     16,  /* (0) input ::= expr */
912     20,  /* (1) colset ::= MINUS LCP colsetlist RCP */
913     20,  /* (2) colset ::= LCP colsetlist RCP */
914     20,  /* (3) colset ::= STRING */
915     20,  /* (4) colset ::= MINUS STRING */
916     21,  /* (5) colsetlist ::= colsetlist STRING */
917     21,  /* (6) colsetlist ::= STRING */
918     17,  /* (7) expr ::= expr AND expr */
919     17,  /* (8) expr ::= expr OR expr */
920     17,  /* (9) expr ::= expr NOT expr */
921     17,  /* (10) expr ::= colset COLON LP expr RP */
922     17,  /* (11) expr ::= LP expr RP */
923     17,  /* (12) expr ::= exprlist */
924     19,  /* (13) exprlist ::= cnearset */
925     19,  /* (14) exprlist ::= exprlist cnearset */
926     18,  /* (15) cnearset ::= nearset */
927     18,  /* (16) cnearset ::= colset COLON nearset */
928     22,  /* (17) nearset ::= phrase */
929     22,  /* (18) nearset ::= CARET phrase */
930     22,  /* (19) nearset ::= STRING LP nearphrases neardist_opt RP */
931     23,  /* (20) nearphrases ::= phrase */
932     23,  /* (21) nearphrases ::= nearphrases phrase */
933     25,  /* (22) neardist_opt ::= */
934     25,  /* (23) neardist_opt ::= COMMA STRING */
935     24,  /* (24) phrase ::= phrase PLUS STRING star_opt */
936     24,  /* (25) phrase ::= STRING star_opt */
937     26,  /* (26) star_opt ::= STAR */
938     26,  /* (27) star_opt ::= */
939 };
940 
941 /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
942 ** of symbols on the right-hand side of that rule. */
943 static const signed char yyRuleInfoNRhs[] = {
944    -1,  /* (0) input ::= expr */
945    -4,  /* (1) colset ::= MINUS LCP colsetlist RCP */
946    -3,  /* (2) colset ::= LCP colsetlist RCP */
947    -1,  /* (3) colset ::= STRING */
948    -2,  /* (4) colset ::= MINUS STRING */
949    -2,  /* (5) colsetlist ::= colsetlist STRING */
950    -1,  /* (6) colsetlist ::= STRING */
951    -3,  /* (7) expr ::= expr AND expr */
952    -3,  /* (8) expr ::= expr OR expr */
953    -3,  /* (9) expr ::= expr NOT expr */
954    -5,  /* (10) expr ::= colset COLON LP expr RP */
955    -3,  /* (11) expr ::= LP expr RP */
956    -1,  /* (12) expr ::= exprlist */
957    -1,  /* (13) exprlist ::= cnearset */
958    -2,  /* (14) exprlist ::= exprlist cnearset */
959    -1,  /* (15) cnearset ::= nearset */
960    -3,  /* (16) cnearset ::= colset COLON nearset */
961    -1,  /* (17) nearset ::= phrase */
962    -2,  /* (18) nearset ::= CARET phrase */
963    -5,  /* (19) nearset ::= STRING LP nearphrases neardist_opt RP */
964    -1,  /* (20) nearphrases ::= phrase */
965    -2,  /* (21) nearphrases ::= nearphrases phrase */
966     0,  /* (22) neardist_opt ::= */
967    -2,  /* (23) neardist_opt ::= COMMA STRING */
968    -4,  /* (24) phrase ::= phrase PLUS STRING star_opt */
969    -2,  /* (25) phrase ::= STRING star_opt */
970    -1,  /* (26) star_opt ::= STAR */
971     0,  /* (27) star_opt ::= */
972 };
973 
974 static void yy_accept(yyParser*);  /* Forward Declaration */
975 
976 /*
977 ** Perform a reduce action and the shift that must immediately
978 ** follow the reduce.
979 **
980 ** The yyLookahead and yyLookaheadToken parameters provide reduce actions
981 ** access to the lookahead token (if any).  The yyLookahead will be YYNOCODE
982 ** if the lookahead token has already been consumed.  As this procedure is
983 ** only called from one place, optimizing compilers will in-line it, which
984 ** means that the extra parameters have no performance impact.
985 */
986 static YYACTIONTYPE yy_reduce(
987   yyParser *yypParser,         /* The parser */
988   unsigned int yyruleno,       /* Number of the rule by which to reduce */
989   int yyLookahead,             /* Lookahead token, or YYNOCODE if none */
990   sqlite3Fts5ParserTOKENTYPE yyLookaheadToken  /* Value of the lookahead token */
991   sqlite3Fts5ParserCTX_PDECL                   /* %extra_context */
992 ){
993   int yygoto;                     /* The next state */
994   YYACTIONTYPE yyact;             /* The next action */
995   yyStackEntry *yymsp;            /* The top of the parser's stack */
996   int yysize;                     /* Amount to pop the stack */
997   sqlite3Fts5ParserARG_FETCH
998   (void)yyLookahead;
999   (void)yyLookaheadToken;
1000   yymsp = yypParser->yytos;
1001 
1002   switch( yyruleno ){
1003   /* Beginning here are the reduction cases.  A typical example
1004   ** follows:
1005   **   case 0:
1006   **  #line <lineno> <grammarfile>
1007   **     { ... }           // User supplied code
1008   **  #line <lineno> <thisfile>
1009   **     break;
1010   */
1011 /********** Begin reduce actions **********************************************/
1012         YYMINORTYPE yylhsminor;
1013       case 0: /* input ::= expr */
1014 #line 82 "fts5parse.y"
1015 { sqlite3Fts5ParseFinished(pParse, yymsp[0].minor.yy24); }
1016 #line 1016 "fts5parse.sql"
1017         break;
1018       case 1: /* colset ::= MINUS LCP colsetlist RCP */
1019 #line 97 "fts5parse.y"
1020 {
1021     yymsp[-3].minor.yy11 = sqlite3Fts5ParseColsetInvert(pParse, yymsp[-1].minor.yy11);
1022 }
1023 #line 1023 "fts5parse.sql"
1024         break;
1025       case 2: /* colset ::= LCP colsetlist RCP */
1026 #line 100 "fts5parse.y"
1027 { yymsp[-2].minor.yy11 = yymsp[-1].minor.yy11; }
1028 #line 1028 "fts5parse.sql"
1029         break;
1030       case 3: /* colset ::= STRING */
1031 #line 101 "fts5parse.y"
1032 {
1033   yylhsminor.yy11 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0);
1034 }
1035 #line 1035 "fts5parse.sql"
1036   yymsp[0].minor.yy11 = yylhsminor.yy11;
1037         break;
1038       case 4: /* colset ::= MINUS STRING */
1039 #line 104 "fts5parse.y"
1040 {
1041   yymsp[-1].minor.yy11 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0);
1042   yymsp[-1].minor.yy11 = sqlite3Fts5ParseColsetInvert(pParse, yymsp[-1].minor.yy11);
1043 }
1044 #line 1044 "fts5parse.sql"
1045         break;
1046       case 5: /* colsetlist ::= colsetlist STRING */
1047 #line 109 "fts5parse.y"
1048 {
1049   yylhsminor.yy11 = sqlite3Fts5ParseColset(pParse, yymsp[-1].minor.yy11, &yymsp[0].minor.yy0); }
1050 #line 1050 "fts5parse.sql"
1051   yymsp[-1].minor.yy11 = yylhsminor.yy11;
1052         break;
1053       case 6: /* colsetlist ::= STRING */
1054 #line 111 "fts5parse.y"
1055 {
1056   yylhsminor.yy11 = sqlite3Fts5ParseColset(pParse, 0, &yymsp[0].minor.yy0);
1057 }
1058 #line 1058 "fts5parse.sql"
1059   yymsp[0].minor.yy11 = yylhsminor.yy11;
1060         break;
1061       case 7: /* expr ::= expr AND expr */
1062 #line 115 "fts5parse.y"
1063 {
1064   yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, yymsp[-2].minor.yy24, yymsp[0].minor.yy24, 0);
1065 }
1066 #line 1066 "fts5parse.sql"
1067   yymsp[-2].minor.yy24 = yylhsminor.yy24;
1068         break;
1069       case 8: /* expr ::= expr OR expr */
1070 #line 118 "fts5parse.y"
1071 {
1072   yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, yymsp[-2].minor.yy24, yymsp[0].minor.yy24, 0);
1073 }
1074 #line 1074 "fts5parse.sql"
1075   yymsp[-2].minor.yy24 = yylhsminor.yy24;
1076         break;
1077       case 9: /* expr ::= expr NOT expr */
1078 #line 121 "fts5parse.y"
1079 {
1080   yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, yymsp[-2].minor.yy24, yymsp[0].minor.yy24, 0);
1081 }
1082 #line 1082 "fts5parse.sql"
1083   yymsp[-2].minor.yy24 = yylhsminor.yy24;
1084         break;
1085       case 10: /* expr ::= colset COLON LP expr RP */
1086 #line 125 "fts5parse.y"
1087 {
1088   sqlite3Fts5ParseSetColset(pParse, yymsp[-1].minor.yy24, yymsp[-4].minor.yy11);
1089   yylhsminor.yy24 = yymsp[-1].minor.yy24;
1090 }
1091 #line 1091 "fts5parse.sql"
1092   yymsp[-4].minor.yy24 = yylhsminor.yy24;
1093         break;
1094       case 11: /* expr ::= LP expr RP */
1095 #line 129 "fts5parse.y"
1096 {yymsp[-2].minor.yy24 = yymsp[-1].minor.yy24;}
1097 #line 1097 "fts5parse.sql"
1098         break;
1099       case 12: /* expr ::= exprlist */
1100       case 13: /* exprlist ::= cnearset */ yytestcase(yyruleno==13);
1101 #line 130 "fts5parse.y"
1102 {yylhsminor.yy24 = yymsp[0].minor.yy24;}
1103 #line 1103 "fts5parse.sql"
1104   yymsp[0].minor.yy24 = yylhsminor.yy24;
1105         break;
1106       case 14: /* exprlist ::= exprlist cnearset */
1107 #line 133 "fts5parse.y"
1108 {
1109   yylhsminor.yy24 = sqlite3Fts5ParseImplicitAnd(pParse, yymsp[-1].minor.yy24, yymsp[0].minor.yy24);
1110 }
1111 #line 1111 "fts5parse.sql"
1112   yymsp[-1].minor.yy24 = yylhsminor.yy24;
1113         break;
1114       case 15: /* cnearset ::= nearset */
1115 #line 137 "fts5parse.y"
1116 {
1117   yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, yymsp[0].minor.yy46);
1118 }
1119 #line 1119 "fts5parse.sql"
1120   yymsp[0].minor.yy24 = yylhsminor.yy24;
1121         break;
1122       case 16: /* cnearset ::= colset COLON nearset */
1123 #line 140 "fts5parse.y"
1124 {
1125   yylhsminor.yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, yymsp[0].minor.yy46);
1126   sqlite3Fts5ParseSetColset(pParse, yylhsminor.yy24, yymsp[-2].minor.yy11);
1127 }
1128 #line 1128 "fts5parse.sql"
1129   yymsp[-2].minor.yy24 = yylhsminor.yy24;
1130         break;
1131       case 17: /* nearset ::= phrase */
1132 #line 151 "fts5parse.y"
1133 { yylhsminor.yy46 = sqlite3Fts5ParseNearset(pParse, 0, yymsp[0].minor.yy53); }
1134 #line 1134 "fts5parse.sql"
1135   yymsp[0].minor.yy46 = yylhsminor.yy46;
1136         break;
1137       case 18: /* nearset ::= CARET phrase */
1138 #line 152 "fts5parse.y"
1139 {
1140   sqlite3Fts5ParseSetCaret(yymsp[0].minor.yy53);
1141   yymsp[-1].minor.yy46 = sqlite3Fts5ParseNearset(pParse, 0, yymsp[0].minor.yy53);
1142 }
1143 #line 1143 "fts5parse.sql"
1144         break;
1145       case 19: /* nearset ::= STRING LP nearphrases neardist_opt RP */
1146 #line 156 "fts5parse.y"
1147 {
1148   sqlite3Fts5ParseNear(pParse, &yymsp[-4].minor.yy0);
1149   sqlite3Fts5ParseSetDistance(pParse, yymsp[-2].minor.yy46, &yymsp[-1].minor.yy0);
1150   yylhsminor.yy46 = yymsp[-2].minor.yy46;
1151 }
1152 #line 1152 "fts5parse.sql"
1153   yymsp[-4].minor.yy46 = yylhsminor.yy46;
1154         break;
1155       case 20: /* nearphrases ::= phrase */
1156 #line 162 "fts5parse.y"
1157 {
1158   yylhsminor.yy46 = sqlite3Fts5ParseNearset(pParse, 0, yymsp[0].minor.yy53);
1159 }
1160 #line 1160 "fts5parse.sql"
1161   yymsp[0].minor.yy46 = yylhsminor.yy46;
1162         break;
1163       case 21: /* nearphrases ::= nearphrases phrase */
1164 #line 165 "fts5parse.y"
1165 {
1166   yylhsminor.yy46 = sqlite3Fts5ParseNearset(pParse, yymsp[-1].minor.yy46, yymsp[0].minor.yy53);
1167 }
1168 #line 1168 "fts5parse.sql"
1169   yymsp[-1].minor.yy46 = yylhsminor.yy46;
1170         break;
1171       case 22: /* neardist_opt ::= */
1172 #line 172 "fts5parse.y"
1173 { yymsp[1].minor.yy0.p = 0; yymsp[1].minor.yy0.n = 0; }
1174 #line 1174 "fts5parse.sql"
1175         break;
1176       case 23: /* neardist_opt ::= COMMA STRING */
1177 #line 173 "fts5parse.y"
1178 { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
1179 #line 1179 "fts5parse.sql"
1180         break;
1181       case 24: /* phrase ::= phrase PLUS STRING star_opt */
1182 #line 185 "fts5parse.y"
1183 {
1184   yylhsminor.yy53 = sqlite3Fts5ParseTerm(pParse, yymsp[-3].minor.yy53, &yymsp[-1].minor.yy0, yymsp[0].minor.yy4);
1185 }
1186 #line 1186 "fts5parse.sql"
1187   yymsp[-3].minor.yy53 = yylhsminor.yy53;
1188         break;
1189       case 25: /* phrase ::= STRING star_opt */
1190 #line 188 "fts5parse.y"
1191 {
1192   yylhsminor.yy53 = sqlite3Fts5ParseTerm(pParse, 0, &yymsp[-1].minor.yy0, yymsp[0].minor.yy4);
1193 }
1194 #line 1194 "fts5parse.sql"
1195   yymsp[-1].minor.yy53 = yylhsminor.yy53;
1196         break;
1197       case 26: /* star_opt ::= STAR */
1198 #line 196 "fts5parse.y"
1199 { yymsp[0].minor.yy4 = 1; }
1200 #line 1200 "fts5parse.sql"
1201         break;
1202       case 27: /* star_opt ::= */
1203 #line 197 "fts5parse.y"
1204 { yymsp[1].minor.yy4 = 0; }
1205 #line 1205 "fts5parse.sql"
1206         break;
1207       default:
1208         break;
1209 /********** End reduce actions ************************************************/
1210   };
1211   assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
1212   yygoto = yyRuleInfoLhs[yyruleno];
1213   yysize = yyRuleInfoNRhs[yyruleno];
1214   yyact = yy_find_reduce_action(yymsp[yysize].stateno,(YYCODETYPE)yygoto);
1215 
1216   /* There are no SHIFTREDUCE actions on nonterminals because the table
1217   ** generator has simplified them to pure REDUCE actions. */
1218   assert( !(yyact>YY_MAX_SHIFT && yyact<=YY_MAX_SHIFTREDUCE) );
1219 
1220   /* It is not possible for a REDUCE to be followed by an error */
1221   assert( yyact!=YY_ERROR_ACTION );
1222 
1223   yymsp += yysize+1;
1224   yypParser->yytos = yymsp;
1225   yymsp->stateno = (YYACTIONTYPE)yyact;
1226   yymsp->major = (YYCODETYPE)yygoto;
1227   yyTraceShift(yypParser, yyact, "... then shift");
1228   return yyact;
1229 }
1230 
1231 /*
1232 ** The following code executes when the parse fails
1233 */
1234 #ifndef YYNOERRORRECOVERY
1235 static void yy_parse_failed(
1236   yyParser *yypParser           /* The parser */
1237 ){
1238   sqlite3Fts5ParserARG_FETCH
1239   sqlite3Fts5ParserCTX_FETCH
1240 #ifndef NDEBUG
1241   if( yyTraceFILE ){
1242     fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
1243   }
1244 #endif
1245   while( yypParser->yytos>yypParser->yystack ) yy_pop_parser_stack(yypParser);
1246   /* Here code is inserted which will be executed whenever the
1247   ** parser fails */
1248 /************ Begin %parse_failure code ***************************************/
1249 /************ End %parse_failure code *****************************************/
1250   sqlite3Fts5ParserARG_STORE /* Suppress warning about unused %extra_argument variable */
1251   sqlite3Fts5ParserCTX_STORE
1252 }
1253 #endif /* YYNOERRORRECOVERY */
1254 
1255 /*
1256 ** The following code executes when a syntax error first occurs.
1257 */
1258 static void yy_syntax_error(
1259   yyParser *yypParser,           /* The parser */
1260   int yymajor,                   /* The major type of the error token */
1261   sqlite3Fts5ParserTOKENTYPE yyminor         /* The minor type of the error token */
1262 ){
1263   sqlite3Fts5ParserARG_FETCH
1264   sqlite3Fts5ParserCTX_FETCH
1265 #define TOKEN yyminor
1266 /************ Begin %syntax_error code ****************************************/
1267 #line 30 "fts5parse.y"
1268 
1269   UNUSED_PARAM(yymajor); /* Silence a compiler warning */
1270   sqlite3Fts5ParseError(
1271     pParse, "fts5: syntax error near \"%.*s\"",TOKEN.n,TOKEN.p
1272   );
1273 #line 1273 "fts5parse.sql"
1274 /************ End %syntax_error code ******************************************/
1275   sqlite3Fts5ParserARG_STORE /* Suppress warning about unused %extra_argument variable */
1276   sqlite3Fts5ParserCTX_STORE
1277 }
1278 
1279 /*
1280 ** The following is executed when the parser accepts
1281 */
1282 static void yy_accept(
1283   yyParser *yypParser           /* The parser */
1284 ){
1285   sqlite3Fts5ParserARG_FETCH
1286   sqlite3Fts5ParserCTX_FETCH
1287 #ifndef NDEBUG
1288   if( yyTraceFILE ){
1289     fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
1290   }
1291 #endif
1292 #ifndef YYNOERRORRECOVERY
1293   yypParser->yyerrcnt = -1;
1294 #endif
1295   assert( yypParser->yytos==yypParser->yystack );
1296   /* Here code is inserted which will be executed whenever the
1297   ** parser accepts */
1298 /*********** Begin %parse_accept code *****************************************/
1299 /*********** End %parse_accept code *******************************************/
1300   sqlite3Fts5ParserARG_STORE /* Suppress warning about unused %extra_argument variable */
1301   sqlite3Fts5ParserCTX_STORE
1302 }
1303 
1304 /* The main parser program.
1305 ** The first argument is a pointer to a structure obtained from
1306 ** "sqlite3Fts5ParserAlloc" which describes the current state of the parser.
1307 ** The second argument is the major token number.  The third is
1308 ** the minor token.  The fourth optional argument is whatever the
1309 ** user wants (and specified in the grammar) and is available for
1310 ** use by the action routines.
1311 **
1312 ** Inputs:
1313 ** <ul>
1314 ** <li> A pointer to the parser (an opaque structure.)
1315 ** <li> The major token number.
1316 ** <li> The minor token number.
1317 ** <li> An option argument of a grammar-specified type.
1318 ** </ul>
1319 **
1320 ** Outputs:
1321 ** None.
1322 */
1323 void sqlite3Fts5Parser(
1324   void *yyp,                   /* The parser */
1325   int yymajor,                 /* The major token code number */
1326   sqlite3Fts5ParserTOKENTYPE yyminor       /* The value for the token */
1327   sqlite3Fts5ParserARG_PDECL               /* Optional %extra_argument parameter */
1328 ){
1329   YYMINORTYPE yyminorunion;
1330   YYACTIONTYPE yyact;   /* The parser action. */
1331 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
1332   int yyendofinput;     /* True if we are at the end of input */
1333 #endif
1334 #ifdef YYERRORSYMBOL
1335   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
1336 #endif
1337   yyParser *yypParser = (yyParser*)yyp;  /* The parser */
1338   sqlite3Fts5ParserCTX_FETCH
1339   sqlite3Fts5ParserARG_STORE
1340 
1341   assert( yypParser->yytos!=0 );
1342 #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY)
1343   yyendofinput = (yymajor==0);
1344 #endif
1345 
1346   yyact = yypParser->yytos->stateno;
1347 #ifndef NDEBUG
1348   if( yyTraceFILE ){
1349     if( yyact < YY_MIN_REDUCE ){
1350       fprintf(yyTraceFILE,"%sInput '%s' in state %d\n",
1351               yyTracePrompt,yyTokenName[yymajor],yyact);
1352     }else{
1353       fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n",
1354               yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE);
1355     }
1356   }
1357 #endif
1358 
1359   while(1){ /* Exit by "break" */
1360     assert( yypParser->yytos>=yypParser->yystack );
1361     assert( yyact==yypParser->yytos->stateno );
1362     yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact);
1363     if( yyact >= YY_MIN_REDUCE ){
1364       unsigned int yyruleno = yyact - YY_MIN_REDUCE; /* Reduce by this rule */
1365 #ifndef NDEBUG
1366       assert( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) );
1367       if( yyTraceFILE ){
1368         int yysize = yyRuleInfoNRhs[yyruleno];
1369         if( yysize ){
1370           fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n",
1371             yyTracePrompt,
1372             yyruleno, yyRuleName[yyruleno],
1373             yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action",
1374             yypParser->yytos[yysize].stateno);
1375         }else{
1376           fprintf(yyTraceFILE, "%sReduce %d [%s]%s.\n",
1377             yyTracePrompt, yyruleno, yyRuleName[yyruleno],
1378             yyruleno<YYNRULE_WITH_ACTION ? "" : " without external action");
1379         }
1380       }
1381 #endif /* NDEBUG */
1382 
1383       /* Check that the stack is large enough to grow by a single entry
1384       ** if the RHS of the rule is empty.  This ensures that there is room
1385       ** enough on the stack to push the LHS value */
1386       if( yyRuleInfoNRhs[yyruleno]==0 ){
1387 #ifdef YYTRACKMAXSTACKDEPTH
1388         if( (int)(yypParser->yytos - yypParser->yystack)>yypParser->yyhwm ){
1389           yypParser->yyhwm++;
1390           assert( yypParser->yyhwm ==
1391                   (int)(yypParser->yytos - yypParser->yystack));
1392         }
1393 #endif
1394 #if YYSTACKDEPTH>0
1395         if( yypParser->yytos>=yypParser->yystackEnd ){
1396           yyStackOverflow(yypParser);
1397           break;
1398         }
1399 #else
1400         if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
1401           if( yyGrowStack(yypParser) ){
1402             yyStackOverflow(yypParser);
1403             break;
1404           }
1405         }
1406 #endif
1407       }
1408       yyact = yy_reduce(yypParser,yyruleno,yymajor,yyminor sqlite3Fts5ParserCTX_PARAM);
1409     }else if( yyact <= YY_MAX_SHIFTREDUCE ){
1410       yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor);
1411 #ifndef YYNOERRORRECOVERY
1412       yypParser->yyerrcnt--;
1413 #endif
1414       break;
1415     }else if( yyact==YY_ACCEPT_ACTION ){
1416       yypParser->yytos--;
1417       yy_accept(yypParser);
1418       return;
1419     }else{
1420       assert( yyact == YY_ERROR_ACTION );
1421       yyminorunion.yy0 = yyminor;
1422 #ifdef YYERRORSYMBOL
1423       int yymx;
1424 #endif
1425 #ifndef NDEBUG
1426       if( yyTraceFILE ){
1427         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
1428       }
1429 #endif
1430 #ifdef YYERRORSYMBOL
1431       /* A syntax error has occurred.
1432       ** The response to an error depends upon whether or not the
1433       ** grammar defines an error token "ERROR".
1434       **
1435       ** This is what we do if the grammar does define ERROR:
1436       **
1437       **  * Call the %syntax_error function.
1438       **
1439       **  * Begin popping the stack until we enter a state where
1440       **    it is legal to shift the error symbol, then shift
1441       **    the error symbol.
1442       **
1443       **  * Set the error count to three.
1444       **
1445       **  * Begin accepting and shifting new tokens.  No new error
1446       **    processing will occur until three tokens have been
1447       **    shifted successfully.
1448       **
1449       */
1450       if( yypParser->yyerrcnt<0 ){
1451         yy_syntax_error(yypParser,yymajor,yyminor);
1452       }
1453       yymx = yypParser->yytos->major;
1454       if( yymx==YYERRORSYMBOL || yyerrorhit ){
1455 #ifndef NDEBUG
1456         if( yyTraceFILE ){
1457           fprintf(yyTraceFILE,"%sDiscard input token %s\n",
1458              yyTracePrompt,yyTokenName[yymajor]);
1459         }
1460 #endif
1461         yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion);
1462         yymajor = YYNOCODE;
1463       }else{
1464         while( yypParser->yytos > yypParser->yystack ){
1465           yyact = yy_find_reduce_action(yypParser->yytos->stateno,
1466                                         YYERRORSYMBOL);
1467           if( yyact<=YY_MAX_SHIFTREDUCE ) break;
1468           yy_pop_parser_stack(yypParser);
1469         }
1470         if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){
1471           yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1472           yy_parse_failed(yypParser);
1473 #ifndef YYNOERRORRECOVERY
1474           yypParser->yyerrcnt = -1;
1475 #endif
1476           yymajor = YYNOCODE;
1477         }else if( yymx!=YYERRORSYMBOL ){
1478           yy_shift(yypParser,yyact,YYERRORSYMBOL,yyminor);
1479         }
1480       }
1481       yypParser->yyerrcnt = 3;
1482       yyerrorhit = 1;
1483       if( yymajor==YYNOCODE ) break;
1484       yyact = yypParser->yytos->stateno;
1485 #elif defined(YYNOERRORRECOVERY)
1486       /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
1487       ** do any kind of error recovery.  Instead, simply invoke the syntax
1488       ** error routine and continue going as if nothing had happened.
1489       **
1490       ** Applications can set this macro (for example inside %include) if
1491       ** they intend to abandon the parse upon the first syntax error seen.
1492       */
1493       yy_syntax_error(yypParser,yymajor, yyminor);
1494       yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1495       break;
1496 #else  /* YYERRORSYMBOL is not defined */
1497       /* This is what we do if the grammar does not define ERROR:
1498       **
1499       **  * Report an error message, and throw away the input token.
1500       **
1501       **  * If the input token is $, then fail the parse.
1502       **
1503       ** As before, subsequent error messages are suppressed until
1504       ** three input tokens have been successfully shifted.
1505       */
1506       if( yypParser->yyerrcnt<=0 ){
1507         yy_syntax_error(yypParser,yymajor, yyminor);
1508       }
1509       yypParser->yyerrcnt = 3;
1510       yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
1511       if( yyendofinput ){
1512         yy_parse_failed(yypParser);
1513 #ifndef YYNOERRORRECOVERY
1514         yypParser->yyerrcnt = -1;
1515 #endif
1516       }
1517       break;
1518 #endif
1519     }
1520   }
1521 #ifndef NDEBUG
1522   if( yyTraceFILE ){
1523     yyStackEntry *i;
1524     char cDiv = '[';
1525     fprintf(yyTraceFILE,"%sReturn. Stack=",yyTracePrompt);
1526     for(i=&yypParser->yystack[1]; i<=yypParser->yytos; i++){
1527       fprintf(yyTraceFILE,"%c%s", cDiv, yyTokenName[i->major]);
1528       cDiv = ' ';
1529     }
1530     fprintf(yyTraceFILE,"]\n");
1531   }
1532 #endif
1533   return;
1534 }
1535 
1536 /*
1537 ** Return the fallback token corresponding to canonical token iToken, or
1538 ** 0 if iToken has no fallback.
1539 */
1540 int sqlite3Fts5ParserFallback(int iToken){
1541 #ifdef YYFALLBACK
1542   assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) );
1543   return yyFallback[iToken];
1544 #else
1545   (void)iToken;
1546   return 0;
1547 #endif
1548 }
1549