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/symbol.h>
28 #pragma GCC diagnostic ignored "-Wold-style-cast"
29 #pragma GCC diagnostic ignored "-Wsign-compare"
30 #pragma GCC diagnostic ignored "-Wunused-parameter"
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->number= atoi(yytext +1); return PORT; }
83 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
85 [\t\r\n] ; /* skip whitespace */
92 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return SERVER; }
94 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return BINARY_PROTOCOL; }
95 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return BUFFER_REQUESTS; }
96 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return CONFIGURE_FILE; }
97 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
98 "--DISTRIBUTION=" { yyextra->begin= yytext; return DISTRIBUTION; }
99 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return HASH_WITH_NAMESPACE; }
100 "--HASH=" { yyextra->begin= yytext; return HASH; }
101 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
102 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
103 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
104 "--NOREPLY" { yyextra->begin= yytext; return NOREPLY; }
105 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
106 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return POLL_TIMEOUT; }
107 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
108 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return RCV_TIMEOUT; }
109 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return REMOVE_FAILED_SERVERS; }
110 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return RETRY_TIMEOUT; }
111 "--SND-TIMEOUT=" { yyextra->begin= yytext; return SND_TIMEOUT; }
112 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
113 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
114 "--SORT-HOSTS" { yyextra->begin= yytext; return SORT_HOSTS; }
115 "--SUPPORT-CAS" { yyextra->begin= yytext; return SUPPORT_CAS; }
116 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
117 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
118 "--TCP-NODELAY" { yyextra->begin= yytext; return _TCP_NODELAY; }
119 "--USE-UDP" { yyextra->begin= yytext; return USE_UDP; }
120 "--USER-DATA" { yyextra->begin= yytext; return USER_DATA; }
121 "--VERIFY-KEY" { yyextra->begin= yytext; return VERIFY_KEY; }
123 "--POOL-MIN=" { yyextra->begin= yytext; return POOL_MIN; }
124 "--POOL-MAX=" { yyextra->begin= yytext; return POOL_MAX; }
126 "--NAMESPACE=" { yyextra->begin= yytext; return NAMESPACE; }
128 INCLUDE { yyextra->begin= yytext; return INCLUDE; }
129 RESET { yyextra->begin= yytext; return RESET; }
130 DEBUG { yyextra->begin= yytext; return PARSER_DEBUG; }
131 SERVERS { yyextra->begin= yytext; return SERVERS; }
132 END { yyextra->begin= yytext; return END; }
133 ERROR { yyextra->begin= yytext; return ERROR; }
135 TRUE { return TRUE; }
136 FALSE { return FALSE; }
140 yyextra->begin= yytext;
141 return UNKNOWN_OPTION;
144 CONSISTENT { return CONSISTENT; }
145 MODULA { return MODULA; }
146 RANDOM { return RANDOM; }
150 FNV1_64 { return FNV1_64; }
151 FNV1A_64 { return FNV1A_64; }
152 FNV1_32 { return FNV1_32; }
153 FNV1A_32 { return FNV1A_32; }
154 HSIEH { return HSIEH; }
155 MURMUR { return MURMUR; }
156 JENKINS { return JENKINS; }
158 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
159 yylval->server.port= MEMCACHED_DEFAULT_PORT;
160 yylval->server.weight= 1;
161 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
162 if (yylval->server.c_str)
163 yylval->server.size= yyleng;
167 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
168 if (yyextra->is_server())
170 yylval->server.port= MEMCACHED_DEFAULT_PORT;
171 yylval->server.weight= 1;
172 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
173 if (yylval->server.c_str)
174 yylval->server.size= yyleng;
179 yylval->string.c_str = yytext;
180 yylval->string.size = yyleng;
186 yylval->string.c_str = yytext;
187 yylval->string.size = yyleng;
188 return QUOTED_STRING;
192 yyextra->begin= yytext;
198 void Context::init_scanner()
200 yylex_init(&scanner);
201 yyset_extra(this, scanner);
204 void Context::destroy_scanner()
206 yylex_destroy(scanner);