Merge in all of the new parser work.
[awesomized/libmemcached] / libmemcached / options / parser.yy
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached library
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
22 * written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38 %{
39
40 #include <stdint.h>
41 #include <iostream>
42
43 #include <libmemcached/options/type.h>
44 #include <libmemcached/options/string.h>
45 #include <libmemcached/options/symbol.h>
46
47 #pragma GCC diagnostic ignored "-Wold-style-cast"
48 #include <libmemcached/options/scanner.h>
49
50 inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner, const char *str)
51 {
52 std::cerr << str << std::endl;
53 return 0;
54 }
55
56
57 %}
58
59 %error-verbose
60 %debug
61 %defines
62 %expect 0
63 %output "libmemcached/options/parser.cc"
64 %defines "libmemcached/options/parser.h"
65 %lex-param { yyscan_t *scanner }
66 %name-prefix="libmemcached_"
67 %parse-param { type_st *parser }
68 %parse-param { yyscan_t *scanner }
69 %locations
70 %pure-parser
71 %require "2.2"
72 %start statement
73 %verbose
74
75 %token EQ
76 %token SERVER
77 %token SERVERS
78 %token TCPNODELAY
79 %token UNKNOWN
80 %token VERIFY_KEY
81 %token COMMA
82
83 %token <number> NUMBER
84 %token <number> FLOAT
85 %token <string> IDENTIFIER
86 %token <string> SERVER_WITH_PORT
87
88 %type <server> server
89
90 %%
91
92 statement:
93 expression
94 { }
95 | statement expression
96 { }
97 ;
98
99
100 expression:
101 SERVER EQ server
102 {
103 (void) memcached_server_add(parser->memc, $3.c_str, $3.port);
104 }
105 | SERVERS EQ server_list
106 { }
107 | TCPNODELAY
108 {
109 memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true);
110 }
111 | VERIFY_KEY
112 {
113 memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, true);
114 }
115 ;
116
117 server_list:
118 server
119 {
120 (void) memcached_server_add(parser->memc, $1.c_str, $1.port);
121 }
122 | server_list COMMA server
123 {
124 (void) memcached_server_add(parser->memc, $3.c_str, $3.port);
125 }
126 ;
127
128 server:
129 SERVER_WITH_PORT NUMBER
130 {
131 $$.c_str= $1.c_str;
132 $$.length= $1.length;
133 $$.port= $2;
134 }
135 | IDENTIFIER
136 {
137 $$.c_str= $1.c_str;
138 $$.length= $1.length;
139 $$.port= 80;
140 }
141 ;