Merge in code such that we are much closer to running the same test
[awesomized/libmemcached] / libmemcached / options / scanner.l
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached Scanner and Parser
4 *
5 * Copyright (C) 2011 DataDifferental, http://datadifferential.com
6 *
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.
11 *
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.
16 *
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/>.
19 */
20
21 %top{
22
23 #include <libmemcached/common.h>
24 #include <libmemcached/options/context.h>
25 #include <libmemcached/options/parser.h>
26 #include <libmemcached/options/symbol.h>
27
28 #pragma GCC diagnostic ignored "-Wold-style-cast"
29 #pragma GCC diagnostic ignored "-Wsign-compare"
30 #pragma GCC diagnostic ignored "-Wunused-parameter"
31
32 #define YY_EXTRA_TYPE Context*
33
34 }
35
36
37 %{
38 #include <cstdlib>
39 #include <cstring>
40
41 #define PARAM yyget_extra(yyscanner)
42
43 #define get_lex_chars(buffer, result, max_size, context) \
44 { \
45 if (context->pos >= context->length) \
46 { \
47 result= YY_NULL; \
48 } \
49 else \
50 { \
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; \
55 } \
56 }
57
58
59 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
60
61 %}
62
63 %option 8bit
64 %option bison-bridge
65 %option case-insensitive
66 %option debug
67 %option nounput
68 %option noyywrap
69 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
70 %option perf-report
71 %option prefix="config_"
72 %option reentrant
73
74 %%
75
76
77 =|,|[ ] { return yytext[0];}
78
79 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
80
81 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
82
83 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
84
85 [\t\r\n] ; /* skip whitespace */
86
87
88 ^#.*$ {
89 return COMMENT;
90 }
91
92 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return SERVER; }
93
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; }
122
123 "--POOL-MIN=" { yyextra->begin= yytext; return POOL_MIN; }
124 "--POOL-MAX=" { yyextra->begin= yytext; return POOL_MAX; }
125
126 "--NAMESPACE=" { yyextra->begin= yytext; return NAMESPACE; }
127
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; }
134
135 TRUE { return TRUE; }
136 FALSE { return FALSE; }
137
138
139 "--"[[:alnum:]]* {
140 yyextra->begin= yytext;
141 return UNKNOWN_OPTION;
142 }
143
144 CONSISTENT { return CONSISTENT; }
145 MODULA { return MODULA; }
146 RANDOM { return RANDOM; }
147
148 MD5 { return MD5; }
149 CRC { return CRC; }
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; }
157
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;
164 return IPADDRESS;
165 }
166
167 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
168 if (yyextra->is_server())
169 {
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;
175
176 return HOSTNAME;
177 }
178
179 yylval->string.c_str = yytext;
180 yylval->string.size = yyleng;
181
182 return STRING;
183 }
184
185 (\".*\") {
186 yylval->string.c_str = yytext;
187 yylval->string.size = yyleng;
188 return QUOTED_STRING;
189 }
190
191 . {
192 yyextra->begin= yytext;
193 return UNKNOWN;
194 }
195
196 %%
197
198 void Context::init_scanner()
199 {
200 yylex_init(&scanner);
201 yyset_extra(this, scanner);
202 }
203
204 void Context::destroy_scanner()
205 {
206 yylex_destroy(scanner);
207 }
208