Update for OSX Lion build.
[awesomized/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_EXTRA_TYPE Context*
35
36 }
37
38
39 %{
40 #include <cstdlib>
41 #include <cstring>
42
43 #define PARAM yyget_extra(yyscanner)
44
45 #define get_lex_chars(buffer, result, max_size, context) \
46 { \
47 if (context->pos >= context->length) \
48 { \
49 result= YY_NULL; \
50 } \
51 else \
52 { \
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; \
57 } \
58 }
59
60
61 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
62
63 %}
64
65 %option 8bit
66 %option bison-bridge
67 %option case-insensitive
68 %option debug
69 %option nounput
70 %option noyywrap
71 %option outfile="libmemcached/csl/scanner.cc" header-file="libmemcached/csl/scanner.h"
72 %option perf-report
73 %option prefix="config_"
74 %option reentrant
75
76 %%
77
78
79 =|,|[ ] { return yytext[0];}
80
81 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
82
83 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
84
85 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
86
87 [\t\r\n] ; /* skip whitespace */
88
89
90 ^#.*$ {
91 return COMMENT;
92 }
93
94 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; }
95
96 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
97
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; }
126
127 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
128 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
129
130 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
131
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; }
138
139 TRUE { return yyextra->previous_token= TRUE; }
140 FALSE { return yyextra->previous_token= FALSE; }
141
142
143 "--"[[:alnum:]]* {
144 yyextra->begin= yytext;
145 return UNKNOWN_OPTION;
146 }
147
148 CONSISTENT { return CONSISTENT; }
149 MODULA { return MODULA; }
150 RANDOM { return RANDOM; }
151
152 MD5 { return MD5; }
153 CRC { return CRC; }
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; }
161
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;
168 return IPADDRESS;
169 }
170
171 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
172 if (yyextra->is_server())
173 {
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;
179
180 return HOSTNAME;
181 }
182
183 yylval->string.c_str = yytext;
184 yylval->string.size = yyleng;
185
186 return STRING;
187 }
188
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;
194 }
195
196 . {
197 yyextra->begin= yytext;
198 return UNKNOWN;
199 }
200
201 %%
202
203 void Context::init_scanner()
204 {
205 yylex_init(&scanner);
206 yyset_extra(this, scanner);
207 }
208
209 void Context::destroy_scanner()
210 {
211 yylex_destroy(scanner);
212 }
213