c8c2ea82579167d6febc2026f99f6966d34bbb34
[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 #pragma GCC diagnostic ignored "-Wold-style-cast"
24 #pragma GCC diagnostic ignored "-Wunused-parameter"
25 #pragma GCC diagnostic ignored "-fpermissive"
26
27 #include <libmemcached/options/parser.h>
28 #include <libmemcached/options/string.h>
29 #include <libmemcached/options/symbol.h>
30 #include <libmemcached/options/type.h>
31
32 }
33
34
35 %{
36 #include <cstdlib>
37 #include <cstring>
38
39 #define PARAM yyget_extra(yyscanner)
40
41 static void get_lex_chars(char* buffer, int& result, int max_size, struct type_st *parser)
42 {
43 if (parser->pos >= parser->length)
44 {
45 result = YY_NULL;
46 }
47 else
48 {
49 result = parser->length - parser->pos;
50 result > (int)max_size ? result = max_size : 0;
51 memcpy(buffer, parser->buf + parser->pos, result);
52 parser->pos += result;
53 }
54 }
55
56
57 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM)
58
59 %}
60
61 %option bison-locations
62 %option bison-bridge
63 %option case-insensitive
64 %option debug
65 %option nounput
66 %option noyywrap
67 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
68 %option perf-report
69 %option prefix="libmemcached_"
70 %option reentrant
71
72 %%
73
74
75 =|,|[ ] { return yytext[0];}
76
77
78 [[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
79
80 ([[:digit:]]*.[:digit:]+) { yylval->double_number = atof(yytext); return (FLOAT); }
81
82 [\t\r\n] ; /* skip whitespace */
83
84 "--" { return DASH_OPTION; }
85
86 SERVER { return SERVER; }
87 SERVERS { return SERVERS; }
88
89 VERIFY_KEY { return VERIFY_KEY; }
90 VERIFY-KEY { return VERIFY_KEY; }
91 AUTO_EJECT_HOSTS { return AUTO_EJECT_HOSTS; }
92 AUTO-EJECT_HOSTS { return AUTO_EJECT_HOSTS; }
93 BINARY_PROTOCOL { return BINARY_PROTOCOL; }
94 BINARY-PROTOCOL { return BINARY_PROTOCOL; }
95 BUFFER_REQUESTS { return BUFFER_REQUESTS; }
96 BUFFER-REQUESTS { return BUFFER_REQUESTS; }
97 CACHE_LOOKUPS { return CACHE_LOOKUPS; }
98 CACHE-LOOKUPS { return CACHE_LOOKUPS; }
99 CONNECT_TIMEOUT { return CONNECT_TIMEOUT; }
100 CONNECT-TIMEOUT { return CONNECT_TIMEOUT; }
101 CORK { return _CORK; }
102 DISTRIBUTION { return DISTRIBUTION; }
103 HASH { return HASH; }
104 HASH_WITH_PREFIX_KEY { return HASH_WITH_PREFIX_KEY; }
105 HASH-WITH-PREFIX_KEY { return HASH_WITH_PREFIX_KEY; }
106 IO_BYTES_WATERMARK { return IO_BYTES_WATERMARK; }
107 IO-BYTES-WATERMARK { return IO_BYTES_WATERMARK; }
108 IO_KEY_PREFETCH { return IO_KEY_PREFETCH; }
109 IO-KEY-PREFETCH { return IO_KEY_PREFETCH; }
110 IO_MSG_WATERMARK { return IO_MSG_WATERMARK; }
111 IO-MSG-WATERMARK { return IO_MSG_WATERMARK; }
112 KETAMA { return KETAMA; }
113 KETAMA_HASH { return KETAMA_HASH; }
114 KETAMA-HASH { return KETAMA_HASH; }
115 KETAMA_WEIGHTED { return KETAMA_WEIGHTED; }
116 KETAMA-WEIGHTED { return KETAMA_WEIGHTED; }
117 NOREPLY { return NOREPLY; }
118 NUMBER_OF_REPLICAS { return NUMBER_OF_REPLICAS; }
119 NUMBER-OF-REPLICAS { return NUMBER_OF_REPLICAS; }
120 POLL_TIMEOUT { return POLL_TIMEOUT; }
121 POLL-TIMEOUT { return POLL_TIMEOUT; }
122 RANDOMIZE_REPLICA_READ { return RANDOMIZE_REPLICA_READ; }
123 RANDOMIZE-REPLICA-READ { return RANDOMIZE_REPLICA_READ; }
124 RCV_TIMEOUT { return RCV_TIMEOUT; }
125 RCV-TIMEOUT { return RCV_TIMEOUT; }
126 RETRY_TIMEOUT { return RETRY_TIMEOUT; }
127 RETRY-TIMEOUT { return RETRY_TIMEOUT; }
128 SERVER-FAILURE-LIMIT { return SERVER_FAILURE_LIMIT; }
129 SND_TIMEOUT { return SND_TIMEOUT; }
130 SND-TIMEOUT { return SND_TIMEOUT; }
131 SOCKET_RECV_SIZE { return SOCKET_RECV_SIZE; }
132 SOCKET-RECV-SIZE { return SOCKET_RECV_SIZE; }
133 SOCKET_SEND_SIZE { return SOCKET_SEND_SIZE; }
134 SOCKET-SEND-SIZE { return SOCKET_SEND_SIZE; }
135 SORT_HOSTS { return SORT_HOSTS; }
136 SORT-HOSTS { return SORT_HOSTS; }
137 SUPPORT_CAS { return SUPPORT_CAS; }
138 SUPPORT-CAS { return SUPPORT_CAS; }
139 TCP_NODELAY { return _TCP_NODELAY; }
140 TCP-NODELAY { return _TCP_NODELAY; }
141 TCP_KEEPALIVE { return _TCP_KEEPALIVE; }
142 TCP-KEEPALIVE { return _TCP_KEEPALIVE; }
143 TCP_KEEPIDLE { return _TCP_KEEPIDLE; }
144 TCP-KEEPIDLE { return _TCP_KEEPIDLE; }
145 USER_DATA { return USER_DATA; }
146 USER-DATA { return USER_DATA; }
147 USE_UDP { return USE_UDP; }
148 USE-UDP { return USE_UDP; }
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 [[:alnum:]][[:alnum:].]*[[:alpha:]]: {
165 yylval->string.c_str = yytext;
166 yylval->string.length = yyleng;
167 return SERVER_WITH_PORT;
168 }
169
170 [[:alnum:]][[:alnum:].]*[[:alpha:]] {
171 yylval->string.c_str = yytext;
172 yylval->string.length = yyleng;
173 return IDENTIFIER;
174 }
175 [[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}: {
176 yylval->string.c_str = yytext;
177 yylval->string.length = yyleng;
178 return IPADDRESS_WITH_PORT;
179 }
180
181 [[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3} {
182 yylval->string.c_str = yytext;
183 yylval->string.length = yyleng;
184 return IPADDRESS;
185 }
186
187 . {
188 return UNKNOWN;
189 }
190
191 %%