1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 * Configure Scripting Language
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/csl/common.h>
24 #include <libmemcached/csl/context.h>
25 #include <libmemcached/csl/parser.h>
26 #include <libmemcached/csl/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/csl/scanner.cc" header-file="libmemcached/csl/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 yyextra->previous_token= SERVER; }
94 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
96 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; }
97 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; }
98 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; }
99 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; }
100 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; }
101 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; }
102 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; }
103 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; }
104 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; }
105 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; }
106 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; }
107 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; }
108 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; }
109 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; }
110 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; }
111 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; }
112 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; }
113 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; }
114 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; }
115 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; }
116 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; }
117 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; }
118 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; }
119 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; }
120 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; }
121 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; }
122 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; }
123 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; }
125 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
126 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
128 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
130 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; }
131 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; }
132 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; }
133 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; }
134 END { yyextra->begin= yytext; return yyextra->previous_token= END; }
135 ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; }
137 TRUE { return yyextra->previous_token= TRUE; }
138 FALSE { return yyextra->previous_token= FALSE; }
142 yyextra->begin= yytext;
143 return UNKNOWN_OPTION;
146 CONSISTENT { return CONSISTENT; }
147 MODULA { return MODULA; }
148 RANDOM { return RANDOM; }
152 FNV1_64 { return FNV1_64; }
153 FNV1A_64 { return FNV1A_64; }
154 FNV1_32 { return FNV1_32; }
155 FNV1A_32 { return FNV1A_32; }
156 HSIEH { return HSIEH; }
157 MURMUR { return MURMUR; }
158 JENKINS { return JENKINS; }
160 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
161 yylval->server.port= MEMCACHED_DEFAULT_PORT;
162 yylval->server.weight= 1;
163 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
164 if (yylval->server.c_str)
165 yylval->server.size= yyleng;
169 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
170 if (yyextra->is_server())
172 yylval->server.port= MEMCACHED_DEFAULT_PORT;
173 yylval->server.weight= 1;
174 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
175 if (yylval->server.c_str)
176 yylval->server.size= yyleng;
181 yylval->string.c_str = yytext;
182 yylval->string.size = yyleng;
187 L?\"(\\.|[^\\"])*\" {
188 yyget_text(yyscanner)[yyleng -1]= 0;
189 yylval->string.c_str= yytext +1;
190 yylval->string.size= yyleng -2;
191 return QUOTED_STRING;
195 yyextra->begin= yytext;
201 void Context::init_scanner()
203 yylex_init(&scanner);
204 yyset_extra(this, scanner);
207 void Context::destroy_scanner()
209 yylex_destroy(scanner);