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="config_"
29 %parse-param { Context *context }
30 %parse-param { yyscan_t *scanner }
38 #include <libmemcached/common.h>
39 #include <libmemcached/options.hpp>
41 #include <libmemcached/options/context.h>
42 #include <libmemcached/options/symbol.h>
43 #include <libmemcached/options/scanner.h>
47 #pragma GCC diagnostic ignored "-Wold-style-cast"
49 int conf_lex(YYSTYPE* lvalp, void* scanner);
51 #define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0)
53 inline void config_error(Context *context, yyscan_t *scanner, const char *error)
55 if (not context->end())
56 context->abort(error);
76 /* All behavior options */
77 %token BINARY_PROTOCOL
78 %token BUFFER_REQUESTS
79 %token CONNECT_TIMEOUT
82 %token HASH_WITH_NAMESPACE
83 %token IO_BYTES_WATERMARK
84 %token IO_KEY_PREFETCH
85 %token IO_MSG_WATERMARK
87 %token KETAMA_WEIGHTED
89 %token NUMBER_OF_REPLICAS
91 %token RANDOMIZE_REPLICA_READ
93 %token REMOVE_FAILED_SERVERS
96 %token SOCKET_RECV_SIZE
97 %token SOCKET_SEND_SIZE
103 %token _TCP_KEEPALIVE
131 %token <boolean> TRUE
132 %token <boolean> FALSE
137 %token <number> FLOAT
138 %token <number> NUMBER
140 %token <number> WEIGHT_START
141 %token <server> IPADDRESS
142 %token <server> HOSTNAME
143 %token <string> STRING
144 %token <string> QUOTED_STRING
145 %token <string> FILE_PATH
147 %type <behavior> behavior_boolean
148 %type <behavior> behavior_number
149 %type <distribution> distribution
151 %type <number> optional_port
152 %type <number> optional_weight
153 %type <string> string
159 | begin ' ' statement
176 context->rc= MEMCACHED_PARSE_USER_ERROR;
177 parser_abort(context, NULL);
181 memcached_reset(context->memc);
189 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
191 parser_abort(context, NULL);
198 SERVER HOSTNAME optional_port optional_weight
200 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
202 parser_abort(context, NULL);
204 context->unset_server();
206 | SERVER IPADDRESS optional_port optional_weight
208 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
210 parser_abort(context, NULL);
212 context->unset_server();
214 | SOCKET string optional_weight
216 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3)))
218 parser_abort(context, NULL);
221 | CONFIGURE_FILE string
223 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
227 context->memc->configure.initial_pool_size= $2;
231 context->memc->configure.max_pool_size= $2;
239 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
241 parser_abort(context, NULL);;
244 | DISTRIBUTION distribution
246 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
248 parser_abort(context, NULL);;
251 | DISTRIBUTION distribution ',' hash
253 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
255 parser_abort(context, NULL);;
257 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
259 parser_abort(context, NULL);;
264 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
266 parser_abort(context, NULL);;
269 | behavior_number NUMBER
271 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
273 parser_abort(context, NULL);;
278 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
280 parser_abort(context, NULL);;
289 REMOVE_FAILED_SERVERS
291 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
295 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
299 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
303 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
307 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
311 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
315 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
319 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
323 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
327 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
331 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
335 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
342 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
346 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
348 | HASH_WITH_NAMESPACE
350 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
354 $$= MEMCACHED_BEHAVIOR_NOREPLY;
356 | RANDOMIZE_REPLICA_READ
358 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
362 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
366 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
370 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
374 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
378 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
382 $$= MEMCACHED_BEHAVIOR_USE_UDP;
386 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
391 { $$= MEMCACHED_DEFAULT_PORT;}
405 $$= MEMCACHED_HASH_MD5;
409 $$= MEMCACHED_HASH_CRC;
413 $$= MEMCACHED_HASH_FNV1_64;
417 $$= MEMCACHED_HASH_FNV1A_64;
421 $$= MEMCACHED_HASH_FNV1_32;
425 $$= MEMCACHED_HASH_FNV1A_32;
429 $$= MEMCACHED_HASH_HSIEH;
433 $$= MEMCACHED_HASH_MURMUR;
437 $$= MEMCACHED_HASH_JENKINS;
450 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
451 $$.size= $1.size -2; // -2 removes the begin and end quote
459 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
463 $$= MEMCACHED_DISTRIBUTION_MODULA;
467 $$= MEMCACHED_DISTRIBUTION_RANDOM;
473 void Context::start()
475 config_parse(this, (void **)scanner);