1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Configure Scripting Language
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/csl/parser.cc"
26 %defines "libmemcached/csl/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/csl/common.h>
39 #include <libmemcached/options.hpp>
41 #include <libmemcached/csl/context.h>
42 #include <libmemcached/csl/symbol.h>
43 #include <libmemcached/csl/scanner.h>
45 #pragma GCC diagnostic ignored "-Wold-style-cast"
47 int conf_lex(YYSTYPE* lvalp, void* scanner);
49 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
51 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
53 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
55 // This is bison calling error.
56 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
58 if (not context->end())
60 context->error(error, yytokentype(last_token), last_token_str);
64 context->error(error, yytokentype(last_token), last_token_str);
68 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
88 /* All behavior options */
89 %token BINARY_PROTOCOL
90 %token BUFFER_REQUESTS
91 %token CONNECT_TIMEOUT
94 %token HASH_WITH_NAMESPACE
95 %token IO_BYTES_WATERMARK
96 %token IO_KEY_PREFETCH
97 %token IO_MSG_WATERMARK
99 %token KETAMA_WEIGHTED
101 %token NUMBER_OF_REPLICAS
103 %token RANDOMIZE_REPLICA_READ
105 %token REMOVE_FAILED_SERVERS
108 %token SOCKET_RECV_SIZE
109 %token SOCKET_SEND_SIZE
115 %token _TCP_KEEPALIVE
143 %token <boolean> TRUE
144 %token <boolean> FALSE
149 %token <number> FLOAT
150 %token <number> NUMBER
152 %token <number> WEIGHT_START
153 %token <server> IPADDRESS
154 %token <server> HOSTNAME
155 %token <string> STRING
156 %token <string> QUOTED_STRING
157 %token <string> FILE_PATH
159 %type <behavior> behavior_boolean
160 %type <behavior> behavior_number
161 %type <distribution> distribution
163 %type <number> optional_port
164 %type <number> optional_weight
165 %type <string> string
171 | begin ' ' statement
188 context->rc= MEMCACHED_PARSE_USER_ERROR;
189 parser_abort(context, NULL);
193 memcached_reset(context->memc);
201 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
203 parser_abort(context, NULL);
210 SERVER HOSTNAME 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 | SERVER IPADDRESS optional_port optional_weight
220 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
222 parser_abort(context, NULL);
224 context->unset_server();
226 | SOCKET string optional_weight
228 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3)))
230 parser_abort(context, NULL);
233 | CONFIGURE_FILE string
235 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
239 context->memc->configure.initial_pool_size= $2;
243 context->memc->configure.max_pool_size= $2;
251 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
253 parser_abort(context, NULL);;
256 | DISTRIBUTION distribution
258 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
260 parser_abort(context, NULL);;
263 | DISTRIBUTION distribution ',' hash
265 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
267 parser_abort(context, NULL);;
269 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
271 parser_abort(context, NULL);;
276 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
278 parser_abort(context, NULL);;
281 | behavior_number NUMBER
283 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
285 parser_abort(context, NULL);;
290 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
292 parser_abort(context, NULL);;
301 REMOVE_FAILED_SERVERS
303 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
307 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
311 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
315 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
319 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
323 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
327 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
331 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
335 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
339 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
343 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
347 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
354 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
358 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
360 | HASH_WITH_NAMESPACE
362 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
366 $$= MEMCACHED_BEHAVIOR_NOREPLY;
368 | RANDOMIZE_REPLICA_READ
370 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
374 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
378 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
382 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
386 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
390 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
394 $$= MEMCACHED_BEHAVIOR_USE_UDP;
398 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
403 { $$= MEMCACHED_DEFAULT_PORT;}
417 $$= MEMCACHED_HASH_MD5;
421 $$= MEMCACHED_HASH_CRC;
425 $$= MEMCACHED_HASH_FNV1_64;
429 $$= MEMCACHED_HASH_FNV1A_64;
433 $$= MEMCACHED_HASH_FNV1_32;
437 $$= MEMCACHED_HASH_FNV1A_32;
441 $$= MEMCACHED_HASH_HSIEH;
445 $$= MEMCACHED_HASH_MURMUR;
449 $$= MEMCACHED_HASH_JENKINS;
467 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
471 $$= MEMCACHED_DISTRIBUTION_MODULA;
475 $$= MEMCACHED_DISTRIBUTION_RANDOM;
481 void Context::start()
483 config_parse(this, (void **)scanner);