1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
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
19 * * The names of its contributors may not be used to endorse or
20 * promote products derived from this software without specific prior
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.
40 #include <libmemcached/csl/common.h>
41 #include <libmemcached/csl/context.h>
42 #include <libmemcached/csl/parser.h>
43 #include <libmemcached/csl/symbol.h>
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"
52 #define YY_EXTRA_TYPE Context*
61 #define PARAM yyget_extra(yyscanner)
63 #define get_lex_chars(buffer, result, max_size, context) \
65 if (context->pos >= context->length) \
71 result= (int)(context->length - context->pos); \
72 (size_t)result > (size_t)max_size ? result= max_size : 0; \
73 memcpy(buffer, context->buf + context->pos, result); \
74 context->pos += result; \
78 #define YY_FATAL_ERROR(msg) \
83 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
89 %option never-interactive
90 %option case-insensitive
94 %option outfile="libmemcached/csl/scanner.cc" header-file="libmemcached/csl/scanner.h"
96 %option prefix="config_"
103 =|,|[ ] { return yytext[0];}
105 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
107 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
109 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
111 [\t\r\n] ; /* skip whitespace */
118 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; }
120 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
122 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; }
123 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; }
124 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; }
125 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; }
126 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; }
127 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; }
128 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; }
129 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; }
130 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; }
131 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; }
132 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; }
133 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; }
134 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; }
135 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; }
136 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; }
137 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; }
138 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; }
139 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; }
140 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; }
141 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; }
142 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; }
143 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; }
144 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; }
145 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; }
146 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; }
147 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; }
148 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; }
149 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; }
151 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
152 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
154 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
156 "--FETCH-VERSION" { yyextra->begin= yytext; return yyextra->previous_token= FETCH_VERSION; }
158 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; }
159 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; }
160 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; }
161 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; }
162 END { yyextra->begin= yytext; return yyextra->previous_token= END; }
163 ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; }
165 TRUE { return yyextra->previous_token= TRUE; }
166 FALSE { return yyextra->previous_token= FALSE; }
170 yyextra->begin= yytext;
171 return UNKNOWN_OPTION;
174 CONSISTENT { return CONSISTENT; }
175 MODULA { return MODULA; }
176 RANDOM { return RANDOM; }
180 FNV1_64 { return FNV1_64; }
181 FNV1A_64 { return FNV1A_64; }
182 FNV1_32 { return FNV1_32; }
183 FNV1A_32 { return FNV1A_32; }
184 HSIEH { return HSIEH; }
185 MURMUR { return MURMUR; }
186 JENKINS { return JENKINS; }
188 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
189 yyextra->hostname(yytext, yyleng, yylval->server);
193 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
194 if (yyextra->is_server())
196 yyextra->hostname(yytext, yyleng, yylval->server);
201 yyextra->string_buffer(yytext, yyleng, yylval->string);
206 L?\"(\\.|[^\\"])*\" {
207 yyget_text(yyscanner)[yyleng -1]= 0;
208 yyextra->string_buffer(yytext +1, yyleng -2, yylval->string);
209 return QUOTED_STRING;
213 yyextra->begin= yytext;
219 void Context::init_scanner()
221 yylex_init(&scanner);
222 yyset_extra(this, scanner);
225 void Context::destroy_scanner()
227 (void)yy_fatal_error; // Removes warning about unused yy_fatal_error()
228 yylex_destroy(scanner);