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 #ifndef __INTEL_COMPILER
46 #pragma GCC diagnostic ignored "-Wold-style-cast"
49 int conf_lex(YYSTYPE* lvalp, void* scanner);
51 #define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
53 #define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
55 #define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
57 // This is bison calling error.
58 inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
60 if (not context->end())
62 context->error(error, yytokentype(last_token), last_token_str);
66 context->error(error, yytokentype(last_token), last_token_str);
70 #define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
90 /* All behavior options */
91 %token BINARY_PROTOCOL
92 %token BUFFER_REQUESTS
93 %token CONNECT_TIMEOUT
96 %token HASH_WITH_NAMESPACE
97 %token IO_BYTES_WATERMARK
98 %token IO_KEY_PREFETCH
99 %token IO_MSG_WATERMARK
101 %token KETAMA_WEIGHTED
103 %token NUMBER_OF_REPLICAS
105 %token RANDOMIZE_REPLICA_READ
107 %token REMOVE_FAILED_SERVERS
110 %token SOCKET_RECV_SIZE
111 %token SOCKET_SEND_SIZE
117 %token _TCP_KEEPALIVE
145 %token <boolean> TRUE
146 %token <boolean> FALSE
151 %token <number> FLOAT
152 %token <number> NUMBER
154 %token <number> WEIGHT_START
155 %token <server> IPADDRESS
156 %token <server> HOSTNAME
157 %token <string> STRING
158 %token <string> QUOTED_STRING
159 %token <string> FILE_PATH
161 %type <behavior> behavior_boolean
162 %type <behavior> behavior_number
163 %type <distribution> distribution
165 %type <number> optional_port
166 %type <number> optional_weight
167 %type <string> string
173 | begin ' ' statement
190 context->rc= MEMCACHED_PARSE_USER_ERROR;
191 parser_abort(context, NULL);
195 memcached_reset(context->memc);
203 if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
205 parser_abort(context, NULL);
212 SERVER HOSTNAME optional_port optional_weight
214 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
216 parser_abort(context, NULL);
218 context->unset_server();
220 | SERVER IPADDRESS optional_port optional_weight
222 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
224 parser_abort(context, NULL);
226 context->unset_server();
228 | SOCKET string optional_weight
230 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3)))
232 parser_abort(context, NULL);
235 | CONFIGURE_FILE string
237 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
241 context->memc->configure.initial_pool_size= $2;
245 context->memc->configure.max_pool_size= $2;
253 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
255 parser_abort(context, NULL);;
258 | DISTRIBUTION distribution
260 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
262 parser_abort(context, NULL);;
265 | DISTRIBUTION distribution ',' hash
267 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
269 parser_abort(context, NULL);;
271 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
273 parser_abort(context, NULL);;
278 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
280 parser_abort(context, NULL);;
283 | behavior_number NUMBER
285 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
287 parser_abort(context, NULL);;
292 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
294 parser_abort(context, NULL);;
303 REMOVE_FAILED_SERVERS
305 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
309 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
313 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
317 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
321 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
325 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
329 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
333 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
337 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
341 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
345 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
349 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
356 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
360 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
362 | HASH_WITH_NAMESPACE
364 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
368 $$= MEMCACHED_BEHAVIOR_NOREPLY;
370 | RANDOMIZE_REPLICA_READ
372 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
376 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
380 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
384 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
388 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
392 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
396 $$= MEMCACHED_BEHAVIOR_USE_UDP;
400 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
405 { $$= MEMCACHED_DEFAULT_PORT;}
419 $$= MEMCACHED_HASH_MD5;
423 $$= MEMCACHED_HASH_CRC;
427 $$= MEMCACHED_HASH_FNV1_64;
431 $$= MEMCACHED_HASH_FNV1A_64;
435 $$= MEMCACHED_HASH_FNV1_32;
439 $$= MEMCACHED_HASH_FNV1A_32;
443 $$= MEMCACHED_HASH_HSIEH;
447 $$= MEMCACHED_HASH_MURMUR;
451 $$= MEMCACHED_HASH_JENKINS;
469 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
473 $$= MEMCACHED_DISTRIBUTION_MODULA;
477 $$= MEMCACHED_DISTRIBUTION_RANDOM;
483 void Context::start()
485 config_parse(this, (void **)scanner);