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 }
42 #include <libmemcached/common.h>
43 #include <libmemcached/options.hpp>
45 #include <libmemcached/options/context.h>
46 #include <libmemcached/options/symbol.h>
47 #include <libmemcached/options/scanner.h>
51 #pragma GCC diagnostic ignored "-Wold-style-cast"
53 int conf_lex(YYSTYPE* lvalp, void* scanner);
55 #define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0)
57 inline void config_error(Context *context, yyscan_t *scanner, const char *error)
59 if (not context->end())
60 context->abort(error);
80 /* All behavior options */
81 %token BINARY_PROTOCOL
82 %token BUFFER_REQUESTS
83 %token CONNECT_TIMEOUT
86 %token HASH_WITH_NAMESPACE
87 %token IO_BYTES_WATERMARK
88 %token IO_KEY_PREFETCH
89 %token IO_MSG_WATERMARK
91 %token KETAMA_WEIGHTED
93 %token NUMBER_OF_REPLICAS
95 %token RANDOMIZE_REPLICA_READ
97 %token REMOVE_FAILED_SERVERS
100 %token SOCKET_RECV_SIZE
101 %token SOCKET_SEND_SIZE
107 %token _TCP_KEEPALIVE
135 %token <boolean> TRUE
136 %token <boolean> FALSE
141 %token <number> FLOAT
142 %token <number> NUMBER
144 %token <number> WEIGHT_START
145 %token <server> IPADDRESS
146 %token <server> HOSTNAME
147 %token <string> STRING
148 %token <string> QUOTED_STRING
149 %token <string> FILE_PATH
151 %type <behavior> behavior_boolean
152 %type <behavior> behavior_number
153 %type <distribution> distribution
155 %type <number> optional_port
156 %type <number> optional_weight
157 %type <string> string
163 | begin ' ' statement
180 context->rc= MEMCACHED_PARSE_USER_ERROR;
181 parser_abort(context, NULL);
185 memcached_reset(context->memc);
193 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
195 parser_abort(context, NULL);
202 SERVER HOSTNAME optional_port optional_weight
204 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
206 parser_abort(context, NULL);
208 context->unset_server();
210 | SERVER IPADDRESS optional_port optional_weight
212 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
214 parser_abort(context, NULL);
216 context->unset_server();
218 | SOCKET string optional_weight
220 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3)))
222 parser_abort(context, NULL);
225 | CONFIGURE_FILE string
227 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
231 context->memc->configure.initial_pool_size= $2;
235 context->memc->configure.max_pool_size= $2;
243 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
245 parser_abort(context, NULL);;
248 | DISTRIBUTION distribution
250 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
252 parser_abort(context, NULL);;
255 | DISTRIBUTION distribution ',' hash
257 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
259 parser_abort(context, NULL);;
261 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
263 parser_abort(context, NULL);;
268 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
270 parser_abort(context, NULL);;
273 | behavior_number NUMBER
275 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
277 parser_abort(context, NULL);;
282 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
284 parser_abort(context, NULL);;
293 REMOVE_FAILED_SERVERS
295 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
299 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
303 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
307 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
311 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
315 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
319 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
323 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
327 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
331 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
335 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
339 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
346 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
350 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
352 | HASH_WITH_NAMESPACE
354 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
358 $$= MEMCACHED_BEHAVIOR_NOREPLY;
360 | RANDOMIZE_REPLICA_READ
362 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
366 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
370 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
374 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
378 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
382 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
386 $$= MEMCACHED_BEHAVIOR_USE_UDP;
390 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
395 { $$= MEMCACHED_DEFAULT_PORT;}
409 $$= MEMCACHED_HASH_MD5;
413 $$= MEMCACHED_HASH_CRC;
417 $$= MEMCACHED_HASH_FNV1_64;
421 $$= MEMCACHED_HASH_FNV1A_64;
425 $$= MEMCACHED_HASH_FNV1_32;
429 $$= MEMCACHED_HASH_FNV1A_32;
433 $$= MEMCACHED_HASH_HSIEH;
437 $$= MEMCACHED_HASH_MURMUR;
441 $$= MEMCACHED_HASH_JENKINS;
454 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
455 $$.size= $1.size -2; // -2 removes the begin and end quote
463 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
467 $$= MEMCACHED_DISTRIBUTION_MODULA;
471 $$= MEMCACHED_DISTRIBUTION_RANDOM;
477 void Context::start()
479 config_parse(this, (void **)scanner);