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 libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanner, const char *error)
57 memcached_string_t local_string;
58 local_string.size= strlen(context->begin);
59 local_string.c_str= context->begin;
60 if (context->rc == MEMCACHED_SUCCESS)
61 context->rc= MEMCACHED_PARSE_ERROR;
62 memcached_set_error(context->memc, context->rc, &local_string);
75 /* All behavior options */
76 %token AUTO_EJECT_HOSTS
77 %token BINARY_PROTOCOL
78 %token BUFFER_REQUESTS
80 %token CONNECT_TIMEOUT
84 %token HASH_WITH_PREFIX_KEY
85 %token IO_BYTES_WATERMARK
86 %token IO_KEY_PREFETCH
87 %token IO_MSG_WATERMARK
90 %token KETAMA_WEIGHTED
92 %token NUMBER_OF_REPLICAS
94 %token RANDOMIZE_REPLICA_READ
97 %token SERVER_FAILURE_LIMIT
99 %token SOCKET_RECV_SIZE
100 %token SOCKET_SEND_SIZE
104 %token _TCP_KEEPALIVE
132 %token <number> NUMBER
133 %token <number> FLOAT
134 %token <string> HOSTNAME
135 %token <string> HOSTNAME_WITH_PORT
136 %token <string> IPADDRESS
137 %token <string> IPADDRESS_WITH_PORT
138 %token <string> STRING
139 %token <string> QUOTED_STRING
141 %type <server> server
142 %type <string> string
143 %type <distribution> distribution
145 %type <behavior> behavior_boolean
146 %type <behavior> behavior_number
153 | statement ' ' expression
165 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
170 | SERVERS '=' server_list
173 | CONFIGURE_FILE '=' string
175 memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
181 PREFIX_KEY '=' string
183 if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
188 | DISTRIBUTION '=' distribution
190 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
197 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
202 | KETAMA_HASH '=' hash
204 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
209 | behavior_number '=' NUMBER
211 if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
218 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
231 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
235 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
239 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
243 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
247 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
251 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
255 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
259 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
261 | SERVER_FAILURE_LIMIT
263 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
267 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
271 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
275 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
282 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
286 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
290 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
294 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
298 $$= MEMCACHED_BEHAVIOR_CORK;
300 | HASH_WITH_PREFIX_KEY
302 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
306 $$= MEMCACHED_BEHAVIOR_KETAMA;
310 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
314 $$= MEMCACHED_BEHAVIOR_NOREPLY;
316 | RANDOMIZE_REPLICA_READ
318 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
322 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
326 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
330 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
334 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
338 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
342 $$= MEMCACHED_BEHAVIOR_USE_UDP;
346 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
353 if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
358 | server_list ',' server
360 if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
368 HOSTNAME_WITH_PORT NUMBER
371 $$.length= $1.length -1;
377 $$.length= $1.length;
378 $$.port= MEMCACHED_DEFAULT_PORT;
380 | STRING /* a match can be against "localhost" which is just a string */
383 $$.length= $1.length;
384 $$.port= MEMCACHED_DEFAULT_PORT;
386 | IPADDRESS_WITH_PORT NUMBER
389 $$.length= $1.length -1;
395 $$.length= $1.length;
396 $$.port= MEMCACHED_DEFAULT_PORT;
403 $$= MEMCACHED_HASH_MD5;
407 $$= MEMCACHED_HASH_CRC;
411 $$= MEMCACHED_HASH_FNV1_64;
415 $$= MEMCACHED_HASH_FNV1A_64;
419 $$= MEMCACHED_HASH_FNV1_32;
423 $$= MEMCACHED_HASH_FNV1A_32;
427 $$= MEMCACHED_HASH_HSIEH;
431 $$= MEMCACHED_HASH_MURMUR;
435 $$= MEMCACHED_HASH_JENKINS;
446 $$.c_str= $1.c_str +1;
447 $$.length= $1.length -2;
454 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
458 $$= MEMCACHED_DISTRIBUTION_MODULA;
462 $$= MEMCACHED_DISTRIBUTION_RANDOM;