Update headers.
[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/string.h>
27 #include <libmemcached/options/symbol.h>
28
29 #pragma GCC diagnostic ignored "-Wold-style-cast"
30 #pragma GCC diagnostic ignored "-Wsign-compare"
31 #pragma GCC diagnostic ignored "-Wunused-parameter"
32
33 #define YY_EXTRA_TYPE Context*
34
35 }
36
37
38 %{
39 #include <cstdlib>
40 #include <cstring>
41
42 #define PARAM yyget_extra(yyscanner)
43
44 #define get_lex_chars(buffer, result, max_size, context) \
45 { \
46 if (context->pos >= context->length) \
47 { \
48 result= YY_NULL; \
49 } \
50 else \
51 { \
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; \
56 } \
57 }
58
59
60 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
61
62 %}
63
64 %option 8bit
65 %option bison-bridge
66 %option case-insensitive
67 %option debug
68 %option nounput
69 %option noyywrap
70 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
71 %option perf-report
72 %option prefix="config_"
73 %option reentrant
74
75 %%
76
77
78 =|,|[ ] { return yytext[0];}
79
80 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
81
82 :[[:digit:]]{1,5} { yylval->server.port = atoi(yytext +1); return PORT; }
83
84 "/?"[[:digit:]]{1,5} { yylval->server.weight = atoi(yytext +2); return WEIGHT_START; }
85
86 [\t\r\n] ; /* skip whitespace */
87
88
89 ^#.*$ {
90 return COMMENT;
91 }
92
93 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return SERVER; }
94
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; }
123
124 "--POOL-MIN=" { yyextra->begin= yytext; return POOL_MIN; }
125 "--POOL-MAX=" { yyextra->begin= yytext; return POOL_MAX; }
126
127 "--NAMESPACE=" { yyextra->begin= yytext; return NAMESPACE; }
128
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; }
135
136 TRUE { return TRUE; }
137 FALSE { return FALSE; }
138
139
140 "--"[[:alnum:]]* {
141 yyextra->begin= yytext;
142 return UNKNOWN_OPTION;
143 }
144
145 CONSISTENT { return CONSISTENT; }
146 MODULA { return MODULA; }
147 RANDOM { return RANDOM; }
148
149 MD5 { return MD5; }
150 CRC { return CRC; }
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; }
158
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;
165 return IPADDRESS;
166 }
167
168 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
169 if (yyextra->is_server())
170 {
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;
176
177 return HOSTNAME;
178 }
179
180 yylval->string.c_str = yytext;
181 yylval->string.length = yyleng;
182
183 return STRING;
184 }
185
186 (\".*\") {
187 yylval->string.c_str = yytext;
188 yylval->string.length = yyleng;
189 return QUOTED_STRING;
190 }
191
192 . {
193 yyextra->begin= yytext;
194 return UNKNOWN;
195 }
196
197 %%
198
199 void Context::init_scanner()
200 {
201 yylex_init(&scanner);
202 yyset_extra(this, scanner);
203 }
204
205 void Context::destroy_scanner()
206 {
207 yylex_destroy(scanner);
208 }
209