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 #include <libmemcached/common.h>
24 #include <libmemcached/options/context.h>
25 #include <libmemcached/options/parser.h>
26 #include <libmemcached/options/string.h>
27 #include <libmemcached/options/symbol.h>
29 #pragma GCC diagnostic ignored "-Wold-style-cast"
30 #pragma GCC diagnostic ignored "-Wsign-compare"
31 #pragma GCC diagnostic ignored "-Wunused-parameter"
33 #define YY_EXTRA_TYPE Context*
42 #define PARAM yyget_extra(yyscanner)
44 #define get_lex_chars(buffer, result, max_size, context) \
46 if (context->pos >= context->length) \
52 result= (int)(context->length - context->pos); \
53 (size_t)result > (size_t)max_size ? result= max_size : 0; \
54 memcpy(buffer, context->buf + context->pos, result); \
55 context->pos += result; \
60 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
66 %option case-insensitive
70 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
72 %option prefix="config_"
78 =|,|[ ] { return yytext[0];}
80 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
82 :[[:digit:]]{1,5} { yylval->server.port = atoi(yytext +1); return PORT; }
84 "/?"[[:digit:]]{1,5} { yylval->server.weight = atoi(yytext +2); return WEIGHT_START; }
86 [\t\r\n] ; /* skip whitespace */
93 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return SERVER; }
95 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
96 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
97 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return CONFIGURE_FILE; }
98 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
99 "--DISTRIBUTION=" { yyextra->begin= yytext; return DISTRIBUTION; }
100 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return HASH_WITH_NAMESPACE; }
101 "--HASH=" { yyextra->begin= yytext; return HASH; }
102 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
103 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
104 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
105 "--NOREPLY" { yyextra->begin= yytext; return NOREPLY; }
106 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
107 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return POLL_TIMEOUT; }
108 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
109 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return RCV_TIMEOUT; }
110 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return REMOVE_FAILED_SERVERS; }
111 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
112 "--SND-TIMEOUT=" { yyextra->begin= yytext; return SND_TIMEOUT; }
113 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
114 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
115 "--SORT-HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
116 "--SUPPORT-CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
117 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
118 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
119 "--TCP-NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
120 "--USE-UDP" { yyextra->begin= yytext; return USE_UDP; }
121 "--USER-DATA" { yyextra->begin= yytext; return USER_DATA; }
122 "--VERIFY-KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
124 "--POOL-MIN=" { yyextra->begin= yytext; return POOL_MIN; }
125 "--POOL-MAX=" { yyextra->begin= yytext; return POOL_MAX; }
127 "--NAMESPACE=" { yyextra->begin= yytext; return NAMESPACE; }
129 INCLUDE { yyextra->begin= yytext; return INCLUDE; }
130 RESET { yyextra->begin= yytext; return RESET; }
131 DEBUG { yyextra->begin= yytext; return PARSER_DEBUG; }
132 SERVERS { yyextra->begin= yytext; return SERVERS; }
133 END { yyextra->begin= yytext; return END; }
134 ERROR { yyextra->begin= yytext; return ERROR; }
136 TRUE { return TRUE; }
137 FALSE { return FALSE; }
141 yyextra->begin= yytext;
142 return UNKNOWN_OPTION;
145 CONSISTENT { return CONSISTENT; }
146 MODULA { return MODULA; }
147 RANDOM { return RANDOM; }
151 FNV1_64 { return FNV1_64; }
152 FNV1A_64 { return FNV1A_64; }
153 FNV1_32 { return FNV1_32; }
154 FNV1A_32 { return FNV1A_32; }
155 HSIEH { return HSIEH; }
156 MURMUR { return MURMUR; }
157 JENKINS { return JENKINS; }
159 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
160 yylval->server.port= MEMCACHED_DEFAULT_PORT;
161 yylval->server.weight= 1;
162 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
163 if (yylval->server.c_str)
164 yylval->server.length= yyleng;
168 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
169 if (yyextra->is_server())
171 yylval->server.port= MEMCACHED_DEFAULT_PORT;
172 yylval->server.weight= 1;
173 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
174 if (yylval->server.c_str)
175 yylval->server.length= yyleng;
180 yylval->string.c_str = yytext;
181 yylval->string.length = yyleng;
187 yylval->string.c_str = yytext;
188 yylval->string.length = yyleng;
189 return QUOTED_STRING;
193 yyextra->begin= yytext;
199 void Context::init_scanner()
201 yylex_init(&scanner);
202 yyset_extra(this, scanner);
205 void Context::destroy_scanner()
207 yylex_destroy(scanner);