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 (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
255 parser_abort(context, "--NAMESPACE can only be called once");
258 if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
260 parser_abort(context, memcached_last_error_message(context->memc));
263 | DISTRIBUTION distribution
265 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
267 parser_abort(context, memcached_last_error_message(context->memc));;
270 | DISTRIBUTION distribution ',' hash
272 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
274 parser_abort(context, NULL);
276 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
278 parser_abort(context, NULL);
283 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
285 parser_abort(context, NULL);
288 | behavior_number NUMBER
290 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
292 parser_abort(context, NULL);
297 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
299 parser_abort(context, NULL);
308 REMOVE_FAILED_SERVERS
310 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
314 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
318 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
322 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
326 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
330 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
334 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
338 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
342 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
346 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
350 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
354 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
361 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
365 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
367 | HASH_WITH_NAMESPACE
369 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
373 $$= MEMCACHED_BEHAVIOR_NOREPLY;
375 | RANDOMIZE_REPLICA_READ
377 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
381 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
385 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
389 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
393 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
397 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
401 $$= MEMCACHED_BEHAVIOR_USE_UDP;
405 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
410 { $$= MEMCACHED_DEFAULT_PORT;}
424 $$= MEMCACHED_HASH_MD5;
428 $$= MEMCACHED_HASH_CRC;
432 $$= MEMCACHED_HASH_FNV1_64;
436 $$= MEMCACHED_HASH_FNV1A_64;
440 $$= MEMCACHED_HASH_FNV1_32;
444 $$= MEMCACHED_HASH_FNV1A_32;
448 $$= MEMCACHED_HASH_HSIEH;
452 $$= MEMCACHED_HASH_MURMUR;
456 $$= MEMCACHED_HASH_JENKINS;
474 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
478 $$= MEMCACHED_DISTRIBUTION_MODULA;
482 $$= MEMCACHED_DISTRIBUTION_RANDOM;
488 void Context::start()
490 config_parse(this, (void **)scanner);