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 #ifndef __INTEL_COMPILER
29 #pragma GCC diagnostic ignored "-Wold-style-cast"
30 #pragma GCC diagnostic ignored "-Wsign-compare"
31 #pragma GCC diagnostic ignored "-Wunused-parameter"
34 #define YY_EXTRA_TYPE Context*
43 #define PARAM yyget_extra(yyscanner)
45 #define get_lex_chars(buffer, result, max_size, context) \
47 if (context->pos >= context->length) \
53 result= (int)(context->length - context->pos); \
54 (size_t)result > (size_t)max_size ? result= max_size : 0; \
55 memcpy(buffer, context->buf + context->pos, result); \
56 context->pos += result; \
61 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
67 %option case-insensitive
71 %option outfile="libmemcached/csl/scanner.cc" header-file="libmemcached/csl/scanner.h"
73 %option prefix="config_"
79 =|,|[ ] { return yytext[0];}
81 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
83 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
85 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
87 [\t\r\n] ; /* skip whitespace */
94 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; }
96 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
98 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; }
99 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; }
100 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; }
101 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; }
102 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; }
103 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; }
104 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; }
105 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; }
106 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; }
107 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; }
108 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; }
109 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; }
110 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; }
111 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; }
112 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; }
113 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; }
114 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; }
115 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; }
116 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; }
117 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; }
118 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; }
119 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; }
120 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; }
121 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; }
122 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; }
123 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; }
124 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; }
125 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; }
127 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
128 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
130 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
132 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; }
133 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; }
134 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; }
135 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; }
136 END { yyextra->begin= yytext; return yyextra->previous_token= END; }
137 ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; }
139 TRUE { return yyextra->previous_token= TRUE; }
140 FALSE { return yyextra->previous_token= FALSE; }
144 yyextra->begin= yytext;
145 return UNKNOWN_OPTION;
148 CONSISTENT { return CONSISTENT; }
149 MODULA { return MODULA; }
150 RANDOM { return RANDOM; }
154 FNV1_64 { return FNV1_64; }
155 FNV1A_64 { return FNV1A_64; }
156 FNV1_32 { return FNV1_32; }
157 FNV1A_32 { return FNV1A_32; }
158 HSIEH { return HSIEH; }
159 MURMUR { return MURMUR; }
160 JENKINS { return JENKINS; }
162 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
163 yylval->server.port= MEMCACHED_DEFAULT_PORT;
164 yylval->server.weight= 1;
165 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
166 if (yylval->server.c_str)
167 yylval->server.size= yyleng;
171 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
172 if (yyextra->is_server())
174 yylval->server.port= MEMCACHED_DEFAULT_PORT;
175 yylval->server.weight= 1;
176 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
177 if (yylval->server.c_str)
178 yylval->server.size= yyleng;
183 yylval->string.c_str = yytext;
184 yylval->string.size = yyleng;
189 L?\"(\\.|[^\\"])*\" {
190 yyget_text(yyscanner)[yyleng -1]= 0;
191 yylval->string.c_str= yytext +1;
192 yylval->string.size= yyleng -2;
193 return QUOTED_STRING;
197 yyextra->begin= yytext;
203 void Context::init_scanner()
205 yylex_init(&scanner);
206 yyset_extra(this, scanner);
209 void Context::destroy_scanner()
211 yylex_destroy(scanner);