4e9eccc8f5a558889656924056387250dc381ebd
[m6w6/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 #pragma GCC diagnostic ignored "-Wold-style-cast"
24 #pragma GCC diagnostic ignored "-Wunused-parameter"
25 #pragma GCC diagnostic ignored "-fpermissive"
26
27 #include <iostream>
28
29 #include <libmemcached/options/context.h>
30 #include <libmemcached/options/parser.h>
31 #include <libmemcached/options/string.h>
32 #include <libmemcached/options/symbol.h>
33
34 #define YY_EXTRA_TYPE Context*
35 #define YY_USER_ACTION yylloc->first_line = yylineno;
36
37 }
38
39
40 %{
41 #include <cstdlib>
42 #include <cstring>
43
44 #define PARAM yyget_extra(yyscanner)
45
46 static void get_lex_chars(char* buffer, int& result, int max_size, Context *context)
47 {
48 if (context->pos >= context->length)
49 {
50 std::cerr << "YY_NULL" << std::endl;
51 result= YY_NULL;
52 }
53 else
54 {
55 result= context->length - context->pos;
56 result > (int)max_size ? result = max_size : 0;
57 memcpy(buffer, context->buf + context->pos, result);
58 context->pos += result;
59 }
60 }
61
62
63 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
64
65 %}
66
67 %option bison-bridge
68 %option bison-locations
69 %option case-insensitive
70 %option debug
71 %option nounput
72 %option noyywrap
73 %option yylineno
74 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
75 %option perf-report
76 %option prefix="libmemcached_"
77 %option reentrant
78
79 %%
80
81
82 =|,|[ ] { return yytext[0];}
83
84
85 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
86
87 ([[:digit:]]*.[:digit:]+) { yylval->double_number = atof(yytext); return (FLOAT); }
88
89 [\t\r\n] ; /* skip whitespace */
90
91 ^#.*$ {
92 return COMMENT;
93 }
94
95 "--" { yyextra->begin= yytext; return DASH_OPTION; }
96
97 SERVER { return SERVER; }
98 SERVERS { return SERVERS; }
99
100 VERIFY_KEY { return VERIFY_KEY; }
101 VERIFY-KEY { return VERIFY_KEY; }
102 AUTO_EJECT_HOSTS { return AUTO_EJECT_HOSTS; }
103 AUTO-EJECT_HOSTS { return AUTO_EJECT_HOSTS; }
104 BINARY_PROTOCOL { return BINARY_PROTOCOL; }
105 BINARY-PROTOCOL { return BINARY_PROTOCOL; }
106 BUFFER_REQUESTS { return BUFFER_REQUESTS; }
107 BUFFER-REQUESTS { return BUFFER_REQUESTS; }
108 CACHE_LOOKUPS { return CACHE_LOOKUPS; }
109 CACHE-LOOKUPS { return CACHE_LOOKUPS; }
110 CONFIGURE_FILE { return CONFIGURE_FILE; }
111 CONFIGURE-FILE { return CONFIGURE_FILE; }
112 CONNECT_TIMEOUT { return CONNECT_TIMEOUT; }
113 CONNECT-TIMEOUT { return CONNECT_TIMEOUT; }
114 CORK { return _CORK; }
115 DISTRIBUTION { return DISTRIBUTION; }
116 HASH { return HASH; }
117 HASH_WITH_PREFIX_KEY { return HASH_WITH_PREFIX_KEY; }
118 HASH-WITH-PREFIX_KEY { return HASH_WITH_PREFIX_KEY; }
119 IO_BYTES_WATERMARK { return IO_BYTES_WATERMARK; }
120 IO-BYTES-WATERMARK { return IO_BYTES_WATERMARK; }
121 IO_KEY_PREFETCH { return IO_KEY_PREFETCH; }
122 IO-KEY-PREFETCH { return IO_KEY_PREFETCH; }
123 IO_MSG_WATERMARK { return IO_MSG_WATERMARK; }
124 IO-MSG-WATERMARK { return IO_MSG_WATERMARK; }
125 KETAMA { return KETAMA; }
126 KETAMA_HASH { return KETAMA_HASH; }
127 KETAMA-HASH { return KETAMA_HASH; }
128 KETAMA_WEIGHTED { return KETAMA_WEIGHTED; }
129 KETAMA-WEIGHTED { return KETAMA_WEIGHTED; }
130 NOREPLY { return NOREPLY; }
131 NUMBER_OF_REPLICAS { return NUMBER_OF_REPLICAS; }
132 NUMBER-OF-REPLICAS { return NUMBER_OF_REPLICAS; }
133 POLL_TIMEOUT { return POLL_TIMEOUT; }
134 POLL-TIMEOUT { return POLL_TIMEOUT; }
135 RANDOMIZE_REPLICA_READ { return RANDOMIZE_REPLICA_READ; }
136 RANDOMIZE-REPLICA-READ { return RANDOMIZE_REPLICA_READ; }
137 RCV_TIMEOUT { return RCV_TIMEOUT; }
138 RCV-TIMEOUT { return RCV_TIMEOUT; }
139 RETRY_TIMEOUT { return RETRY_TIMEOUT; }
140 RETRY-TIMEOUT { return RETRY_TIMEOUT; }
141 SERVER_FAILURE_LIMIT { return SERVER_FAILURE_LIMIT; }
142 SERVER-FAILURE-LIMIT { return SERVER_FAILURE_LIMIT; }
143 SND_TIMEOUT { return SND_TIMEOUT; }
144 SND-TIMEOUT { return SND_TIMEOUT; }
145 SOCKET_RECV_SIZE { return SOCKET_RECV_SIZE; }
146 SOCKET-RECV-SIZE { return SOCKET_RECV_SIZE; }
147 SOCKET_SEND_SIZE { return SOCKET_SEND_SIZE; }
148 SOCKET-SEND-SIZE { return SOCKET_SEND_SIZE; }
149 SORT_HOSTS { return SORT_HOSTS; }
150 SORT-HOSTS { return SORT_HOSTS; }
151 SUPPORT_CAS { return SUPPORT_CAS; }
152 SUPPORT-CAS { return SUPPORT_CAS; }
153 TCP_NODELAY { return _TCP_NODELAY; }
154 TCP-NODELAY { return _TCP_NODELAY; }
155 TCP_KEEPALIVE { return _TCP_KEEPALIVE; }
156 TCP-KEEPALIVE { return _TCP_KEEPALIVE; }
157 TCP_KEEPIDLE { return _TCP_KEEPIDLE; }
158 TCP-KEEPIDLE { return _TCP_KEEPIDLE; }
159 USER_DATA { return USER_DATA; }
160 USER-DATA { return USER_DATA; }
161 USE_UDP { return USE_UDP; }
162 USE-UDP { return USE_UDP; }
163
164 PREFIX-KEY { return PREFIX_KEY; }
165 PREFIX_KEY { return PREFIX_KEY; }
166
167 CONSISTENT { return CONSISTENT; }
168 MODULA { return MODULA; }
169 RANDOM { return RANDOM; }
170
171 MD5 { return MD5; }
172 CRC { return CRC; }
173 FNV1_64 { return FNV1_64; }
174 FNV1A_64 { return FNV1A_64; }
175 FNV1_32 { return FNV1_32; }
176 FNV1A_32 { return FNV1A_32; }
177 HSIEH { return HSIEH; }
178 MURMUR { return MURMUR; }
179 JENKINS { return JENKINS; }
180
181 [[:alnum:]][[:alnum:].]*[[:alpha:]]: {
182 yylval->string.c_str = yytext;
183 yylval->string.length = yyleng;
184 return HOSTNAME_WITH_PORT;
185 }
186
187 [[:alnum:]]+"."[[:alpha:].]+ {
188 yylval->string.c_str = yytext;
189 yylval->string.length = yyleng;
190 return HOSTNAME;
191 }
192
193 [[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}: {
194 yylval->string.c_str = yytext;
195 yylval->string.length = yyleng;
196 return IPADDRESS_WITH_PORT;
197 }
198
199 [[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3} {
200 yylval->string.c_str = yytext;
201 yylval->string.length = yyleng;
202 return IPADDRESS;
203 }
204
205 [[:alnum:]]+ {
206 yylval->string.c_str = yytext;
207 yylval->string.length = yyleng;
208 return STRING;
209 }
210
211 \".*\" {
212 yylval->string.c_str = yytext;
213 yylval->string.length = yyleng;
214 return QUOTED_STRING;
215 }
216
217 . {
218 return UNKNOWN;
219 }
220
221 %%
222
223 void Context::init_scanner()
224 {
225 yylex_init(&scanner);
226 yyset_extra(this, scanner);
227 }
228
229 void Context::destroy_scanner()
230 {
231 yylex_destroy(scanner);
232 }