Merge in more updates for docs (we are just going to check them all in so that users...
[awesomized/libmemcached] / libmemcached / options / parser.yy
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached Scanner and Parser
4 *
5 * Copyright (C) 2011 DataDifferental, http://datadifferential.com
6 *
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.
11 *
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.
16 *
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/>.
19 */
20
21 %error-verbose
22 %debug
23 %defines
24 %expect 0
25 %output "libmemcached/options/parser.cc"
26 %defines "libmemcached/options/parser.h"
27 %lex-param { yyscan_t *scanner }
28 %name-prefix="config_"
29 %parse-param { Context *context }
30 %parse-param { yyscan_t *scanner }
31 %pure-parser
32 %require "2.2"
33 %start begin
34 %verbose
35
36 %{
37
38 #include <config.h>
39
40 #include <stdint.h>
41
42 #include <libmemcached/options/context.h>
43 #include <libmemcached/options/string.h>
44 #include <libmemcached/options/symbol.h>
45 #include <libmemcached/visibility.h>
46 #include <libmemcached/prefix_key.h>
47
48 #pragma GCC diagnostic ignored "-Wold-style-cast"
49 #include <libmemcached/options/scanner.h>
50
51 int conf_lex(YYSTYPE* lvalp, void* scanner);
52
53 #define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0)
54
55 inline void config_error(Context *context, yyscan_t *scanner, const char *error)
56 {
57 if (not context->end())
58 context->abort(error);
59 }
60
61 %}
62
63 %token COMMENT
64 %token END
65 %token ERROR
66 %token RESET
67 %token PARSER_DEBUG
68 %token INCLUDE
69 %token CONFIGURE_FILE
70 %token EMPTY_LINE
71 %token SERVER
72 %token SERVERS
73 %token SERVERS_OPTION
74 %token UNKNOWN_OPTION
75 %token UNKNOWN
76
77 /* All behavior options */
78 %token AUTO_EJECT_HOSTS
79 %token BINARY_PROTOCOL
80 %token BUFFER_REQUESTS
81 %token CONNECT_TIMEOUT
82 %token DISTRIBUTION
83 %token HASH
84 %token HASH_WITH_PREFIX_KEY
85 %token IO_BYTES_WATERMARK
86 %token IO_KEY_PREFETCH
87 %token IO_MSG_WATERMARK
88 %token KETAMA_HASH
89 %token KETAMA_WEIGHTED
90 %token NOREPLY
91 %token NUMBER_OF_REPLICAS
92 %token POLL_TIMEOUT
93 %token RANDOMIZE_REPLICA_READ
94 %token RCV_TIMEOUT
95 %token RETRY_TIMEOUT
96 %token SERVER_FAILURE_LIMIT
97 %token SND_TIMEOUT
98 %token SOCKET_RECV_SIZE
99 %token SOCKET_SEND_SIZE
100 %token SORT_HOSTS
101 %token SUPPORT_CAS
102 %token _TCP_NODELAY
103 %token _TCP_KEEPALIVE
104 %token _TCP_KEEPIDLE
105 %token USER_DATA
106 %token USE_UDP
107 %token VERIFY_KEY
108
109 /* Callbacks */
110 %token PREFIX_KEY
111
112 /* Hash types */
113 %token MD5
114 %token CRC
115 %token FNV1_64
116 %token FNV1A_64
117 %token FNV1_32
118 %token FNV1A_32
119 %token HSIEH
120 %token MURMUR
121 %token JENKINS
122
123 /* Distributions */
124 %token CONSISTENT
125 %token MODULA
126 %token RANDOM
127
128 /* Boolean values */
129 %token <boolean> TRUE
130 %token <boolean> FALSE
131
132 %nonassoc ','
133 %nonassoc '='
134
135 %token <number> FLOAT
136 %token <number> NUMBER
137 %token PORT
138 %token WEIGHT_START
139 %token <server> IPADDRESS
140 %token <server> HOSTNAME
141 %token <string> STRING
142 %token <string> QUOTED_STRING
143 %token <string> FILE_PATH
144
145 %type <string> string
146 %type <distribution> distribution
147 %type <hash> hash
148 %type <behavior> behavior_boolean
149 %type <behavior> behavior_number
150
151 %%
152
153 begin:
154 statement
155 | begin ' ' statement
156 ;
157
158 statement:
159 expression
160 { }
161 | COMMENT
162 { }
163 | EMPTY_LINE
164 { }
165 | END
166 {
167 context->set_end();
168 YYACCEPT;
169 }
170 | ERROR
171 {
172 context->rc= MEMCACHED_PARSE_USER_ERROR;
173 parser_abort(context, NULL);
174 }
175 | RESET
176 {
177 memcached_reset(context->memc);
178 }
179 | PARSER_DEBUG
180 {
181 yydebug= 1;
182 }
183 | INCLUDE ' ' string
184 {
185 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
186 {
187 parser_abort(context, NULL);
188 }
189 }
190 ;
191
192
193 expression:
194 SERVER HOSTNAME optional_port optional_weight
195 {
196 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
197 {
198 parser_abort(context, NULL);
199 }
200 context->unset_server();
201 }
202 | SERVER IPADDRESS optional_port optional_weight
203 {
204 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
205 {
206 parser_abort(context, NULL);
207 }
208 context->unset_server();
209 }
210 | CONFIGURE_FILE string
211 {
212 memcached_set_configuration_file(context->memc, $2.c_str, $2.length);
213 }
214 | behaviors
215 ;
216
217 behaviors:
218 PREFIX_KEY string
219 {
220 if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
221 {
222 parser_abort(context, NULL);;
223 }
224 }
225 | DISTRIBUTION distribution
226 {
227 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
228 {
229 parser_abort(context, NULL);;
230 }
231 }
232 | DISTRIBUTION distribution ',' hash
233 {
234 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
235 {
236 parser_abort(context, NULL);;
237 }
238 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
239 {
240 parser_abort(context, NULL);;
241 }
242 }
243 | HASH hash
244 {
245 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
246 {
247 parser_abort(context, NULL);;
248 }
249 }
250 | behavior_number NUMBER
251 {
252 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
253 {
254 parser_abort(context, NULL);;
255 }
256 }
257 | behavior_boolean
258 {
259 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
260 {
261 parser_abort(context, NULL);;
262 }
263 }
264 | USER_DATA
265 {
266 }
267 ;
268
269 behavior_number:
270 CONNECT_TIMEOUT
271 {
272 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
273 }
274 | IO_MSG_WATERMARK
275 {
276 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
277 }
278 | IO_BYTES_WATERMARK
279 {
280 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
281 }
282 | IO_KEY_PREFETCH
283 {
284 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
285 }
286 | NUMBER_OF_REPLICAS
287 {
288 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
289 }
290 | POLL_TIMEOUT
291 {
292 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
293 }
294 | RCV_TIMEOUT
295 {
296 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
297 }
298 | RETRY_TIMEOUT
299 {
300 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
301 }
302 | SERVER_FAILURE_LIMIT
303 {
304 $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
305 }
306 | SND_TIMEOUT
307 {
308 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
309 }
310 | SOCKET_RECV_SIZE
311 {
312 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
313 }
314 | SOCKET_SEND_SIZE
315 {
316 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
317 }
318 ;
319
320 behavior_boolean:
321 AUTO_EJECT_HOSTS
322 {
323 $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
324 }
325 | BINARY_PROTOCOL
326 {
327 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
328 }
329 | BUFFER_REQUESTS
330 {
331 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
332 }
333 | HASH_WITH_PREFIX_KEY
334 {
335 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
336 }
337 | NOREPLY
338 {
339 $$= MEMCACHED_BEHAVIOR_NOREPLY;
340 }
341 | RANDOMIZE_REPLICA_READ
342 {
343 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
344 }
345 | SORT_HOSTS
346 {
347 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
348 }
349 | SUPPORT_CAS
350 {
351 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
352 }
353 | _TCP_NODELAY
354 {
355 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
356 }
357 | _TCP_KEEPALIVE
358 {
359 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
360 }
361 | _TCP_KEEPIDLE
362 {
363 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
364 }
365 | USE_UDP
366 {
367 $$= MEMCACHED_BEHAVIOR_USE_UDP;
368 }
369 | VERIFY_KEY
370 {
371 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
372 }
373
374
375 optional_port:
376 { }
377 | PORT
378 { };
379 ;
380
381 optional_weight:
382 { }
383 | WEIGHT_START
384 { }
385 ;
386
387 hash:
388 MD5
389 {
390 $$= MEMCACHED_HASH_MD5;
391 }
392 | CRC
393 {
394 $$= MEMCACHED_HASH_CRC;
395 }
396 | FNV1_64
397 {
398 $$= MEMCACHED_HASH_FNV1_64;
399 }
400 | FNV1A_64
401 {
402 $$= MEMCACHED_HASH_FNV1A_64;
403 }
404 | FNV1_32
405 {
406 $$= MEMCACHED_HASH_FNV1_32;
407 }
408 | FNV1A_32
409 {
410 $$= MEMCACHED_HASH_FNV1A_32;
411 }
412 | HSIEH
413 {
414 $$= MEMCACHED_HASH_HSIEH;
415 }
416 | MURMUR
417 {
418 $$= MEMCACHED_HASH_MURMUR;
419 }
420 | JENKINS
421 {
422 $$= MEMCACHED_HASH_JENKINS;
423 }
424 ;
425
426 string:
427 STRING
428 {
429 $$= $1;
430 }
431 | QUOTED_STRING
432 {
433 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
434 $$.length= $1.length -1; // -1 removes the end quote
435 }
436 ;
437
438 distribution:
439 CONSISTENT
440 {
441 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
442 }
443 | MODULA
444 {
445 $$= MEMCACHED_DISTRIBUTION_MODULA;
446 }
447 | RANDOM
448 {
449 $$= MEMCACHED_DISTRIBUTION_RANDOM;
450 }
451 ;
452
453 %%
454
455 void Context::start()
456 {
457 config_parse(this, (void **)scanner);
458 }
459