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>
49 #pragma GCC diagnostic ignored "-Wold-style-cast"
51 int conf_lex(YYSTYPE* lvalp, void* scanner);
53 #define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0)
55 inline void config_error(Context *context, yyscan_t *scanner, const char *error)
57 if (not context->end())
58 context->abort(error);
77 /* All behavior options */
78 %token BINARY_PROTOCOL
79 %token BUFFER_REQUESTS
80 %token CONNECT_TIMEOUT
83 %token HASH_WITH_NAMESPACE
84 %token IO_BYTES_WATERMARK
85 %token IO_KEY_PREFETCH
86 %token IO_MSG_WATERMARK
88 %token KETAMA_WEIGHTED
90 %token NUMBER_OF_REPLICAS
92 %token RANDOMIZE_REPLICA_READ
94 %token REMOVE_FAILED_SERVERS
97 %token SOCKET_RECV_SIZE
98 %token SOCKET_SEND_SIZE
104 %token _TCP_KEEPALIVE
132 %token <boolean> TRUE
133 %token <boolean> FALSE
138 %token <number> FLOAT
139 %token <number> NUMBER
141 %token <number> WEIGHT_START
142 %token <server> IPADDRESS
143 %token <server> HOSTNAME
144 %token <string> STRING
145 %token <string> QUOTED_STRING
146 %token <string> FILE_PATH
148 %type <behavior> behavior_boolean
149 %type <behavior> behavior_number
150 %type <distribution> distribution
152 %type <number> optional_port
153 %type <number> optional_weight
154 %type <string> string
160 | begin ' ' statement
177 context->rc= MEMCACHED_PARSE_USER_ERROR;
178 parser_abort(context, NULL);
182 memcached_reset(context->memc);
190 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
192 parser_abort(context, NULL);
199 SERVER HOSTNAME optional_port optional_weight
201 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
203 parser_abort(context, NULL);
205 context->unset_server();
207 | SERVER IPADDRESS optional_port optional_weight
209 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
211 parser_abort(context, NULL);
213 context->unset_server();
215 | CONFIGURE_FILE string
217 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
221 context->memc->configure.initial_pool_size= $2;
225 context->memc->configure.max_pool_size= $2;
233 if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
235 parser_abort(context, NULL);;
238 | DISTRIBUTION distribution
240 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
242 parser_abort(context, NULL);;
245 | DISTRIBUTION distribution ',' hash
247 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
249 parser_abort(context, NULL);;
251 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
253 parser_abort(context, NULL);;
258 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
260 parser_abort(context, NULL);;
263 | behavior_number NUMBER
265 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
267 parser_abort(context, NULL);;
272 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
274 parser_abort(context, NULL);;
283 REMOVE_FAILED_SERVERS
285 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
289 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
293 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
297 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
301 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
305 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
309 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
313 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
317 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
321 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
325 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
329 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
336 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
340 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
342 | HASH_WITH_NAMESPACE
344 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
348 $$= MEMCACHED_BEHAVIOR_NOREPLY;
350 | RANDOMIZE_REPLICA_READ
352 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
356 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
360 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
364 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
368 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
372 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
376 $$= MEMCACHED_BEHAVIOR_USE_UDP;
380 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
385 { $$= MEMCACHED_DEFAULT_PORT;}
399 $$= MEMCACHED_HASH_MD5;
403 $$= MEMCACHED_HASH_CRC;
407 $$= MEMCACHED_HASH_FNV1_64;
411 $$= MEMCACHED_HASH_FNV1A_64;
415 $$= MEMCACHED_HASH_FNV1_32;
419 $$= MEMCACHED_HASH_FNV1A_32;
423 $$= MEMCACHED_HASH_HSIEH;
427 $$= MEMCACHED_HASH_MURMUR;
431 $$= MEMCACHED_HASH_JENKINS;
442 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
443 $$.size= $1.size -2; // -2 removes the begin and end quote
450 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
454 $$= MEMCACHED_DISTRIBUTION_MODULA;
458 $$= MEMCACHED_DISTRIBUTION_RANDOM;
464 void Context::start()
466 config_parse(this, (void **)scanner);