Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/sqlite/sqlite-src-3170000/ext/fts5/fts5parse.y

Issue 2747283002: [sql] Import reference version of SQLite 3.17.. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 ** 2014 May 31
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
10 **
11 ******************************************************************************
12 **
13 */
14
15
16 // All token codes are small integers with #defines that begin with "TK_"
17 %token_prefix FTS5_
18
19 // The type of the data attached to each token is Token. This is also the
20 // default type for non-terminals.
21 //
22 %token_type {Fts5Token}
23 %default_type {Fts5Token}
24
25 // The generated parser function takes a 4th argument as follows:
26 %extra_argument {Fts5Parse *pParse}
27
28 // This code runs whenever there is a syntax error
29 //
30 %syntax_error {
31 UNUSED_PARAM(yymajor); /* Silence a compiler warning */
32 sqlite3Fts5ParseError(
33 pParse, "fts5: syntax error near \"%.*s\"",TOKEN.n,TOKEN.p
34 );
35 }
36 %stack_overflow {
37 sqlite3Fts5ParseError(pParse, "fts5: parser stack overflow");
38 }
39
40 // The name of the generated procedure that implements the parser
41 // is as follows:
42 %name sqlite3Fts5Parser
43
44 // The following text is included near the beginning of the C source
45 // code file that implements the parser.
46 //
47 %include {
48 #include "fts5Int.h"
49 #include "fts5parse.h"
50
51 /*
52 ** Disable all error recovery processing in the parser push-down
53 ** automaton.
54 */
55 #define YYNOERRORRECOVERY 1
56
57 /*
58 ** Make yytestcase() the same as testcase()
59 */
60 #define yytestcase(X) testcase(X)
61
62 /*
63 ** Indicate that sqlite3ParserFree() will never be called with a null
64 ** pointer.
65 */
66 #define YYPARSEFREENOTNULL 1
67
68 /*
69 ** Alternative datatype for the argument to the malloc() routine passed
70 ** into sqlite3ParserAlloc(). The default is size_t.
71 */
72 #define YYMALLOCARGTYPE u64
73
74 } // end %include
75
76 %left OR.
77 %left AND.
78 %left NOT.
79 %left TERM.
80 %left COLON.
81
82 input ::= expr(X). { sqlite3Fts5ParseFinished(pParse, X); }
83 %destructor input { (void)pParse; }
84
85 %type cnearset {Fts5ExprNode*}
86 %type expr {Fts5ExprNode*}
87 %type exprlist {Fts5ExprNode*}
88 %destructor cnearset { sqlite3Fts5ParseNodeFree($$); }
89 %destructor expr { sqlite3Fts5ParseNodeFree($$); }
90 %destructor exprlist { sqlite3Fts5ParseNodeFree($$); }
91
92 expr(A) ::= expr(X) AND expr(Y). {
93 A = sqlite3Fts5ParseNode(pParse, FTS5_AND, X, Y, 0);
94 }
95 expr(A) ::= expr(X) OR expr(Y). {
96 A = sqlite3Fts5ParseNode(pParse, FTS5_OR, X, Y, 0);
97 }
98 expr(A) ::= expr(X) NOT expr(Y). {
99 A = sqlite3Fts5ParseNode(pParse, FTS5_NOT, X, Y, 0);
100 }
101
102 expr(A) ::= LP expr(X) RP. {A = X;}
103 expr(A) ::= exprlist(X). {A = X;}
104
105 exprlist(A) ::= cnearset(X). {A = X;}
106 exprlist(A) ::= exprlist(X) cnearset(Y). {
107 A = sqlite3Fts5ParseImplicitAnd(pParse, X, Y);
108 }
109
110 cnearset(A) ::= nearset(X). {
111 A = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, X);
112 }
113 cnearset(A) ::= colset(X) COLON nearset(Y). {
114 sqlite3Fts5ParseSetColset(pParse, Y, X);
115 A = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, Y);
116 }
117
118 %type colset {Fts5Colset*}
119 %destructor colset { sqlite3_free($$); }
120 %type colsetlist {Fts5Colset*}
121 %destructor colsetlist { sqlite3_free($$); }
122
123 colset(A) ::= MINUS LCP colsetlist(X) RCP. {
124 A = sqlite3Fts5ParseColsetInvert(pParse, X);
125 }
126 colset(A) ::= LCP colsetlist(X) RCP. { A = X; }
127 colset(A) ::= STRING(X). {
128 A = sqlite3Fts5ParseColset(pParse, 0, &X);
129 }
130 colset(A) ::= MINUS STRING(X). {
131 A = sqlite3Fts5ParseColset(pParse, 0, &X);
132 A = sqlite3Fts5ParseColsetInvert(pParse, A);
133 }
134
135 colsetlist(A) ::= colsetlist(Y) STRING(X). {
136 A = sqlite3Fts5ParseColset(pParse, Y, &X); }
137 colsetlist(A) ::= STRING(X). {
138 A = sqlite3Fts5ParseColset(pParse, 0, &X);
139 }
140
141 %type nearset {Fts5ExprNearset*}
142 %type nearphrases {Fts5ExprNearset*}
143 %destructor nearset { sqlite3Fts5ParseNearsetFree($$); }
144 %destructor nearphrases { sqlite3Fts5ParseNearsetFree($$); }
145
146 nearset(A) ::= phrase(X). { A = sqlite3Fts5ParseNearset(pParse, 0, X); }
147 nearset(A) ::= STRING(X) LP nearphrases(Y) neardist_opt(Z) RP. {
148 sqlite3Fts5ParseNear(pParse, &X);
149 sqlite3Fts5ParseSetDistance(pParse, Y, &Z);
150 A = Y;
151 }
152
153 nearphrases(A) ::= phrase(X). {
154 A = sqlite3Fts5ParseNearset(pParse, 0, X);
155 }
156 nearphrases(A) ::= nearphrases(X) phrase(Y). {
157 A = sqlite3Fts5ParseNearset(pParse, X, Y);
158 }
159
160 /*
161 ** The optional ", <integer>" at the end of the NEAR() arguments.
162 */
163 neardist_opt(A) ::= . { A.p = 0; A.n = 0; }
164 neardist_opt(A) ::= COMMA STRING(X). { A = X; }
165
166 /*
167 ** A phrase. A set of primitives connected by "+" operators. Examples:
168 **
169 ** "the" + "quick brown" + fo *
170 ** "the quick brown fo" *
171 ** the+quick+brown+fo*
172 */
173 %type phrase {Fts5ExprPhrase*}
174 %destructor phrase { sqlite3Fts5ParsePhraseFree($$); }
175
176 phrase(A) ::= phrase(X) PLUS STRING(Y) star_opt(Z). {
177 A = sqlite3Fts5ParseTerm(pParse, X, &Y, Z);
178 }
179 phrase(A) ::= STRING(Y) star_opt(Z). {
180 A = sqlite3Fts5ParseTerm(pParse, 0, &Y, Z);
181 }
182
183 /*
184 ** Optional "*" character.
185 */
186 %type star_opt {int}
187
188 star_opt(A) ::= STAR. { A = 1; }
189 star_opt(A) ::= . { A = 0; }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698