Fixes all current issues with hashkit tests.
[awesomized/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 CACHE_LOOKUPS
83 %token CONNECT_TIMEOUT
84 %token DISTRIBUTION
85 %token HASH
86 %token HASH_WITH_PREFIX_KEY
87 %token IO_BYTES_WATERMARK
88 %token IO_KEY_PREFETCH
89 %token IO_MSG_WATERMARK
90 %token KETAMA_HASH
91 %token KETAMA_WEIGHTED
92 %token NOREPLY
93 %token NUMBER_OF_REPLICAS
94 %token POLL_TIMEOUT
95 %token RANDOMIZE_REPLICA_READ
96 %token RCV_TIMEOUT
97 %token RETRY_TIMEOUT
98 %token SERVER_FAILURE_LIMIT
99 %token SND_TIMEOUT
100 %token SOCKET_RECV_SIZE
101 %token SOCKET_SEND_SIZE
102 %token SORT_HOSTS
103 %token SUPPORT_CAS
104 %token _TCP_NODELAY
105 %token _TCP_KEEPALIVE
106 %token _TCP_KEEPIDLE
107 %token USER_DATA
108 %token USE_UDP
109 %token VERIFY_KEY
110
111 /* Callbacks */
112 %token PREFIX_KEY
113
114 /* Hash types */
115 %token MD5
116 %token CRC
117 %token FNV1_64
118 %token FNV1A_64
119 %token FNV1_32
120 %token FNV1A_32
121 %token HSIEH
122 %token MURMUR
123 %token JENKINS
124
125 /* Distributions */
126 %token CONSISTENT
127 %token MODULA
128 %token RANDOM
129
130 /* Boolean values */
131 %token <boolean> TRUE
132 %token <boolean> FALSE
133
134 %nonassoc ','
135 %nonassoc '='
136
137 %token <number> NUMBER
138 %token <number> FLOAT
139 %token <string> HOSTNAME
140 %token <string> HOSTNAME_WITH_PORT
141 %token <string> IPADDRESS
142 %token <string> IPADDRESS_WITH_PORT
143 %token <string> STRING
144 %token <string> QUOTED_STRING
145 %token <string> FILE_PATH
146
147 %type <server> server
148 %type <string> string
149 %type <distribution> distribution
150 %type <hash> hash
151 %type <behavior> behavior_boolean
152 %type <behavior> behavior_number
153
154 %%
155
156 begin:
157 statement
158 | begin ' ' statement
159 ;
160
161 statement:
162 expression
163 { }
164 | COMMENT
165 { }
166 | EMPTY_LINE
167 { }
168 | END
169 {
170 context->set_end();
171 YYACCEPT;
172 }
173 | ERROR
174 {
175 context->rc= MEMCACHED_PARSE_USER_ERROR;
176 parser_abort(context, NULL);
177 }
178 | RESET
179 {
180 memcached_reset(context->memc);
181 }
182 | PARSER_DEBUG
183 {
184 yydebug= 1;
185 }
186 | INCLUDE ' ' string
187 {
188 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
189 {
190 parser_abort(context, NULL);
191 }
192 }
193 ;
194
195
196 expression:
197 SERVER server
198 {
199 if ((context->rc= memcached_server_add_parsed(context->memc, $2.c_str, $2.length, $2.port, 0)) != MEMCACHED_SUCCESS)
200 {
201 parser_abort(context, NULL);
202 }
203 }
204 | SERVERS_OPTION server_list
205 {
206 }
207 | CONFIGURE_FILE string
208 {
209 memcached_set_configuration_file(context->memc, $2.c_str, $2.length);
210 }
211 | behaviors
212 ;
213
214 behaviors:
215 PREFIX_KEY string
216 {
217 if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
218 {
219 parser_abort(context, NULL);;
220 }
221 }
222 | DISTRIBUTION distribution
223 {
224 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
225 {
226 parser_abort(context, NULL);;
227 }
228 }
229 | DISTRIBUTION distribution ',' hash
230 {
231 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
232 {
233 parser_abort(context, NULL);;
234 }
235 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
236 {
237 parser_abort(context, NULL);;
238 }
239 }
240 | HASH hash
241 {
242 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
243 {
244 parser_abort(context, NULL);;
245 }
246 }
247 | behavior_number NUMBER
248 {
249 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
250 {
251 parser_abort(context, NULL);;
252 }
253 }
254 | behavior_boolean
255 {
256 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
257 {
258 parser_abort(context, NULL);;
259 }
260 }
261 | USER_DATA
262 {
263 }
264 ;
265
266 behavior_number:
267 CONNECT_TIMEOUT
268 {
269 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
270 }
271 | IO_MSG_WATERMARK
272 {
273 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
274 }
275 | IO_BYTES_WATERMARK
276 {
277 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
278 }
279 | IO_KEY_PREFETCH
280 {
281 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
282 }
283 | NUMBER_OF_REPLICAS
284 {
285 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
286 }
287 | POLL_TIMEOUT
288 {
289 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
290 }
291 | RCV_TIMEOUT
292 {
293 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
294 }
295 | RETRY_TIMEOUT
296 {
297 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
298 }
299 | SERVER_FAILURE_LIMIT
300 {
301 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
302 }
303 | SND_TIMEOUT
304 {
305 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
306 }
307 | SOCKET_RECV_SIZE
308 {
309 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
310 }
311 | SOCKET_SEND_SIZE
312 {
313 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
314 }
315 ;
316
317 behavior_boolean:
318 AUTO_EJECT_HOSTS
319 {
320 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
321 }
322 | BINARY_PROTOCOL
323 {
324 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
325 }
326 | BUFFER_REQUESTS
327 {
328 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
329 }
330 | CACHE_LOOKUPS
331 {
332 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
333 }
334 | HASH_WITH_PREFIX_KEY
335 {
336 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
337 }
338 | KETAMA_WEIGHTED
339 {
340 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
341 }
342 | NOREPLY
343 {
344 $$= MEMCACHED_BEHAVIOR_NOREPLY;
345 }
346 | RANDOMIZE_REPLICA_READ
347 {
348 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
349 }
350 | SORT_HOSTS
351 {
352 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
353 }
354 | SUPPORT_CAS
355 {
356 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
357 }
358 | _TCP_NODELAY
359 {
360 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
361 }
362 | _TCP_KEEPALIVE
363 {
364 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
365 }
366 | _TCP_KEEPIDLE
367 {
368 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
369 }
370 | USE_UDP
371 {
372 $$= MEMCACHED_BEHAVIOR_USE_UDP;
373 }
374 | VERIFY_KEY
375 {
376 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
377 }
378
379
380 server_list:
381 server
382 {
383 if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
384 {
385 parser_abort(context, NULL);;
386 }
387 }
388 | server_list ',' server
389 {
390 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
391 {
392 parser_abort(context, NULL);;
393 }
394 }
395 ;
396
397 server:
398 HOSTNAME_WITH_PORT NUMBER
399 {
400 $$.c_str= $1.c_str;
401 $$.length= $1.length -1; // -1 to remove :
402 $$.port= $2;
403 }
404 | HOSTNAME
405 {
406 $$.c_str= $1.c_str;
407 $$.length= $1.length;
408 $$.port= MEMCACHED_DEFAULT_PORT;
409 }
410 | STRING /* a match can be against "localhost" which is just a string */
411 {
412 $$.c_str= $1.c_str;
413 $$.length= $1.length;
414 $$.port= MEMCACHED_DEFAULT_PORT;
415 }
416 | IPADDRESS_WITH_PORT NUMBER
417 {
418 $$.c_str= $1.c_str;
419 $$.length= $1.length -1; // -1 to remove :
420 $$.port= $2;
421 }
422 | IPADDRESS
423 {
424 $$.c_str= $1.c_str;
425 $$.length= $1.length;
426 $$.port= MEMCACHED_DEFAULT_PORT;
427 }
428 ;
429
430 hash:
431 MD5
432 {
433 $$= MEMCACHED_HASH_MD5;
434 }
435 | CRC
436 {
437 $$= MEMCACHED_HASH_CRC;
438 }
439 | FNV1_64
440 {
441 $$= MEMCACHED_HASH_FNV1_64;
442 }
443 | FNV1A_64
444 {
445 $$= MEMCACHED_HASH_FNV1A_64;
446 }
447 | FNV1_32
448 {
449 $$= MEMCACHED_HASH_FNV1_32;
450 }
451 | FNV1A_32
452 {
453 $$= MEMCACHED_HASH_FNV1A_32;
454 }
455 | HSIEH
456 {
457 $$= MEMCACHED_HASH_HSIEH;
458 }
459 | MURMUR
460 {
461 $$= MEMCACHED_HASH_MURMUR;
462 }
463 | JENKINS
464 {
465 $$= MEMCACHED_HASH_JENKINS;
466 }
467 ;
468
469 string:
470 STRING
471 {
472 $$= $1;
473 }
474 | QUOTED_STRING
475 {
476 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
477 $$.length= $1.length -1; // -1 removes the end quote
478 }
479 ;
480
481 distribution:
482 CONSISTENT
483 {
484 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
485 }
486 | MODULA
487 {
488 $$= MEMCACHED_DISTRIBUTION_MODULA;
489 }
490 | RANDOM
491 {
492 $$= MEMCACHED_DISTRIBUTION_RANDOM;
493 }
494 ;
495
496 %%
497
498 void Context::start()
499 {
500 config_parse(this, (void **)scanner);
501 }
502