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/>.
26 #include <libmemcached/options/type.h>
27 #include <libmemcached/options/string.h>
28 #include <libmemcached/options/symbol.h>
30 #pragma GCC diagnostic ignored "-Wold-style-cast"
31 #include <libmemcached/options/scanner.h>
33 inline void libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner, const char *str)
35 memcached_string_t local_string;
36 local_string.size= strlen(str);
37 local_string.c_str= str;
38 memcached_set_error(parser->memc, MEMCACHED_FAILURE, &local_string);
48 %output "libmemcached/options/parser.cc"
49 %defines "libmemcached/options/parser.h"
50 %lex-param { yyscan_t *scanner }
51 %name-prefix="libmemcached_"
52 %parse-param { type_st *parser }
53 %parse-param { yyscan_t *scanner }
68 /* All behavior options */
69 %token AUTO_EJECT_HOSTS
70 %token BINARY_PROTOCOL
71 %token BUFFER_REQUESTS
73 %token CONNECT_TIMEOUT
77 %token HASH_WITH_PREFIX_KEY
78 %token IO_BYTES_WATERMARK
79 %token IO_KEY_PREFETCH
80 %token IO_MSG_WATERMARK
83 %token KETAMA_WEIGHTED
85 %token NUMBER_OF_REPLICAS
87 %token RANDOMIZE_REPLICA_READ
90 %token SERVER_FAILURE_LIMIT
92 %token SOCKET_RECV_SIZE
93 %token SOCKET_SEND_SIZE
125 %token <number> NUMBER
126 %token <number> FLOAT
127 %token <string> HOSTNAME
128 %token <string> HOSTNAME_WITH_PORT
129 %token <string> IPADDRESS
130 %token <string> IPADDRESS_WITH_PORT
131 %token <string> STRING
132 %token <string> QUOTED_STRING
134 %type <server> server
135 %type <string> string
136 %type <distribution> distribution
138 %type <behavior> behavior_boolean
139 %type <behavior> behavior_number
144 DASH_OPTION expression
146 | statement ' ' DASH_OPTION expression
158 (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0);
160 | SERVERS '=' server_list
167 PREFIX_KEY '=' string
169 memcached_callback_set(parser->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str());
171 | DISTRIBUTION '=' distribution
173 memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3);
177 memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3);
179 | KETAMA_HASH '=' hash
181 memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3);
183 | behavior_number '=' NUMBER
185 memcached_behavior_set(parser->memc, $1, $3);
189 memcached_behavior_set(parser->memc, $1, true);
199 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
203 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
207 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
211 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
215 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
219 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
223 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
227 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
229 | SERVER_FAILURE_LIMIT
231 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
235 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
239 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
243 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
250 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
254 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
258 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
262 $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
266 $$= MEMCACHED_BEHAVIOR_CORK;
268 | HASH_WITH_PREFIX_KEY
270 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
274 $$= MEMCACHED_BEHAVIOR_KETAMA;
278 $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
282 $$= MEMCACHED_BEHAVIOR_NOREPLY;
284 | RANDOMIZE_REPLICA_READ
286 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
290 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
294 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
298 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
302 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
306 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
310 $$= MEMCACHED_BEHAVIOR_USE_UDP;
314 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
321 (void) memcached_server_add_parsed(parser->memc, $1.c_str, $1.length, $1.port, 0);
323 | server_list ',' server
325 (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0);
330 HOSTNAME_WITH_PORT NUMBER
333 $$.length= $1.length -1;
339 $$.length= $1.length;
340 $$.port= MEMCACHED_DEFAULT_PORT;
342 | STRING /* a match can be against "localhost" which is just a string */
345 $$.length= $1.length;
346 $$.port= MEMCACHED_DEFAULT_PORT;
348 | IPADDRESS_WITH_PORT NUMBER
351 $$.length= $1.length -1;
357 $$.length= $1.length;
358 $$.port= MEMCACHED_DEFAULT_PORT;
365 $$= MEMCACHED_HASH_MD5;
369 $$= MEMCACHED_HASH_CRC;
373 $$= MEMCACHED_HASH_FNV1_64;
377 $$= MEMCACHED_HASH_FNV1A_64;
381 $$= MEMCACHED_HASH_FNV1_32;
385 $$= MEMCACHED_HASH_FNV1A_32;
389 $$= MEMCACHED_HASH_HSIEH;
393 $$= MEMCACHED_HASH_MURMUR;
397 $$= MEMCACHED_HASH_JENKINS;
408 $$.c_str= $1.c_str +1;
409 $$.length= $1.length -2;
416 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
420 $$= MEMCACHED_DISTRIBUTION_MODULA;
424 $$= MEMCACHED_DISTRIBUTION_RANDOM;