e9957408fa27d9f1ac4e0cedf8c8de98356b23c5
[awesomized/libmemcached] / libmemcached / csl / scanner.l
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached library
4 *
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following disclaimer
16 * in the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 */
36
37
38 %top{
39
40 #include <libmemcached/csl/common.h>
41 #include <libmemcached/csl/context.h>
42 #include <libmemcached/csl/parser.h>
43 #include <libmemcached/csl/symbol.h>
44
45 #ifndef __INTEL_COMPILER
46 #pragma GCC diagnostic ignored "-Wold-style-cast"
47 #pragma GCC diagnostic ignored "-Wsign-compare"
48 #pragma GCC diagnostic ignored "-Wunused-parameter"
49 #pragma GCC diagnostic ignored "-Wmissing-declarations"
50 #pragma GCC diagnostic ignored "-Wunused-result"
51 #pragma GCC diagnostic ignored "-Wshorten-64-to-32"
52 #pragma GCC diagnostic ignored "-Wmissing-noreturn"
53 #endif
54
55 #define YY_EXTRA_TYPE Context*
56
57 }
58
59
60 %{
61 #include <cstdlib>
62 #include <cstring>
63
64 #define PARAM yyget_extra(yyscanner)
65
66 #define get_lex_chars(buffer, result, max_size, context) \
67 { \
68 if (context->pos >= context->length) \
69 { \
70 result= YY_NULL; \
71 } \
72 else \
73 { \
74 result= (int)(context->length - context->pos); \
75 (size_t)result > (size_t)max_size ? result= max_size : 0; \
76 memcpy(buffer, context->buf + context->pos, result); \
77 context->pos += result; \
78 } \
79 }
80
81 #define YY_FATAL_ERROR(msg) \
82 { \
83 }
84
85
86 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
87
88 %}
89
90 %option 8bit
91 %option bison-bridge
92 %option never-interactive
93 %option case-insensitive
94 %option noinput
95 %option nounput
96 %option noyywrap
97 %option outfile="libmemcached/csl/scanner.cc" header-file="libmemcached/csl/scanner.h"
98 %option perf-report
99 %option prefix="config_"
100 %option reentrant
101 %option warn
102
103 %%
104
105
106 =|,|[ ] { return yytext[0];}
107
108 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
109
110 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
111
112 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
113
114 [\t\r\n] ; /* skip whitespace */
115
116
117 ^#.*$ {
118 return COMMENT;
119 }
120
121 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; }
122
123 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
124
125 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; }
126 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; }
127 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; }
128 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; }
129 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; }
130 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; }
131 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; }
132 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; }
133 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; }
134 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; }
135 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; }
136 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; }
137 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; }
138 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; }
139 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; }
140 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; }
141 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; }
142 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; }
143 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; }
144 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; }
145 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; }
146 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; }
147 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; }
148 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; }
149 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; }
150 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; }
151 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; }
152 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; }
153
154 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
155 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
156
157 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
158
159 "--FETCH-VERSION" { yyextra->begin= yytext; return yyextra->previous_token= FETCH_VERSION; }
160
161 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; }
162 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; }
163 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; }
164 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; }
165 END { yyextra->begin= yytext; return yyextra->previous_token= END; }
166 ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; }
167
168 TRUE { return yyextra->previous_token= TRUE; }
169 FALSE { return yyextra->previous_token= FALSE; }
170
171
172 "--"[[:alnum:]]* {
173 yyextra->begin= yytext;
174 return UNKNOWN_OPTION;
175 }
176
177 CONSISTENT { return CONSISTENT; }
178 MODULA { return MODULA; }
179 RANDOM { return RANDOM; }
180
181 MD5 { return MD5; }
182 CRC { return CRC; }
183 FNV1_64 { return FNV1_64; }
184 FNV1A_64 { return FNV1A_64; }
185 FNV1_32 { return FNV1_32; }
186 FNV1A_32 { return FNV1A_32; }
187 HSIEH { return HSIEH; }
188 MURMUR { return MURMUR; }
189 JENKINS { return JENKINS; }
190
191 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
192 yyextra->hostname(yytext, yyleng, yylval->server);
193 return IPADDRESS;
194 }
195
196 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
197 if (yyextra->is_server())
198 {
199 yyextra->hostname(yytext, yyleng, yylval->server);
200
201 return HOSTNAME;
202 }
203
204 yyextra->string_buffer(yytext, yyleng, yylval->string);
205
206 return STRING;
207 }
208
209 L?\"(\\.|[^\\"])*\" {
210 yyget_text(yyscanner)[yyleng -1]= 0;
211 yyextra->string_buffer(yytext +1, yyleng -2, yylval->string);
212 return QUOTED_STRING;
213 }
214
215 . {
216 yyextra->begin= yytext;
217 return UNKNOWN;
218 }
219
220 %%
221
222 void Context::init_scanner()
223 {
224 yylex_init(&scanner);
225 yyset_extra(this, scanner);
226 }
227
228 void Context::destroy_scanner()
229 {
230 (void)yy_fatal_error; // Removes warning about unused yy_fatal_error()
231 yylex_destroy(scanner);
232 }
233