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="libmemcached_"
29 %parse-param { Context *context }
30 %parse-param { yyscan_t *scanner }
46 #include <libmemcached/options/context.h>
47 #include <libmemcached/options/string.h>
48 #include <libmemcached/options/symbol.h>
50 #pragma GCC diagnostic ignored "-Wold-style-cast"
51 #include <libmemcached/options/scanner.h>
53 int libmemcached_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
55 #define parser_abort(A, B) do { parser_abort_func((A), (B)); YYABORT; } while (0)
57 inline void parser_abort_func(Context *context, const char *error)
60 if (context->rc == MEMCACHED_SUCCESS)
61 context->rc= MEMCACHED_PARSE_ERROR;
63 std::string error_message;
64 error_message+= context->begin;
66 error_message+= memcached_strerror(NULL, context->rc);
69 memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size());
72 inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanner, const char *error)
74 if (not context->end())
75 parser_abort_func(context, error);
93 /* All behavior options */
94 %token AUTO_EJECT_HOSTS
95 %token BINARY_PROTOCOL
96 %token BUFFER_REQUESTS
98 %token CONNECT_TIMEOUT
102 %token HASH_WITH_PREFIX_KEY
103 %token IO_BYTES_WATERMARK
104 %token IO_KEY_PREFETCH
105 %token IO_MSG_WATERMARK
108 %token KETAMA_WEIGHTED
110 %token NUMBER_OF_REPLICAS
112 %token RANDOMIZE_REPLICA_READ
115 %token SERVER_FAILURE_LIMIT
117 %token SOCKET_RECV_SIZE
118 %token SOCKET_SEND_SIZE
122 %token _TCP_KEEPALIVE
148 %token <boolean> TRUE
149 %token <boolean> FALSE
154 %token <number> NUMBER
155 %token <number> FLOAT
156 %token <string> HOSTNAME
157 %token <string> HOSTNAME_WITH_PORT
158 %token <string> IPADDRESS
159 %token <string> IPADDRESS_WITH_PORT
160 %token <string> STRING
161 %token <string> QUOTED_STRING
163 %type <server> server
164 %type <string> string
165 %type <distribution> distribution
167 %type <behavior> behavior_boolean
168 %type <behavior> behavior_number
174 | statement ' ' statement
191 memcached_reset(context->memc);
195 memcached_servers_reset(context->memc);
211 if ((context->rc= memcached_parse_configure_file(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
213 parser_abort(context, NULL);
222 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
224 parser_abort(context, NULL);
227 | SERVERS_OPTION '=' server_list
230 | CONFIGURE_FILE '=' string
232 memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
238 PREFIX_KEY '=' string
240 if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
242 parser_abort(context, NULL);;
245 | DISTRIBUTION '=' distribution
247 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
249 parser_abort(context, NULL);;
254 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
256 parser_abort(context, NULL);;
259 | KETAMA_HASH '=' hash
261 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
263 parser_abort(context, NULL);;
266 | behavior_number '=' NUMBER
268 if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
270 parser_abort(context, NULL);;
275 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
277 parser_abort(context, NULL);;
288 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
292 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
296 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
300 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
304 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
308 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
312 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
316 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
318 | SERVER_FAILURE_LIMIT
320 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
324 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
328 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
332 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
339 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
343 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
347 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
351 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
355 $$= MEMCACHED_BEHAVIOR_CORK;
357 | HASH_WITH_PREFIX_KEY
359 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
363 $$= MEMCACHED_BEHAVIOR_KETAMA;
367 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
371 $$= MEMCACHED_BEHAVIOR_NOREPLY;
373 | RANDOMIZE_REPLICA_READ
375 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
379 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
383 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
387 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
391 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
395 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
399 $$= MEMCACHED_BEHAVIOR_USE_UDP;
403 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
410 if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
412 parser_abort(context, NULL);;
415 | server_list ',' server
417 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
419 parser_abort(context, NULL);;
425 HOSTNAME_WITH_PORT NUMBER
428 $$.length= $1.length -1;
434 $$.length= $1.length;
435 $$.port= MEMCACHED_DEFAULT_PORT;
437 | STRING /* a match can be against "localhost" which is just a string */
440 $$.length= $1.length;
441 $$.port= MEMCACHED_DEFAULT_PORT;
443 | IPADDRESS_WITH_PORT NUMBER
446 $$.length= $1.length -1;
452 $$.length= $1.length;
453 $$.port= MEMCACHED_DEFAULT_PORT;
460 $$= MEMCACHED_HASH_MD5;
464 $$= MEMCACHED_HASH_CRC;
468 $$= MEMCACHED_HASH_FNV1_64;
472 $$= MEMCACHED_HASH_FNV1A_64;
476 $$= MEMCACHED_HASH_FNV1_32;
480 $$= MEMCACHED_HASH_FNV1A_32;
484 $$= MEMCACHED_HASH_HSIEH;
488 $$= MEMCACHED_HASH_MURMUR;
492 $$= MEMCACHED_HASH_JENKINS;
503 $$.c_str= $1.c_str +1;
504 $$.length= $1.length -2;
511 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
515 $$= MEMCACHED_DISTRIBUTION_MODULA;
519 $$= MEMCACHED_DISTRIBUTION_RANDOM;