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/options/context.h>
43 #include <libmemcached/options/string.h>
44 #include <libmemcached/options/symbol.h>
45 #include <libmemcached/visibility.h>
46 #include <libmemcached/prefix_key.h>
48 #pragma GCC diagnostic ignored "-Wold-style-cast"
49 #include <libmemcached/options/scanner.h>
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 AUTO_EJECT_HOSTS
79 %token BINARY_PROTOCOL
80 %token BUFFER_REQUESTS
81 %token CONNECT_TIMEOUT
84 %token HASH_WITH_PREFIX_KEY
85 %token IO_BYTES_WATERMARK
86 %token IO_KEY_PREFETCH
87 %token IO_MSG_WATERMARK
89 %token KETAMA_WEIGHTED
91 %token NUMBER_OF_REPLICAS
93 %token RANDOMIZE_REPLICA_READ
96 %token SERVER_FAILURE_LIMIT
98 %token SOCKET_RECV_SIZE
99 %token SOCKET_SEND_SIZE
103 %token _TCP_KEEPALIVE
129 %token <boolean> TRUE
130 %token <boolean> FALSE
135 %token <number> FLOAT
136 %token <number> NUMBER
139 %token <server> IPADDRESS
140 %token <server> HOSTNAME
141 %token <string> STRING
142 %token <string> QUOTED_STRING
143 %token <string> FILE_PATH
145 %type <string> string
146 %type <distribution> distribution
148 %type <behavior> behavior_boolean
149 %type <behavior> behavior_number
155 | begin ' ' statement
172 context->rc= MEMCACHED_PARSE_USER_ERROR;
173 parser_abort(context, NULL);
177 memcached_reset(context->memc);
185 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
187 parser_abort(context, NULL);
194 SERVER HOSTNAME optional_port optional_weight
196 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
198 parser_abort(context, NULL);
200 context->unset_server();
202 | SERVER IPADDRESS optional_port optional_weight
204 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
206 parser_abort(context, NULL);
208 context->unset_server();
210 | CONFIGURE_FILE string
212 memcached_set_configuration_file(context->memc, $2.c_str, $2.length);
220 if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
222 parser_abort(context, NULL);;
225 | DISTRIBUTION distribution
227 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
229 parser_abort(context, NULL);;
232 | DISTRIBUTION distribution ',' hash
234 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
236 parser_abort(context, NULL);;
238 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
240 parser_abort(context, NULL);;
245 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
247 parser_abort(context, NULL);;
250 | behavior_number NUMBER
252 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
254 parser_abort(context, NULL);;
259 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
261 parser_abort(context, NULL);;
272 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
276 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
280 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
284 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
288 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
292 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
296 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
300 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
302 | SERVER_FAILURE_LIMIT
304 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
308 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
312 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
316 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
323 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
327 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
331 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
333 | HASH_WITH_PREFIX_KEY
335 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
339 $$= MEMCACHED_BEHAVIOR_NOREPLY;
341 | RANDOMIZE_REPLICA_READ
343 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
347 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
351 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
355 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
359 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
363 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
367 $$= MEMCACHED_BEHAVIOR_USE_UDP;
371 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
390 $$= MEMCACHED_HASH_MD5;
394 $$= MEMCACHED_HASH_CRC;
398 $$= MEMCACHED_HASH_FNV1_64;
402 $$= MEMCACHED_HASH_FNV1A_64;
406 $$= MEMCACHED_HASH_FNV1_32;
410 $$= MEMCACHED_HASH_FNV1A_32;
414 $$= MEMCACHED_HASH_HSIEH;
418 $$= MEMCACHED_HASH_MURMUR;
422 $$= MEMCACHED_HASH_JENKINS;
433 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
434 $$.length= $1.length -1; // -1 removes the end quote
441 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
445 $$= MEMCACHED_DISTRIBUTION_MODULA;
449 $$= MEMCACHED_DISTRIBUTION_RANDOM;
455 void Context::start()
457 config_parse(this, (void **)scanner);