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 }
42 #include <libmemcached/options/context.h>
43 #include <libmemcached/options/string.h>
44 #include <libmemcached/options/symbol.h>
46 #pragma GCC diagnostic ignored "-Wold-style-cast"
47 #include <libmemcached/options/scanner.h>
49 int libmemcached_lex(YYSTYPE* lvalp, void* scanner);
51 #define parser_abort(A, B) do { parser_abort_func((A), (B)); YYABORT; } while (0)
53 inline void parser_abort_func(Context *context, const char *error)
56 if (context->rc == MEMCACHED_SUCCESS)
57 context->rc= MEMCACHED_PARSE_ERROR;
59 std::string error_message;
60 error_message+= "Error occured while parsing: ";
61 error_message+= context->begin;
63 if (context->rc == MEMCACHED_PARSE_ERROR and error)
65 error_message+= error;
69 error_message+= memcached_strerror(NULL, context->rc);
73 memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size());
76 inline void libmemcached_error(Context *context, yyscan_t *scanner, const char *error)
78 if (not context->end())
79 parser_abort_func(context, error);
82 int libmemcached_parse(Context*, yyscan_t *);
85 libmemcached_parse(this, scanner);
100 %token SERVERS_OPTION
101 %token UNKNOWN_OPTION
104 /* All behavior options */
105 %token AUTO_EJECT_HOSTS
106 %token BINARY_PROTOCOL
107 %token BUFFER_REQUESTS
109 %token CONNECT_TIMEOUT
113 %token HASH_WITH_PREFIX_KEY
114 %token IO_BYTES_WATERMARK
115 %token IO_KEY_PREFETCH
116 %token IO_MSG_WATERMARK
119 %token KETAMA_WEIGHTED
121 %token NUMBER_OF_REPLICAS
123 %token RANDOMIZE_REPLICA_READ
126 %token SERVER_FAILURE_LIMIT
128 %token SOCKET_RECV_SIZE
129 %token SOCKET_SEND_SIZE
133 %token _TCP_KEEPALIVE
159 %token <boolean> TRUE
160 %token <boolean> FALSE
165 %token <number> NUMBER
166 %token <number> FLOAT
167 %token <string> HOSTNAME
168 %token <string> HOSTNAME_WITH_PORT
169 %token <string> IPADDRESS
170 %token <string> IPADDRESS_WITH_PORT
171 %token <string> STRING
172 %token <string> QUOTED_STRING
173 %token <string> FILE_PATH
175 %type <server> server
176 %type <string> string
177 %type <distribution> distribution
179 %type <behavior> behavior_boolean
180 %type <behavior> behavior_number
186 | begin ' ' statement
203 context->rc= MEMCACHED_PARSE_USER_ERROR;
204 parser_abort(context, NULL);
208 memcached_reset(context->memc);
216 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
218 parser_abort(context, NULL);
227 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
229 parser_abort(context, NULL);
232 | SERVERS_OPTION '=' server_list
235 | CONFIGURE_FILE '=' string
237 memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
243 PREFIX_KEY '=' string
245 if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
247 parser_abort(context, NULL);;
250 | DISTRIBUTION '=' distribution
252 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
254 parser_abort(context, NULL);;
259 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
261 parser_abort(context, NULL);;
264 | KETAMA_HASH '=' hash
266 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
268 parser_abort(context, NULL);;
271 | behavior_number '=' NUMBER
273 if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
275 parser_abort(context, NULL);;
280 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
282 parser_abort(context, NULL);;
293 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
297 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
301 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
305 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
309 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
313 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
317 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
321 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
323 | SERVER_FAILURE_LIMIT
325 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
329 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
333 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
337 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
344 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
348 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
352 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
356 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
360 $$= MEMCACHED_BEHAVIOR_CORK;
362 | HASH_WITH_PREFIX_KEY
364 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
368 $$= MEMCACHED_BEHAVIOR_KETAMA;
372 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
376 $$= MEMCACHED_BEHAVIOR_NOREPLY;
378 | RANDOMIZE_REPLICA_READ
380 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
384 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
388 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
392 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
396 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
400 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
404 $$= MEMCACHED_BEHAVIOR_USE_UDP;
408 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
415 if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
417 parser_abort(context, NULL);;
420 | server_list ',' server
422 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
424 parser_abort(context, NULL);;
430 HOSTNAME_WITH_PORT NUMBER
433 $$.length= $1.length -1; // -1 to remove :
439 $$.length= $1.length;
440 $$.port= MEMCACHED_DEFAULT_PORT;
442 | STRING /* a match can be against "localhost" which is just a string */
445 $$.length= $1.length;
446 $$.port= MEMCACHED_DEFAULT_PORT;
448 | IPADDRESS_WITH_PORT NUMBER
451 $$.length= $1.length -1; // -1 to remove :
457 $$.length= $1.length;
458 $$.port= MEMCACHED_DEFAULT_PORT;
465 $$= MEMCACHED_HASH_MD5;
469 $$= MEMCACHED_HASH_CRC;
473 $$= MEMCACHED_HASH_FNV1_64;
477 $$= MEMCACHED_HASH_FNV1A_64;
481 $$= MEMCACHED_HASH_FNV1_32;
485 $$= MEMCACHED_HASH_FNV1A_32;
489 $$= MEMCACHED_HASH_HSIEH;
493 $$= MEMCACHED_HASH_MURMUR;
497 $$= MEMCACHED_HASH_JENKINS;
508 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
509 $$.length= $1.length -1; // -1 removes the end quote
516 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
520 $$= MEMCACHED_DISTRIBUTION_MODULA;
524 $$= MEMCACHED_DISTRIBUTION_RANDOM;