Add missing code.
[m6w6/libmemcached] / libmemcached / options / parser.yy
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached Scanner and Parser
4 *
5 * Copyright (C) 2011 DataDifferental, http://datadifferential.com
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 %error-verbose
22 %debug
23 %defines
24 %expect 0
25 %output "libmemcached/options/parser.cc"
26 %defines "libmemcached/options/parser.h"
27 %lex-param { yyscan_t *scanner }
28 %name-prefix="config_"
29 %parse-param { Context *context }
30 %parse-param { yyscan_t *scanner }
31 %pure-parser
32 %require "2.2"
33 %start begin
34 %verbose
35
36 %{
37
38 #include <config.h>
39
40 #include <stdint.h>
41
42 #include <libmemcached/options/context.h>
43 #include <libmemcached/options/build.h>
44 #include <libmemcached/options/string.h>
45 #include <libmemcached/options/symbol.h>
46 #include <libmemcached/visibility.h>
47 #include <libmemcached/prefix_key.h>
48
49 #pragma GCC diagnostic ignored "-Wold-style-cast"
50 #include <libmemcached/options/scanner.h>
51
52 int conf_lex(YYSTYPE* lvalp, void* scanner);
53
54 #define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0)
55
56 inline void config_error(Context *context, yyscan_t *scanner, const char *error)
57 {
58 if (not context->end())
59 parser::abort_func(context, error);
60 }
61
62 %}
63
64 %token COMMENT
65 %token END
66 %token ERROR
67 %token RESET
68 %token PARSER_DEBUG
69 %token INCLUDE
70 %token CONFIGURE_FILE
71 %token EMPTY_LINE
72 %token SERVER
73 %token SERVERS
74 %token SERVERS_OPTION
75 %token UNKNOWN_OPTION
76 %token UNKNOWN
77
78 /* All behavior options */
79 %token AUTO_EJECT_HOSTS
80 %token BINARY_PROTOCOL
81 %token BUFFER_REQUESTS
82 %token CONNECT_TIMEOUT
83 %token DISTRIBUTION
84 %token HASH
85 %token HASH_WITH_PREFIX_KEY
86 %token IO_BYTES_WATERMARK
87 %token IO_KEY_PREFETCH
88 %token IO_MSG_WATERMARK
89 %token KETAMA_HASH
90 %token KETAMA_WEIGHTED
91 %token NOREPLY
92 %token NUMBER_OF_REPLICAS
93 %token POLL_TIMEOUT
94 %token RANDOMIZE_REPLICA_READ
95 %token RCV_TIMEOUT
96 %token RETRY_TIMEOUT
97 %token SERVER_FAILURE_LIMIT
98 %token SND_TIMEOUT
99 %token SOCKET_RECV_SIZE
100 %token SOCKET_SEND_SIZE
101 %token SORT_HOSTS
102 %token SUPPORT_CAS
103 %token _TCP_NODELAY
104 %token _TCP_KEEPALIVE
105 %token _TCP_KEEPIDLE
106 %token USER_DATA
107 %token USE_UDP
108 %token VERIFY_KEY
109
110 /* Callbacks */
111 %token PREFIX_KEY
112
113 /* Hash types */
114 %token MD5
115 %token CRC
116 %token FNV1_64
117 %token FNV1A_64
118 %token FNV1_32
119 %token FNV1A_32
120 %token HSIEH
121 %token MURMUR
122 %token JENKINS
123
124 /* Distributions */
125 %token CONSISTENT
126 %token MODULA
127 %token RANDOM
128
129 /* Boolean values */
130 %token <boolean> TRUE
131 %token <boolean> FALSE
132
133 %nonassoc ','
134 %nonassoc '='
135
136 %token <number> FLOAT
137 %token <number> NUMBER
138 %token PORT
139 %token WEIGHT_START
140 %token <server> IPADDRESS
141 %token <server> HOSTNAME
142 %token <string> STRING
143 %token <string> QUOTED_STRING
144 %token <string> FILE_PATH
145
146 %type <string> string
147 %type <distribution> distribution
148 %type <hash> hash
149 %type <behavior> behavior_boolean
150 %type <behavior> behavior_number
151
152 %%
153
154 begin:
155 statement
156 | begin ' ' statement
157 ;
158
159 statement:
160 expression
161 { }
162 | COMMENT
163 { }
164 | EMPTY_LINE
165 { }
166 | END
167 {
168 context->set_end();
169 YYACCEPT;
170 }
171 | ERROR
172 {
173 context->rc= MEMCACHED_PARSE_USER_ERROR;
174 parser_abort(context, NULL);
175 }
176 | RESET
177 {
178 memcached_reset(context->memc);
179 }
180 | PARSER_DEBUG
181 {
182 yydebug= 1;
183 }
184 | INCLUDE ' ' string
185 {
186 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
187 {
188 parser_abort(context, NULL);
189 }
190 }
191 ;
192
193
194 expression:
195 SERVER HOSTNAME optional_port optional_weight
196 {
197 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
198 {
199 parser_abort(context, NULL);
200 }
201 context->unset_server();
202 }
203 | SERVER IPADDRESS optional_port optional_weight
204 {
205 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
206 {
207 parser_abort(context, NULL);
208 }
209 context->unset_server();
210 }
211 | CONFIGURE_FILE string
212 {
213 memcached_set_configuration_file(context->memc, $2.c_str, $2.length);
214 }
215 | behaviors
216 ;
217
218 behaviors:
219 PREFIX_KEY string
220 {
221 if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
222 {
223 parser_abort(context, NULL);;
224 }
225 }
226 | DISTRIBUTION distribution
227 {
228 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
229 {
230 parser_abort(context, NULL);;
231 }
232 }
233 | DISTRIBUTION distribution ',' hash
234 {
235 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
236 {
237 parser_abort(context, NULL);;
238 }
239 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
240 {
241 parser_abort(context, NULL);;
242 }
243 }
244 | HASH hash
245 {
246 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
247 {
248 parser_abort(context, NULL);;
249 }
250 }
251 | behavior_number NUMBER
252 {
253 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
254 {
255 parser_abort(context, NULL);;
256 }
257 }
258 | behavior_boolean
259 {
260 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
261 {
262 parser_abort(context, NULL);;
263 }
264 }
265 | USER_DATA
266 {
267 }
268 ;
269
270 behavior_number:
271 CONNECT_TIMEOUT
272 {
273 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
274 }
275 | IO_MSG_WATERMARK
276 {
277 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
278 }
279 | IO_BYTES_WATERMARK
280 {
281 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
282 }
283 | IO_KEY_PREFETCH
284 {
285 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
286 }
287 | NUMBER_OF_REPLICAS
288 {
289 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
290 }
291 | POLL_TIMEOUT
292 {
293 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
294 }
295 | RCV_TIMEOUT
296 {
297 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
298 }
299 | RETRY_TIMEOUT
300 {
301 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
302 }
303 | SERVER_FAILURE_LIMIT
304 {
305 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
306 }
307 | SND_TIMEOUT
308 {
309 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
310 }
311 | SOCKET_RECV_SIZE
312 {
313 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
314 }
315 | SOCKET_SEND_SIZE
316 {
317 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
318 }
319 ;
320
321 behavior_boolean:
322 AUTO_EJECT_HOSTS
323 {
324 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
325 }
326 | BINARY_PROTOCOL
327 {
328 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
329 }
330 | BUFFER_REQUESTS
331 {
332 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
333 }
334 | HASH_WITH_PREFIX_KEY
335 {
336 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
337 }
338 | NOREPLY
339 {
340 $$= MEMCACHED_BEHAVIOR_NOREPLY;
341 }
342 | RANDOMIZE_REPLICA_READ
343 {
344 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
345 }
346 | SORT_HOSTS
347 {
348 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
349 }
350 | SUPPORT_CAS
351 {
352 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
353 }
354 | _TCP_NODELAY
355 {
356 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
357 }
358 | _TCP_KEEPALIVE
359 {
360 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
361 }
362 | _TCP_KEEPIDLE
363 {
364 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
365 }
366 | USE_UDP
367 {
368 $$= MEMCACHED_BEHAVIOR_USE_UDP;
369 }
370 | VERIFY_KEY
371 {
372 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
373 }
374
375
376 optional_port:
377 { }
378 | PORT
379 { };
380 ;
381
382 optional_weight:
383 { }
384 | WEIGHT_START
385 { }
386 ;
387
388 hash:
389 MD5
390 {
391 $$= MEMCACHED_HASH_MD5;
392 }
393 | CRC
394 {
395 $$= MEMCACHED_HASH_CRC;
396 }
397 | FNV1_64
398 {
399 $$= MEMCACHED_HASH_FNV1_64;
400 }
401 | FNV1A_64
402 {
403 $$= MEMCACHED_HASH_FNV1A_64;
404 }
405 | FNV1_32
406 {
407 $$= MEMCACHED_HASH_FNV1_32;
408 }
409 | FNV1A_32
410 {
411 $$= MEMCACHED_HASH_FNV1A_32;
412 }
413 | HSIEH
414 {
415 $$= MEMCACHED_HASH_HSIEH;
416 }
417 | MURMUR
418 {
419 $$= MEMCACHED_HASH_MURMUR;
420 }
421 | JENKINS
422 {
423 $$= MEMCACHED_HASH_JENKINS;
424 }
425 ;
426
427 string:
428 STRING
429 {
430 $$= $1;
431 }
432 | QUOTED_STRING
433 {
434 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
435 $$.length= $1.length -1; // -1 removes the end quote
436 }
437 ;
438
439 distribution:
440 CONSISTENT
441 {
442 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
443 }
444 | MODULA
445 {
446 $$= MEMCACHED_DISTRIBUTION_MODULA;
447 }
448 | RANDOM
449 {
450 $$= MEMCACHED_DISTRIBUTION_RANDOM;
451 }
452 ;
453
454 %%
455
456 void Context::start()
457 {
458 config_parse(this, (void **)scanner);
459 }
460