1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Libmemcached Scanner and Parser
5 * Copyright (C) 2011 DataDifferental, http://datadifferential.com
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.
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.
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/>.
23 #pragma GCC diagnostic ignored "-Wold-style-cast"
24 #pragma GCC diagnostic ignored "-Wsign-compare"
25 #pragma GCC diagnostic ignored "-Wunused-parameter"
27 #include <libmemcached/options/context.h>
28 #include <libmemcached/options/parser.h>
29 #include <libmemcached/options/string.h>
30 #include <libmemcached/options/symbol.h>
32 #define YY_EXTRA_TYPE Context*
41 #define PARAM yyget_extra(yyscanner)
43 #define get_lex_chars(buffer, result, max_size, context) \
45 if (context->pos >= context->length) \
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; \
59 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
65 %option case-insensitive
69 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
71 %option prefix="config_"
77 =|,|[ ] { return yytext[0];}
79 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
81 :[[:digit:]]{1,5} { yylval->server.port = atoi(yytext +1); return PORT; }
83 "/?"[[:digit:]]{1,5} { yylval->server.weight = atoi(yytext +2); return WEIGHT_START; }
85 [\t\r\n] ; /* skip whitespace */
92 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return SERVER; }
94 "--VERIFY_KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
95 "--VERIFY-KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
96 "--AUTO_EJECT_HOSTS" { yyextra->begin= yytext; return AUTO_EJECT_HOSTS; }
97 "--AUTO-EJECT_HOSTS" { yyextra->begin= yytext; return AUTO_EJECT_HOSTS; }
98 "--BINARY_PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
99 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
100 "--BUFFER_REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
101 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
102 "--CONFIGURE_FILE=" { yyextra->begin= yytext; return CONFIGURE_FILE; }
103 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return CONFIGURE_FILE; }
104 "--CONNECT_TIMEOUT=" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
105 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
106 "--DISTRIBUTION=" { yyextra->begin= yytext; return DISTRIBUTION; }
107 "--HASH=" { yyextra->begin= yytext; return HASH; }
108 "--HASH_WITH_PREFIX_KEY" { yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; }
109 "--HASH-WITH-PREFIX_KEY" { yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; }
110 "--IO_BYTES_WATERMARK=" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
111 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
112 "--IO_KEY_PREFETCH=" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
113 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
114 "--IO_MSG_WATERMARK=" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
115 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
116 "--NOREPLY" { yyextra->begin= yytext; return NOREPLY; }
117 "--NUMBER_OF_REPLICAS=" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
118 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
119 "--POLL_TIMEOUT=" { yyextra->begin= yytext; return POLL_TIMEOUT; }
120 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return POLL_TIMEOUT; }
121 "--RANDOMIZE_REPLICA_READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
122 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
123 "--RCV_TIMEOUT=" { yyextra->begin= yytext; return RCV_TIMEOUT; }
124 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return RCV_TIMEOUT; }
125 "--RETRY_TIMEOUT=" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
126 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
127 "--SERVER_FAILURE_LIMIT=" { yyextra->begin= yytext; return SERVER_FAILURE_LIMIT; }
128 "--SERVER-FAILURE-LIMIT=" { yyextra->begin= yytext; return SERVER_FAILURE_LIMIT; }
129 "--SND_TIMEOUT=" { yyextra->begin= yytext; return SND_TIMEOUT; }
130 "--SND-TIMEOUT=" { yyextra->begin= yytext; return SND_TIMEOUT; }
131 "--SOCKET_RECV_SIZE=" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
132 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
133 "--SOCKET_SEND_SIZE=" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
134 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
135 "--SORT_HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
136 "--SORT-HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
137 "--SUPPORT_CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
138 "--SUPPORT-CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
139 "--TCP_NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
140 "--TCP-NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
141 "--TCP_KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
142 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
143 "--TCP_KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
144 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
145 "--USER_DATA" { yyextra->begin= yytext; return USER_DATA; }
146 "--USER-DATA" { yyextra->begin= yytext; return USER_DATA; }
147 "--USE_UDP" { yyextra->begin= yytext; return USE_UDP; }
148 "--USE-UDP" { yyextra->begin= yytext; return USE_UDP; }
150 "--PREFIX-KEY=" { yyextra->begin= yytext; return PREFIX_KEY; }
151 "--PREFIX_KEY=" { yyextra->begin= yytext; return PREFIX_KEY; }
153 INCLUDE { yyextra->begin= yytext; return INCLUDE; }
154 RESET { yyextra->begin= yytext; return RESET; }
155 DEBUG { yyextra->begin= yytext; return PARSER_DEBUG; }
156 SERVERS { yyextra->begin= yytext; return SERVERS; }
157 END { yyextra->begin= yytext; return END; }
158 ERROR { yyextra->begin= yytext; return ERROR; }
160 TRUE { return TRUE; }
161 FALSE { return FALSE; }
165 yyextra->begin= yytext;
166 return UNKNOWN_OPTION;
169 CONSISTENT { return CONSISTENT; }
170 MODULA { return MODULA; }
171 RANDOM { return RANDOM; }
175 FNV1_64 { return FNV1_64; }
176 FNV1A_64 { return FNV1A_64; }
177 FNV1_32 { return FNV1_32; }
178 FNV1A_32 { return FNV1A_32; }
179 HSIEH { return HSIEH; }
180 MURMUR { return MURMUR; }
181 JENKINS { return JENKINS; }
183 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
184 yylval->server.port= MEMCACHED_DEFAULT_PORT;
185 yylval->server.weight= 1;
186 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
187 if (yylval->server.c_str)
188 yylval->server.length= yyleng;
192 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
193 if (yyextra->is_server())
195 yylval->server.port= MEMCACHED_DEFAULT_PORT;
196 yylval->server.weight= 1;
197 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
198 if (yylval->server.c_str)
199 yylval->server.length= yyleng;
204 yylval->string.c_str = yytext;
205 yylval->string.length = yyleng;
211 yylval->string.c_str = yytext;
212 yylval->string.length = yyleng;
213 return QUOTED_STRING;
217 yyextra->begin= yytext;
223 void Context::init_scanner()
225 yylex_init(&scanner);
226 yyset_extra(this, scanner);
229 void Context::destroy_scanner()
231 yylex_destroy(scanner);