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 "-Wunused-parameter"
25 #pragma GCC diagnostic ignored "-fpermissive"
29 #include <libmemcached/options/context.h>
30 #include <libmemcached/options/parser.h>
31 #include <libmemcached/options/string.h>
32 #include <libmemcached/options/symbol.h>
34 #define YY_EXTRA_TYPE Context*
35 #define YY_USER_ACTION yylloc->first_line = yylineno;
44 #define PARAM yyget_extra(yyscanner)
46 static void get_lex_chars(char* buffer, int& result, int max_size, Context *context)
48 if (context->pos >= context->length)
54 result= context->length - context->pos;
55 result > (int)max_size ? result = max_size : 0;
56 memcpy(buffer, context->buf + context->pos, result);
57 context->pos += result;
62 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
67 %option bison-locations
68 %option case-insensitive
73 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
75 %option prefix="libmemcached_"
81 =|,|[ ] { return yytext[0];}
84 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
86 [\t\r\n] ; /* skip whitespace */
92 "--SERVER" { yyextra->begin= yytext; return SERVER; }
93 "--SERVERS" { yyextra->begin= yytext; return SERVERS_OPTION; }
95 "--VERIFY_KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
96 "--VERIFY-KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
97 "--AUTO_EJECT_HOSTS" { yyextra->begin= yytext; return AUTO_EJECT_HOSTS; }
98 "--AUTO-EJECT_HOSTS" { yyextra->begin= yytext; return AUTO_EJECT_HOSTS; }
99 "--BINARY_PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
100 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
101 "--BUFFER_REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
102 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
103 "--CACHE_LOOKUPS" { yyextra->begin= yytext; return CACHE_LOOKUPS; }
104 "--CACHE-LOOKUPS" { yyextra->begin= yytext; return CACHE_LOOKUPS; }
105 "--CONFIGURE_FILE" { yyextra->begin= yytext; return CONFIGURE_FILE; }
106 "--CONFIGURE-FILE" { yyextra->begin= yytext; return CONFIGURE_FILE; }
107 "--CONNECT_TIMEOUT" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
108 "--CONNECT-TIMEOUT" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
109 "--CORK" { yyextra->begin= yytext; return _CORK; }
110 "--DISTRIBUTION" { yyextra->begin= yytext; return DISTRIBUTION; }
111 "--HASH" { yyextra->begin= yytext; return HASH; }
112 "--HASH_WITH_PREFIX_KEY" { yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; }
113 "--HASH-WITH-PREFIX_KEY" { yyextra->begin= yytext; return HASH_WITH_PREFIX_KEY; }
114 "--IO_BYTES_WATERMARK" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
115 "--IO-BYTES-WATERMARK" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
116 "--IO_KEY_PREFETCH" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
117 "--IO-KEY-PREFETCH" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
118 "--IO_MSG_WATERMARK" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
119 "--IO-MSG-WATERMARK" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
120 "--KETAMA" { yyextra->begin= yytext; return KETAMA; }
121 "--KETAMA_HASH" { yyextra->begin= yytext; return KETAMA_HASH; }
122 "--KETAMA-HASH" { yyextra->begin= yytext; return KETAMA_HASH; }
123 "--KETAMA_WEIGHTED" { yyextra->begin= yytext; return KETAMA_WEIGHTED; }
124 "--KETAMA-WEIGHTED" { yyextra->begin= yytext; return KETAMA_WEIGHTED; }
125 "--NOREPLY" { yyextra->begin= yytext; return NOREPLY; }
126 "--NUMBER_OF_REPLICAS" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
127 "--NUMBER-OF-REPLICAS" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
128 "--POLL_TIMEOUT" { yyextra->begin= yytext; return POLL_TIMEOUT; }
129 "--POLL-TIMEOUT" { yyextra->begin= yytext; return POLL_TIMEOUT; }
130 "--RANDOMIZE_REPLICA_READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
131 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
132 "--RCV_TIMEOUT" { yyextra->begin= yytext; return RCV_TIMEOUT; }
133 "--RCV-TIMEOUT" { yyextra->begin= yytext; return RCV_TIMEOUT; }
134 "--RETRY_TIMEOUT" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
135 "--RETRY-TIMEOUT" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
136 "--SERVER_FAILURE_LIMIT" { yyextra->begin= yytext; return SERVER_FAILURE_LIMIT; }
137 "--SERVER-FAILURE-LIMIT" { yyextra->begin= yytext; return SERVER_FAILURE_LIMIT; }
138 "--SND_TIMEOUT" { yyextra->begin= yytext; return SND_TIMEOUT; }
139 "--SND-TIMEOUT" { yyextra->begin= yytext; return SND_TIMEOUT; }
140 "--SOCKET_RECV_SIZE" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
141 "--SOCKET-RECV-SIZE" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
142 "--SOCKET_SEND_SIZE" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
143 "--SOCKET-SEND-SIZE" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
144 "--SORT_HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
145 "--SORT-HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
146 "--SUPPORT_CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
147 "--SUPPORT-CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
148 "--TCP_NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
149 "--TCP-NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
150 "--TCP_KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
151 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
152 "--TCP_KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
153 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
154 "--USER_DATA" { yyextra->begin= yytext; return USER_DATA; }
155 "--USER-DATA" { yyextra->begin= yytext; return USER_DATA; }
156 "--USE_UDP" { yyextra->begin= yytext; return USE_UDP; }
157 "--USE-UDP" { yyextra->begin= yytext; return USE_UDP; }
159 "--PREFIX-KEY" { yyextra->begin= yytext; return PREFIX_KEY; }
160 "--PREFIX_KEY" { yyextra->begin= yytext; return PREFIX_KEY; }
162 INCLUDE { yyextra->begin= yytext; std::cerr << "Found INCLUDE" << std::endl; return INCLUDE; }
163 RESET { yyextra->begin= yytext; return RESET; }
164 DEBUG { yyextra->begin= yytext; return DEBUG; }
165 SERVERS { yyextra->begin= yytext; return SERVERS; }
166 END { yyextra->begin= yytext; return END; }
168 TRUE { return TRUE; }
169 FALSE { return FALSE; }
173 yyextra->begin= yytext;
174 return UNKNOWN_OPTION;
177 CONSISTENT { return CONSISTENT; }
178 MODULA { return MODULA; }
179 RANDOM { return RANDOM; }
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; }
191 [[:alnum:]][[:alnum:].]*[[:alpha:]]: {
192 yylval->string.c_str = yytext;
193 yylval->string.length = yyleng;
194 return HOSTNAME_WITH_PORT;
197 [[:alnum:]]+"."[[:alpha:].]+[[:alnum:]] {
198 yylval->string.c_str = yytext;
199 yylval->string.length = yyleng;
203 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})): {
204 yylval->string.c_str = yytext;
205 yylval->string.length = yyleng;
206 return IPADDRESS_WITH_PORT;
209 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
210 yylval->string.c_str = yytext;
211 yylval->string.length = yyleng;
216 yylval->string.c_str = yytext;
217 yylval->string.length = yyleng;
222 yylval->string.c_str = yytext;
223 yylval->string.length = yyleng;
224 return QUOTED_STRING;
228 yyextra->begin= yytext;
234 void Context::init_scanner()
236 yylex_init(&scanner);
237 yyset_extra(this, scanner);
240 void Context::destroy_scanner()
242 yylex_destroy(scanner);