Merge in more documentation.
[awesomized/libmemcached] / libmemcached / options / scanner.l
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 %top{
22
23 #pragma GCC diagnostic ignored "-Wold-style-cast"
24 #pragma GCC diagnostic ignored "-Wsign-compare"
25 #pragma GCC diagnostic ignored "-Wunused-parameter"
26
27 #include <libmemcached/options/context.h>
28 #include <libmemcached/options/parser.h>
29 #include <libmemcached/options/string.h>
30 #include <libmemcached/options/symbol.h>
31
32 #define YY_EXTRA_TYPE Context*
33
34 }
35
36
37 %{
38 #include <cstdlib>
39 #include <cstring>
40
41 #define PARAM yyget_extra(yyscanner)
42
43 #define get_lex_chars(buffer, result, max_size, context) \
44 { \
45 if (context->pos >= context->length) \
46 { \
47 result= YY_NULL; \
48 } \
49 else \
50 { \
51 result= (int)(context->length - context->pos); \
52 (size_t)result > (size_t)max_size ? result= max_size : 0; \
53 memcpy(buffer, context->buf + context->pos, result); \
54 context->pos += result; \
55 } \
56 }
57
58
59 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
60
61 %}
62
63 %option 8bit
64 %option bison-bridge
65 %option case-insensitive
66 %option debug
67 %option nounput
68 %option noyywrap
69 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
70 %option perf-report
71 %option prefix="config_"
72 %option reentrant
73
74 %%
75
76
77 =|,|[ ] { return yytext[0];}
78
79 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
80
81 :[[:digit:]]{1,5} { yylval->server.port = atoi(yytext +1); return PORT; }
82
83 "/?"[[:digit:]]{1,5} { yylval->server.weight = atoi(yytext +2); return WEIGHT_START; }
84
85 [\t\r\n] ; /* skip whitespace */
86
87
88 ^#.*$ {
89 return COMMENT;
90 }
91
92 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return SERVER; }
93
94 "--VERIFY_KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
95 "--VERIFY-KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
96 "--BINARY_PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
97 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
98 "--BUFFER_REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
99 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
100 "--CONFIGURE_FILE=" { yyextra->begin= yytext; return CONFIGURE_FILE; }
101 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return CONFIGURE_FILE; }
102 "--CONNECT_TIMEOUT=" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
103 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
104 "--DISTRIBUTION=" { yyextra->begin= yytext; return DISTRIBUTION; }
105 "--HASH=" { yyextra->begin= yytext; return HASH; }
106 "--HASH_WITH_PREFIX_KEY" { yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; }
107 "--HASH-WITH-PREFIX_KEY" { yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; }
108 "--IO_BYTES_WATERMARK=" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
109 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
110 "--IO_KEY_PREFETCH=" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
111 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
112 "--IO_MSG_WATERMARK=" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
113 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
114 "--NOREPLY" { yyextra->begin= yytext; return NOREPLY; }
115 "--NUMBER_OF_REPLICAS=" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
116 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
117 "--POLL_TIMEOUT=" { yyextra->begin= yytext; return POLL_TIMEOUT; }
118 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return POLL_TIMEOUT; }
119 "--RANDOMIZE_REPLICA_READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
120 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
121 "--RCV_TIMEOUT=" { yyextra->begin= yytext; return RCV_TIMEOUT; }
122 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return RCV_TIMEOUT; }
123 "--RETRY_TIMEOUT=" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
124 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
125 "--SND_TIMEOUT=" { yyextra->begin= yytext; return SND_TIMEOUT; }
126 "--SND-TIMEOUT=" { yyextra->begin= yytext; return SND_TIMEOUT; }
127 "--REMOVE_FAILED_SERVERS=" { yyextra->begin= yytext; return REMOVE_FAILED_SERVERS; }
128 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return REMOVE_FAILED_SERVERS; }
129 "--SOCKET_RECV_SIZE=" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
130 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
131 "--SOCKET_SEND_SIZE=" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
132 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
133 "--SORT_HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
134 "--SORT-HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
135 "--SUPPORT_CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
136 "--SUPPORT-CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
137 "--TCP_NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
138 "--TCP-NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
139 "--TCP_KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
140 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
141 "--TCP_KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
142 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
143 "--USER_DATA" { yyextra->begin= yytext; return USER_DATA; }
144 "--USER-DATA" { yyextra->begin= yytext; return USER_DATA; }
145 "--USE_UDP" { yyextra->begin= yytext; return USE_UDP; }
146 "--USE-UDP" { yyextra->begin= yytext; return USE_UDP; }
147
148 "--PREFIX-KEY=" { yyextra->begin= yytext; return PREFIX_KEY; }
149 "--PREFIX_KEY=" { yyextra->begin= yytext; return PREFIX_KEY; }
150
151 INCLUDE { yyextra->begin= yytext; return INCLUDE; }
152 RESET { yyextra->begin= yytext; return RESET; }
153 DEBUG { yyextra->begin= yytext; return PARSER_DEBUG; }
154 SERVERS { yyextra->begin= yytext; return SERVERS; }
155 END { yyextra->begin= yytext; return END; }
156 ERROR { yyextra->begin= yytext; return ERROR; }
157
158 TRUE { return TRUE; }
159 FALSE { return FALSE; }
160
161
162 "--"[[:alnum:]]* {
163 yyextra->begin= yytext;
164 return UNKNOWN_OPTION;
165 }
166
167 CONSISTENT { return CONSISTENT; }
168 MODULA { return MODULA; }
169 RANDOM { return RANDOM; }
170
171 MD5 { return MD5; }
172 CRC { return CRC; }
173 FNV1_64 { return FNV1_64; }
174 FNV1A_64 { return FNV1A_64; }
175 FNV1_32 { return FNV1_32; }
176 FNV1A_32 { return FNV1A_32; }
177 HSIEH { return HSIEH; }
178 MURMUR { return MURMUR; }
179 JENKINS { return JENKINS; }
180
181 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
182 yylval->server.port= MEMCACHED_DEFAULT_PORT;
183 yylval->server.weight= 1;
184 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
185 if (yylval->server.c_str)
186 yylval->server.length= yyleng;
187 return IPADDRESS;
188 }
189
190 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
191 if (yyextra->is_server())
192 {
193 yylval->server.port= MEMCACHED_DEFAULT_PORT;
194 yylval->server.weight= 1;
195 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
196 if (yylval->server.c_str)
197 yylval->server.length= yyleng;
198
199 return HOSTNAME;
200 }
201
202 yylval->string.c_str = yytext;
203 yylval->string.length = yyleng;
204
205 return STRING;
206 }
207
208 (\".*\") {
209 yylval->string.c_str = yytext;
210 yylval->string.length = yyleng;
211 return QUOTED_STRING;
212 }
213
214 . {
215 yyextra->begin= yytext;
216 return UNKNOWN;
217 }
218
219 %%
220
221 void Context::init_scanner()
222 {
223 yylex_init(&scanner);
224 yyset_extra(this, scanner);
225 }
226
227 void Context::destroy_scanner()
228 {
229 yylex_destroy(scanner);
230 }
231