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, "ERROR called directly");
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, "Failed to parse configuration file");
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)))
217 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
218 parser_abort(context, buffer);
220 context->unset_server();
222 | SERVER IPADDRESS optional_port optional_weight
224 if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
227 snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
228 parser_abort(context, buffer);
230 context->unset_server();
232 | SOCKET string optional_weight
234 if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3)))
237 snprintf(buffer, sizeof(buffer), "Failed to add server: %s", $2.c_str);
238 parser_abort(context, buffer);
241 | CONFIGURE_FILE string
243 memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
247 context->memc->configure.initial_pool_size= $2;
251 context->memc->configure.max_pool_size= $2;
259 if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
261 parser_abort(context, "--NAMESPACE can only be called once");
264 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
266 parser_abort(context, memcached_last_error_message(context->memc));
269 | DISTRIBUTION distribution
271 // Check to see if DISTRIBUTION has already been set
272 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
274 parser_abort(context, "--DISTRIBUTION can only be called once");
277 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
279 parser_abort(context, memcached_last_error_message(context->memc));;
282 | DISTRIBUTION distribution ',' hash
284 // Check to see if DISTRIBUTION has already been set
285 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
287 parser_abort(context, "--DISTRIBUTION can only be called once");
290 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
292 parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
297 if (context->set_hash($2) == false)
299 parser_abort(context, "--HASH can only be set once");
302 | behavior_number NUMBER
304 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
306 parser_abort(context, "Unable to set behavior");
311 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
314 snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
315 parser_abort(context, buffer);
324 REMOVE_FAILED_SERVERS
326 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
330 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
334 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
338 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
342 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
346 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
350 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
354 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
358 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
362 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
366 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
370 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
377 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
381 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
383 | HASH_WITH_NAMESPACE
385 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
389 $$= MEMCACHED_BEHAVIOR_NOREPLY;
391 | RANDOMIZE_REPLICA_READ
393 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
397 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
401 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
405 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
409 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
413 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
417 $$= MEMCACHED_BEHAVIOR_USE_UDP;
421 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
426 { $$= MEMCACHED_DEFAULT_PORT;}
440 $$= MEMCACHED_HASH_MD5;
444 $$= MEMCACHED_HASH_CRC;
448 $$= MEMCACHED_HASH_FNV1_64;
452 $$= MEMCACHED_HASH_FNV1A_64;
456 $$= MEMCACHED_HASH_FNV1_32;
460 $$= MEMCACHED_HASH_FNV1A_32;
464 $$= MEMCACHED_HASH_HSIEH;
468 $$= MEMCACHED_HASH_MURMUR;
472 $$= MEMCACHED_HASH_JENKINS;
490 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
494 $$= MEMCACHED_DISTRIBUTION_MODULA;
498 $$= MEMCACHED_DISTRIBUTION_RANDOM;
504 void Context::start()
506 config_parse(this, (void **)scanner);