b52a316c4f3c3e2a15d90bdc2652e591f7b45bb5
[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 #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/csl/scanner.cc" header-file="libmemcached/csl/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 yyextra->previous_token= SERVER; }
93
94 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET; }
95
96 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; }
97 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; }
98 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; }
99 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; }
100 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; }
101 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; }
102 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; }
103 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; }
104 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; }
105 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; }
106 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; }
107 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; }
108 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; }
109 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; }
110 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; }
111 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; }
112 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; }
113 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; }
114 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; }
115 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; }
116 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; }
117 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; }
118 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; }
119 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; }
120 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; }
121 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; }
122 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; }
123 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; }
124
125 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; }
126 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; }
127
128 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; }
129
130 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; }
131 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; }
132 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; }
133 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; }
134 END { yyextra->begin= yytext; return yyextra->previous_token= END; }
135 ERROR { yyextra->begin= yytext; return yyextra->previous_token= ERROR; }
136
137 TRUE { return yyextra->previous_token= TRUE; }
138 FALSE { return yyextra->previous_token= FALSE; }
139
140
141 "--"[[:alnum:]]* {
142 yyextra->begin= yytext;
143 return UNKNOWN_OPTION;
144 }
145
146 CONSISTENT { return CONSISTENT; }
147 MODULA { return MODULA; }
148 RANDOM { return RANDOM; }
149
150 MD5 { return MD5; }
151 CRC { return CRC; }
152 FNV1_64 { return FNV1_64; }
153 FNV1A_64 { return FNV1A_64; }
154 FNV1_32 { return FNV1_32; }
155 FNV1A_32 { return FNV1A_32; }
156 HSIEH { return HSIEH; }
157 MURMUR { return MURMUR; }
158 JENKINS { return JENKINS; }
159
160 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
161 yylval->server.port= MEMCACHED_DEFAULT_PORT;
162 yylval->server.weight= 1;
163 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
164 if (yylval->server.c_str)
165 yylval->server.size= yyleng;
166 return IPADDRESS;
167 }
168
169 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
170 if (yyextra->is_server())
171 {
172 yylval->server.port= MEMCACHED_DEFAULT_PORT;
173 yylval->server.weight= 1;
174 yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
175 if (yylval->server.c_str)
176 yylval->server.size= yyleng;
177
178 return HOSTNAME;
179 }
180
181 yylval->string.c_str = yytext;
182 yylval->string.size = yyleng;
183
184 return STRING;
185 }
186
187 L?\"(\\.|[^\\"])*\" {
188 yyget_text(yyscanner)[yyleng -1]= 0;
189 yylval->string.c_str= yytext +1;
190 yylval->string.size= yyleng -2;
191 return QUOTED_STRING;
192 }
193
194 . {
195 yyextra->begin= yytext;
196 return UNKNOWN;
197 }
198
199 %%
200
201 void Context::init_scanner()
202 {
203 yylex_init(&scanner);
204 yyset_extra(this, scanner);
205 }
206
207 void Context::destroy_scanner()
208 {
209 yylex_destroy(scanner);
210 }
211