Add docs for tap, and update all other documentation.
[m6w6/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 BINARY_PROTOCOL
79 %token BUFFER_REQUESTS
80 %token CONNECT_TIMEOUT
81 %token DISTRIBUTION
82 %token HASH
83 %token HASH_WITH_NAMESPACE
84 %token IO_BYTES_WATERMARK
85 %token IO_KEY_PREFETCH
86 %token IO_MSG_WATERMARK
87 %token KETAMA_HASH
88 %token KETAMA_WEIGHTED
89 %token NOREPLY
90 %token NUMBER_OF_REPLICAS
91 %token POLL_TIMEOUT
92 %token RANDOMIZE_REPLICA_READ
93 %token RCV_TIMEOUT
94 %token REMOVE_FAILED_SERVERS
95 %token RETRY_TIMEOUT
96 %token SND_TIMEOUT
97 %token SOCKET_RECV_SIZE
98 %token SOCKET_SEND_SIZE
99 %token SORT_HOSTS
100 %token SUPPORT_CAS
101 %token USER_DATA
102 %token USE_UDP
103 %token VERIFY_KEY
104 %token _TCP_KEEPALIVE
105 %token _TCP_KEEPIDLE
106 %token _TCP_NODELAY
107
108 /* Callbacks */
109 %token NAMESPACE
110
111 /* Hash types */
112 %token MD5
113 %token CRC
114 %token FNV1_64
115 %token FNV1A_64
116 %token FNV1_32
117 %token FNV1A_32
118 %token HSIEH
119 %token MURMUR
120 %token JENKINS
121
122 /* Distributions */
123 %token CONSISTENT
124 %token MODULA
125 %token RANDOM
126
127 /* Boolean values */
128 %token <boolean> TRUE
129 %token <boolean> FALSE
130
131 %nonassoc ','
132 %nonassoc '='
133
134 %token <number> FLOAT
135 %token <number> NUMBER
136 %token PORT
137 %token WEIGHT_START
138 %token <server> IPADDRESS
139 %token <server> HOSTNAME
140 %token <string> STRING
141 %token <string> QUOTED_STRING
142 %token <string> FILE_PATH
143
144 %type <string> string
145 %type <distribution> distribution
146 %type <hash> hash
147 %type <behavior> behavior_boolean
148 %type <behavior> behavior_number
149
150 %%
151
152 begin:
153 statement
154 | begin ' ' statement
155 ;
156
157 statement:
158 expression
159 { }
160 | COMMENT
161 { }
162 | EMPTY_LINE
163 { }
164 | END
165 {
166 context->set_end();
167 YYACCEPT;
168 }
169 | ERROR
170 {
171 context->rc= MEMCACHED_PARSE_USER_ERROR;
172 parser_abort(context, NULL);
173 }
174 | RESET
175 {
176 memcached_reset(context->memc);
177 }
178 | PARSER_DEBUG
179 {
180 yydebug= 1;
181 }
182 | INCLUDE ' ' string
183 {
184 if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
185 {
186 parser_abort(context, NULL);
187 }
188 }
189 ;
190
191
192 expression:
193 SERVER HOSTNAME optional_port optional_weight
194 {
195 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
196 {
197 parser_abort(context, NULL);
198 }
199 context->unset_server();
200 }
201 | SERVER IPADDRESS optional_port optional_weight
202 {
203 if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
204 {
205 parser_abort(context, NULL);
206 }
207 context->unset_server();
208 }
209 | CONFIGURE_FILE string
210 {
211 memcached_set_configuration_file(context->memc, $2.c_str, $2.length);
212 }
213 | behaviors
214 ;
215
216 behaviors:
217 NAMESPACE string
218 {
219 if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
220 {
221 parser_abort(context, NULL);;
222 }
223 }
224 | DISTRIBUTION distribution
225 {
226 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
227 {
228 parser_abort(context, NULL);;
229 }
230 }
231 | DISTRIBUTION distribution ',' hash
232 {
233 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
234 {
235 parser_abort(context, NULL);;
236 }
237 if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
238 {
239 parser_abort(context, NULL);;
240 }
241 }
242 | HASH hash
243 {
244 if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
245 {
246 parser_abort(context, NULL);;
247 }
248 }
249 | behavior_number NUMBER
250 {
251 if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
252 {
253 parser_abort(context, NULL);;
254 }
255 }
256 | behavior_boolean
257 {
258 if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
259 {
260 parser_abort(context, NULL);;
261 }
262 }
263 | USER_DATA
264 {
265 }
266 ;
267
268 behavior_number:
269 REMOVE_FAILED_SERVERS
270 {
271 $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
272 }
273 | CONNECT_TIMEOUT
274 {
275 $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
276 }
277 | IO_MSG_WATERMARK
278 {
279 $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
280 }
281 | IO_BYTES_WATERMARK
282 {
283 $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
284 }
285 | IO_KEY_PREFETCH
286 {
287 $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
288 }
289 | NUMBER_OF_REPLICAS
290 {
291 $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
292 }
293 | POLL_TIMEOUT
294 {
295 $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
296 }
297 | RCV_TIMEOUT
298 {
299 $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
300 }
301 | RETRY_TIMEOUT
302 {
303 $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
304 }
305 | SND_TIMEOUT
306 {
307 $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
308 }
309 | SOCKET_RECV_SIZE
310 {
311 $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
312 }
313 | SOCKET_SEND_SIZE
314 {
315 $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
316 }
317 ;
318
319 behavior_boolean:
320 BINARY_PROTOCOL
321 {
322 $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
323 }
324 | BUFFER_REQUESTS
325 {
326 $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
327 }
328 | HASH_WITH_NAMESPACE
329 {
330 $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
331 }
332 | NOREPLY
333 {
334 $$= MEMCACHED_BEHAVIOR_NOREPLY;
335 }
336 | RANDOMIZE_REPLICA_READ
337 {
338 $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
339 }
340 | SORT_HOSTS
341 {
342 $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
343 }
344 | SUPPORT_CAS
345 {
346 $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
347 }
348 | _TCP_NODELAY
349 {
350 $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
351 }
352 | _TCP_KEEPALIVE
353 {
354 $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
355 }
356 | _TCP_KEEPIDLE
357 {
358 $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
359 }
360 | USE_UDP
361 {
362 $$= MEMCACHED_BEHAVIOR_USE_UDP;
363 }
364 | VERIFY_KEY
365 {
366 $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
367 }
368
369
370 optional_port:
371 { }
372 | PORT
373 { };
374 ;
375
376 optional_weight:
377 { }
378 | WEIGHT_START
379 { }
380 ;
381
382 hash:
383 MD5
384 {
385 $$= MEMCACHED_HASH_MD5;
386 }
387 | CRC
388 {
389 $$= MEMCACHED_HASH_CRC;
390 }
391 | FNV1_64
392 {
393 $$= MEMCACHED_HASH_FNV1_64;
394 }
395 | FNV1A_64
396 {
397 $$= MEMCACHED_HASH_FNV1A_64;
398 }
399 | FNV1_32
400 {
401 $$= MEMCACHED_HASH_FNV1_32;
402 }
403 | FNV1A_32
404 {
405 $$= MEMCACHED_HASH_FNV1A_32;
406 }
407 | HSIEH
408 {
409 $$= MEMCACHED_HASH_HSIEH;
410 }
411 | MURMUR
412 {
413 $$= MEMCACHED_HASH_MURMUR;
414 }
415 | JENKINS
416 {
417 $$= MEMCACHED_HASH_JENKINS;
418 }
419 ;
420
421 string:
422 STRING
423 {
424 $$= $1;
425 }
426 | QUOTED_STRING
427 {
428 $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
429 $$.length= $1.length -1; // -1 removes the end quote
430 }
431 ;
432
433 distribution:
434 CONSISTENT
435 {
436 $$= MEMCACHED_DISTRIBUTION_CONSISTENT;
437 }
438 | MODULA
439 {
440 $$= MEMCACHED_DISTRIBUTION_MODULA;
441 }
442 | RANDOM
443 {
444 $$= MEMCACHED_DISTRIBUTION_RANDOM;
445 }
446 ;
447
448 %%
449
450 void Context::start()
451 {
452 config_parse(this, (void **)scanner);
453 }
454