1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Libmemcached Scanner and Parser
5 * Copyright (C) 2011 DataDifferental, http://datadifferential.com
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.
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.
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/>.
25 %output "libmemcached/options/parser.cc"
26 %defines "libmemcached/options/parser.h"
27 %lex-param { yyscan_t *scanner }
28 %name-prefix="libmemcached_"
29 %parse-param { Context *context }
30 %parse-param { yyscan_t *scanner }
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>
49 #pragma GCC diagnostic ignored "-Wold-style-cast"
50 #include <libmemcached/options/scanner.h>
52 int libmemcached_lex(YYSTYPE* lvalp, void* scanner);
54 #define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0)
56 inline void libmemcached_error(Context *context, yyscan_t *scanner, const char *error)
58 if (not context->end())
59 parser::abort_func(context, error);
62 int libmemcached_parse(Context*, yyscan_t *);
65 libmemcached_parse(this, scanner);
84 /* All behavior options */
85 %token AUTO_EJECT_HOSTS
86 %token BINARY_PROTOCOL
87 %token BUFFER_REQUESTS
89 %token CONNECT_TIMEOUT
93 %token HASH_WITH_PREFIX_KEY
94 %token IO_BYTES_WATERMARK
95 %token IO_KEY_PREFETCH
96 %token IO_MSG_WATERMARK
99 %token KETAMA_WEIGHTED
101 %token NUMBER_OF_REPLICAS
103 %token RANDOMIZE_REPLICA_READ
106 %token SERVER_FAILURE_LIMIT
108 %token SOCKET_RECV_SIZE
109 %token SOCKET_SEND_SIZE
113 %token _TCP_KEEPALIVE
139 %token <boolean> TRUE
140 %token <boolean> FALSE
145 %token <number> NUMBER
146 %token <number> FLOAT
147 %token <string> HOSTNAME
148 %token <string> HOSTNAME_WITH_PORT
149 %token <string> IPADDRESS
150 %token <string> IPADDRESS_WITH_PORT
151 %token <string> STRING
152 %token <string> QUOTED_STRING
153 %token <string> FILE_PATH
155 %type <server> server
156 %type <string> string
157 %type <distribution> distribution
159 %type <behavior> behavior_boolean
160 %type <behavior> behavior_number
166 | begin ' ' statement
183 context->rc= MEMCACHED_PARSE_USER_ERROR;
184 parser_abort(context, NULL);
188 memcached_reset(context->memc);
196 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
198 parser_abort(context, NULL);
207 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
209 parser_abort(context, NULL);
212 | SERVERS_OPTION '=' server_list
215 | CONFIGURE_FILE '=' string
217 memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
223 PREFIX_KEY '=' string
225 if ((context->rc= memcached_set_prefix_key(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
227 parser_abort(context, NULL);;
230 | DISTRIBUTION '=' distribution
232 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
234 parser_abort(context, NULL);;
239 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
241 parser_abort(context, NULL);;
244 | KETAMA_HASH '=' hash
246 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
248 parser_abort(context, NULL);;
251 | behavior_number '=' NUMBER
253 if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
255 parser_abort(context, NULL);;
260 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
262 parser_abort(context, NULL);;
273 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
277 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
281 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
285 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
289 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
293 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
297 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
301 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
303 | SERVER_FAILURE_LIMIT
305 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
309 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
313 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
317 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
324 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
328 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
332 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
336 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
340 $$= MEMCACHED_BEHAVIOR_CORK;
342 | HASH_WITH_PREFIX_KEY
344 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
348 $$= MEMCACHED_BEHAVIOR_KETAMA;
352 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
356 $$= MEMCACHED_BEHAVIOR_NOREPLY;
358 | RANDOMIZE_REPLICA_READ
360 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
364 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
368 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
372 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
376 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
380 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
384 $$= MEMCACHED_BEHAVIOR_USE_UDP;
388 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
395 if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
397 parser_abort(context, NULL);;
400 | server_list ',' server
402 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
404 parser_abort(context, NULL);;
410 HOSTNAME_WITH_PORT NUMBER
413 $$.length= $1.length -1; // -1 to remove :
419 $$.length= $1.length;
420 $$.port= MEMCACHED_DEFAULT_PORT;
422 | STRING /* a match can be against "localhost" which is just a string */
425 $$.length= $1.length;
426 $$.port= MEMCACHED_DEFAULT_PORT;
428 | IPADDRESS_WITH_PORT NUMBER
431 $$.length= $1.length -1; // -1 to remove :
437 $$.length= $1.length;
438 $$.port= MEMCACHED_DEFAULT_PORT;
445 $$= MEMCACHED_HASH_MD5;
449 $$= MEMCACHED_HASH_CRC;
453 $$= MEMCACHED_HASH_FNV1_64;
457 $$= MEMCACHED_HASH_FNV1A_64;
461 $$= MEMCACHED_HASH_FNV1_32;
465 $$= MEMCACHED_HASH_FNV1A_32;
469 $$= MEMCACHED_HASH_HSIEH;
473 $$= MEMCACHED_HASH_MURMUR;
477 $$= MEMCACHED_HASH_JENKINS;
488 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
489 $$.length= $1.length -1; // -1 removes the end quote
496 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
500 $$= MEMCACHED_DISTRIBUTION_MODULA;
504 $$= MEMCACHED_DISTRIBUTION_RANDOM;