Update all licenses to BSD.
[m6w6/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 #endif
50
51 #define YY_NO_INPUT
52
53 #define YY_EXTRA_TYPE Context*
54
55 }
56
57
58 %{
59 #include <cstdlib>
60 #include <cstring>
61
62 #define PARAM yyget_extra(yyscanner)
63
64 #define get_lex_chars(buffer, result, max_size, context) \
65 { \
66 if (context->pos >= context->length) \
67 { \
68 result= YY_NULL; \
69 } \
70 else \
71 { \
72 result= (int)(context->length - context->pos); \
73 (size_t)result > (size_t)max_size ? result= max_size : 0; \
74 memcpy(buffer, context->buf + context->pos, result); \
75 context->pos += result; \
76 } \
77 }
78
79
80 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
81
82 %}
83
84 %option 8bit
85 %option bison-bridge
86 %option case-insensitive
87 %option debug
88 %option nounput
89 %option noyywrap
90 %option outfile="libmemcached/csl/scanner.cc" header-file="libmemcached/csl/scanner.h"
91 %option perf-report
92 %option prefix="config_"
93 %option reentrant
94
95 %%
96
97
98 =|,|[ ] { return yytext[0];}
99
100 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
101
102 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
103
104 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
105
106 [\t\r\n] ; /* skip whitespace */
107
108
109 ^#.*$ {
110 return COMMENT;
111 }
112
113 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; }
114
115 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
116
117 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; }
118 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; }
119 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; }
120 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; }
121 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; }
122 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; }
123 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; }
124 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; }
125 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; }
126 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; }
127 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; }
128 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; }
129 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; }
130 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; }
131 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; }
132 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; }
133 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; }
134 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; }
135 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; }
136 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; }
137 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; }
138 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; }
139 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; }
140 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; }
141 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; }
142 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; }
143 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; }
144 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; }
145
146 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
147 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
148
149 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
150
151 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; }
152 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; }
153 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; }
154 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; }
155 END { yyextra->begin= yytext; return yyextra->previous_token= END; }
156 ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; }
157
158 TRUE { return yyextra->previous_token= TRUE; }
159 FALSE { return yyextra->previous_token= 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.size= 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.size= yyleng;
198
199 return HOSTNAME;
200 }
201
202 yylval->string.c_str = yytext;
203 yylval->string.size = yyleng;
204
205 return STRING;
206 }
207
208 L?\"(\\.|[^\\"])*\" {
209 yyget_text(yyscanner)[yyleng -1]= 0;
210 yylval->string.c_str= yytext +1;
211 yylval->string.size= yyleng -2;
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 yylex_destroy(scanner);
231 }
232