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 inline void parser_abort(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+= context->begin;
64 error_message+= memcached_strerror(NULL, context->rc);
67 memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size());
70 inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanner, const char *error)
72 parser_abort(context, error);
85 /* All behavior options */
86 %token AUTO_EJECT_HOSTS
87 %token BINARY_PROTOCOL
88 %token BUFFER_REQUESTS
90 %token CONNECT_TIMEOUT
94 %token HASH_WITH_PREFIX_KEY
95 %token IO_BYTES_WATERMARK
96 %token IO_KEY_PREFETCH
97 %token IO_MSG_WATERMARK
100 %token KETAMA_WEIGHTED
102 %token NUMBER_OF_REPLICAS
104 %token RANDOMIZE_REPLICA_READ
107 %token SERVER_FAILURE_LIMIT
109 %token SOCKET_RECV_SIZE
110 %token SOCKET_SEND_SIZE
114 %token _TCP_KEEPALIVE
142 %token <number> NUMBER
143 %token <number> FLOAT
144 %token <string> HOSTNAME
145 %token <string> HOSTNAME_WITH_PORT
146 %token <string> IPADDRESS
147 %token <string> IPADDRESS_WITH_PORT
148 %token <string> STRING
149 %token <string> QUOTED_STRING
151 %type <server> server
152 %type <string> string
153 %type <distribution> distribution
155 %type <behavior> behavior_boolean
156 %type <behavior> behavior_number
163 | statement ' ' expression
175 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
177 parser_abort(context, NULL);
180 | SERVERS '=' server_list
183 | CONFIGURE_FILE '=' string
185 memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
191 PREFIX_KEY '=' string
193 if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
195 parser_abort(context, NULL);;
198 | DISTRIBUTION '=' distribution
200 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
202 parser_abort(context, NULL);;
207 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
209 parser_abort(context, NULL);;
212 | KETAMA_HASH '=' hash
214 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
216 parser_abort(context, NULL);;
219 | behavior_number '=' NUMBER
221 if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
223 parser_abort(context, NULL);;
228 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
230 parser_abort(context, NULL);;
241 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
245 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
249 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
253 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
257 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
261 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
265 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
269 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
271 | SERVER_FAILURE_LIMIT
273 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
277 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
281 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
285 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
292 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
296 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
300 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
304 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
308 $$= MEMCACHED_BEHAVIOR_CORK;
310 | HASH_WITH_PREFIX_KEY
312 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
316 $$= MEMCACHED_BEHAVIOR_KETAMA;
320 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
324 $$= MEMCACHED_BEHAVIOR_NOREPLY;
326 | RANDOMIZE_REPLICA_READ
328 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
332 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
336 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
340 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
344 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
348 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
352 $$= MEMCACHED_BEHAVIOR_USE_UDP;
356 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
363 if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
365 parser_abort(context, NULL);;
368 | server_list ',' server
370 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
372 parser_abort(context, NULL);;
378 HOSTNAME_WITH_PORT NUMBER
381 $$.length= $1.length -1;
387 $$.length= $1.length;
388 $$.port= MEMCACHED_DEFAULT_PORT;
390 | STRING /* a match can be against "localhost" which is just a string */
393 $$.length= $1.length;
394 $$.port= MEMCACHED_DEFAULT_PORT;
396 | IPADDRESS_WITH_PORT NUMBER
399 $$.length= $1.length -1;
405 $$.length= $1.length;
406 $$.port= MEMCACHED_DEFAULT_PORT;
413 $$= MEMCACHED_HASH_MD5;
417 $$= MEMCACHED_HASH_CRC;
421 $$= MEMCACHED_HASH_FNV1_64;
425 $$= MEMCACHED_HASH_FNV1A_64;
429 $$= MEMCACHED_HASH_FNV1_32;
433 $$= MEMCACHED_HASH_FNV1A_32;
437 $$= MEMCACHED_HASH_HSIEH;
441 $$= MEMCACHED_HASH_MURMUR;
445 $$= MEMCACHED_HASH_JENKINS;
456 $$.c_str= $1.c_str +1;
457 $$.length= $1.length -2;
464 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
468 $$= MEMCACHED_DISTRIBUTION_MODULA;
472 $$= MEMCACHED_DISTRIBUTION_RANDOM;