Add memc.h to include.am
[m6w6/libmemcached] / libmemcached / csl / scanner.l
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Configure Scripting Language
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/csl/common.h>
24 #include <libmemcached/csl/context.h>
25 #include <libmemcached/csl/parser.h>
26 #include <libmemcached/csl/symbol.h>
27
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"
32 #endif
33
34 #define YY_NO_INPUT
35
36 #define YY_EXTRA_TYPE Context*
37
38 }
39
40
41 %{
42 #include <cstdlib>
43 #include <cstring>
44
45 #define PARAM yyget_extra(yyscanner)
46
47 #define get_lex_chars(buffer, result, max_size, context) \
48 { \
49 if (context->pos >= context->length) \
50 { \
51 result= YY_NULL; \
52 } \
53 else \
54 { \
55 result= (int)(context->length - context->pos); \
56 (size_t)result > (size_t)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 8bit
68 %option bison-bridge
69 %option case-insensitive
70 %option debug
71 %option nounput
72 %option noyywrap
73 %option outfile="libmemcached/csl/scanner.cc" header-file="libmemcached/csl/scanner.h"
74 %option perf-report
75 %option prefix="config_"
76 %option reentrant
77
78 %%
79
80
81 =|,|[ ] { return yytext[0];}
82
83 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
84
85 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
86
87 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
88
89 [\t\r\n] ; /* skip whitespace */
90
91
92 ^#.*$ {
93 return COMMENT;
94 }
95
96 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; }
97
98 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
99
100 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; }
101 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; }
102 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; }
103 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; }
104 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; }
105 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; }
106 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; }
107 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; }
108 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; }
109 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; }
110 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; }
111 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; }
112 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; }
113 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; }
114 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; }
115 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; }
116 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; }
117 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; }
118 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; }
119 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; }
120 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; }
121 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; }
122 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; }
123 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; }
124 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; }
125 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; }
126 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; }
127 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; }
128
129 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
130 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
131
132 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
133
134 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; }
135 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; }
136 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; }
137 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; }
138 END { yyextra->begin= yytext; return yyextra->previous_token= END; }
139 ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; }
140
141 TRUE { return yyextra->previous_token= TRUE; }
142 FALSE { return yyextra->previous_token= FALSE; }
143
144
145 "--"[[:alnum:]]* {
146 yyextra->begin= yytext;
147 return UNKNOWN_OPTION;
148 }
149
150 CONSISTENT { return CONSISTENT; }
151 MODULA { return MODULA; }
152 RANDOM { return RANDOM; }
153
154 MD5 { return MD5; }
155 CRC { return CRC; }
156 FNV1_64 { return FNV1_64; }
157 FNV1A_64 { return FNV1A_64; }
158 FNV1_32 { return FNV1_32; }
159 FNV1A_32 { return FNV1A_32; }
160 HSIEH { return HSIEH; }
161 MURMUR { return MURMUR; }
162 JENKINS { return JENKINS; }
163
164 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
165 yylval->server.port= MEMCACHED_DEFAULT_PORT;
166 yylval->server.weight= 1;
167 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
168 if (yylval->server.c_str)
169 yylval->server.size= yyleng;
170 return IPADDRESS;
171 }
172
173 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
174 if (yyextra->is_server())
175 {
176 yylval->server.port= MEMCACHED_DEFAULT_PORT;
177 yylval->server.weight= 1;
178 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
179 if (yylval->server.c_str)
180 yylval->server.size= yyleng;
181
182 return HOSTNAME;
183 }
184
185 yylval->string.c_str = yytext;
186 yylval->string.size = yyleng;
187
188 return STRING;
189 }
190
191 L?\"(\\.|[^\\"])*\" {
192 yyget_text(yyscanner)[yyleng -1]= 0;
193 yylval->string.c_str= yytext +1;
194 yylval->string.size= yyleng -2;
195 return QUOTED_STRING;
196 }
197
198 . {
199 yyextra->begin= yytext;
200 return UNKNOWN;
201 }
202
203 %%
204
205 void Context::init_scanner()
206 {
207 yylex_init(&scanner);
208 yyset_extra(this, scanner);
209 }
210
211 void Context::destroy_scanner()
212 {
213 yylex_destroy(scanner);
214 }
215