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 }
44 #include <libmemcached/options/context.h>
45 #include <libmemcached/options/string.h>
46 #include <libmemcached/options/symbol.h>
48 #pragma GCC diagnostic ignored "-Wold-style-cast"
49 #include <libmemcached/options/scanner.h>
51 int libmemcached_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
53 #define parser_abort(A, B) do { parser_abort_func((A), (B)); YYABORT; } while (0)
55 inline void parser_abort_func(Context *context, const char *error)
58 if (context->rc == MEMCACHED_SUCCESS)
59 context->rc= MEMCACHED_PARSE_ERROR;
61 std::string error_message;
62 error_message+= "Error occured while parsing: ";
63 error_message+= context->begin;
65 if (context->rc == MEMCACHED_PARSE_ERROR and error)
67 error_message+= error;
71 error_message+= memcached_strerror(NULL, context->rc);
75 memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size());
78 inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanner, const char *error)
80 if (not context->end())
81 parser_abort_func(context, error);
84 int libmemcached_parse(Context*, yyscan_t *);
87 libmemcached_parse(this, scanner);
102 %token SERVERS_OPTION
103 %token UNKNOWN_OPTION
106 /* All behavior options */
107 %token AUTO_EJECT_HOSTS
108 %token BINARY_PROTOCOL
109 %token BUFFER_REQUESTS
111 %token CONNECT_TIMEOUT
115 %token HASH_WITH_PREFIX_KEY
116 %token IO_BYTES_WATERMARK
117 %token IO_KEY_PREFETCH
118 %token IO_MSG_WATERMARK
121 %token KETAMA_WEIGHTED
123 %token NUMBER_OF_REPLICAS
125 %token RANDOMIZE_REPLICA_READ
128 %token SERVER_FAILURE_LIMIT
130 %token SOCKET_RECV_SIZE
131 %token SOCKET_SEND_SIZE
135 %token _TCP_KEEPALIVE
161 %token <boolean> TRUE
162 %token <boolean> FALSE
167 %token <number> NUMBER
168 %token <number> FLOAT
169 %token <string> HOSTNAME
170 %token <string> HOSTNAME_WITH_PORT
171 %token <string> IPADDRESS
172 %token <string> IPADDRESS_WITH_PORT
173 %token <string> STRING
174 %token <string> QUOTED_STRING
175 %token <string> FILE_PATH
177 %type <server> server
178 %type <string> string
179 %type <distribution> distribution
181 %type <behavior> behavior_boolean
182 %type <behavior> behavior_number
188 | begin ' ' statement
205 context->rc= MEMCACHED_PARSE_USER_ERROR;
206 parser_abort(context, NULL);
210 memcached_reset(context->memc);
218 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
220 parser_abort(context, NULL);
229 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
231 parser_abort(context, NULL);
234 | SERVERS_OPTION '=' server_list
237 | CONFIGURE_FILE '=' string
239 memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
245 PREFIX_KEY '=' string
247 if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
249 parser_abort(context, NULL);;
252 | DISTRIBUTION '=' distribution
254 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
256 parser_abort(context, NULL);;
261 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
263 parser_abort(context, NULL);;
266 | KETAMA_HASH '=' hash
268 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
270 parser_abort(context, NULL);;
273 | behavior_number '=' NUMBER
275 if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
277 parser_abort(context, NULL);;
282 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
284 parser_abort(context, NULL);;
295 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
299 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
303 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
307 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
311 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
315 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
319 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
323 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
325 | SERVER_FAILURE_LIMIT
327 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
331 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
335 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
339 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
346 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
350 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
354 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
358 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
362 $$= MEMCACHED_BEHAVIOR_CORK;
364 | HASH_WITH_PREFIX_KEY
366 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
370 $$= MEMCACHED_BEHAVIOR_KETAMA;
374 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
378 $$= MEMCACHED_BEHAVIOR_NOREPLY;
380 | RANDOMIZE_REPLICA_READ
382 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
386 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
390 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
394 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
398 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
402 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
406 $$= MEMCACHED_BEHAVIOR_USE_UDP;
410 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
417 if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
419 parser_abort(context, NULL);;
422 | server_list ',' server
424 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
426 parser_abort(context, NULL);;
432 HOSTNAME_WITH_PORT NUMBER
435 $$.length= $1.length -1; // -1 to remove :
441 $$.length= $1.length;
442 $$.port= MEMCACHED_DEFAULT_PORT;
444 | STRING /* a match can be against "localhost" which is just a string */
447 $$.length= $1.length;
448 $$.port= MEMCACHED_DEFAULT_PORT;
450 | IPADDRESS_WITH_PORT NUMBER
453 $$.length= $1.length -1; // -1 to remove :
459 $$.length= $1.length;
460 $$.port= MEMCACHED_DEFAULT_PORT;
467 $$= MEMCACHED_HASH_MD5;
471 $$= MEMCACHED_HASH_CRC;
475 $$= MEMCACHED_HASH_FNV1_64;
479 $$= MEMCACHED_HASH_FNV1A_64;
483 $$= MEMCACHED_HASH_FNV1_32;
487 $$= MEMCACHED_HASH_FNV1A_32;
491 $$= MEMCACHED_HASH_HSIEH;
495 $$= MEMCACHED_HASH_MURMUR;
499 $$= MEMCACHED_HASH_JENKINS;
510 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
511 $$.length= $1.length -1; // -1 removes the end quote
518 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
522 $$= MEMCACHED_DISTRIBUTION_MODULA;
526 $$= MEMCACHED_DISTRIBUTION_RANDOM;