1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 2 * 3 * Libmemcached library 4 * 5 * Copyright (C) 2012 Data Differential, http://datadifferential.com/ 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * * Redistributions in binary form must reproduce the above 15 * copyright notice, this list of conditions and the following disclaimer 16 * in the documentation and/or other materials provided with the 17 * distribution. 18 * 19 * * The names of its contributors may not be used to endorse or 20 * promote products derived from this software without specific prior 21 * written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 */ 36 37 38 %top{ 39 40 #include <libmemcached/csl/common.h> 41 #include <libmemcached/csl/context.h> 42 #include <libmemcached/csl/parser.h> 43 #include <libmemcached/csl/symbol.h> 44 45 #ifndef __INTEL_COMPILER 46 #pragma GCC diagnostic ignored "-Wold-style-cast" 47 #pragma GCC diagnostic ignored "-Wsign-compare" 48 #pragma GCC diagnostic ignored "-Wunused-parameter" 49 #pragma GCC diagnostic ignored "-Wmissing-declarations" 50 #pragma GCC diagnostic ignored "-Wunused-result" 51 #pragma GCC diagnostic ignored "-Wmissing-noreturn" 52 #endif 53 54 #ifdef __clang__ 55 #pragma GCC diagnostic ignored "-Wshorten-64-to-32" 56 #endif 57 58 #ifndef __INTEL_COMPILER 59 #ifndef __clang__ 60 #pragma GCC diagnostic ignored "-Wlogical-op" 61 #endif 62 #endif 63 64 } 65 66 67 %{ 68 #define PARAM yyget_extra(yyscanner) 69 70 #define get_lex_chars(buffer, result, max_size, context) \ 71 { \ 72 if (context->pos >= context->length) \ 73 { \ 74 result= YY_NULL; \ 75 } \ 76 else \ 77 { \ 78 result= (int)(context->length - context->pos); \ 79 (size_t)result > (size_t)max_size ? result= max_size : 0; \ 80 memcpy(buffer, context->buf + context->pos, result); \ 81 context->pos += result; \ 82 } \ 83 } 84 85 #define YY_FATAL_ERROR(msg) \ 86 { \ 87 } 88 89 90 #define YY_INPUT(buffer, result, max_size) get_lex_chars(buffer, result, max_size, PARAM) 91 92 %} 93 94 %option nostdinit 95 %option 8bit 96 %option warn 97 %option bison-bridge 98 %option never-interactive 99 %option case-insensitive 100 %option nodefault 101 %option noinput 102 %option nounput 103 %option noyywrap 104 %option outfile="libmemcached/csl/scanner.cc" header-file="libmemcached/csl/scanner.h" 105 %option perf-report 106 %option prefix="config_" 107 %option reentrant 108 109 %% 110 111 112 =|,|[ ] { return yytext[0];} 113 114 [[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); } 115 116 :[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; } 117 118 "/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; } 119 120 [\t\r\n] ; /* skip whitespace */ 121 122 123 ^#.*$ { 124 return COMMENT; 125 } 126 127 "--SERVER=" { yyextra->begin= yytext; yyextra->set_server(); return yyextra->previous_token= SERVER; } 128 129 "--SOCKET=" { yyextra->begin= yytext; return yyextra->previous_token= CSL_SOCKET; } 130 131 "--BINARY-PROTOCOL" { yyextra->begin= yytext; return yyextra->previous_token= BINARY_PROTOCOL; } 132 "--BUFFER-REQUESTS" { yyextra->begin= yytext; return yyextra->previous_token= BUFFER_REQUESTS; } 133 "--CONFIGURE-FILE=" { yyextra->begin= yytext; return yyextra->previous_token= CONFIGURE_FILE; } 134 "--CONNECT-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= CONNECT_TIMEOUT; } 135 "--DISTRIBUTION=" { yyextra->begin= yytext; return yyextra->previous_token= DISTRIBUTION; } 136 "--HASH-WITH-NAMESPACE" { yyextra->begin= yytext; return yyextra->previous_token= HASH_WITH_NAMESPACE; } 137 "--HASH=" { yyextra->begin= yytext; return yyextra->previous_token= HASH; } 138 "--IO-BYTES-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_BYTES_WATERMARK; } 139 "--IO-KEY-PREFETCH=" { yyextra->begin= yytext; return yyextra->previous_token= IO_KEY_PREFETCH; } 140 "--IO-MSG-WATERMARK=" { yyextra->begin= yytext; return yyextra->previous_token= IO_MSG_WATERMARK; } 141 "--NOREPLY" { yyextra->begin= yytext; return yyextra->previous_token= NOREPLY; } 142 "--NUMBER-OF-REPLICAS=" { yyextra->begin= yytext; return yyextra->previous_token= NUMBER_OF_REPLICAS; } 143 "--POLL-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= POLL_TIMEOUT; } 144 "--RANDOMIZE-REPLICA-READ" { yyextra->begin= yytext; return yyextra->previous_token= RANDOMIZE_REPLICA_READ; } 145 "--RCV-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RCV_TIMEOUT; } 146 "--REMOVE-FAILED-SERVERS=" { yyextra->begin= yytext; return yyextra->previous_token= REMOVE_FAILED_SERVERS; } 147 "--RETRY-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= RETRY_TIMEOUT; } 148 "--SND-TIMEOUT=" { yyextra->begin= yytext; return yyextra->previous_token= SND_TIMEOUT; } 149 "--SOCKET-RECV-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_RECV_SIZE; } 150 "--SOCKET-SEND-SIZE=" { yyextra->begin= yytext; return yyextra->previous_token= SOCKET_SEND_SIZE; } 151 "--SORT-HOSTS" { yyextra->begin= yytext; return yyextra->previous_token= SORT_HOSTS; } 152 "--SUPPORT-CAS" { yyextra->begin= yytext; return yyextra->previous_token= SUPPORT_CAS; } 153 "--TCP-KEEPALIVE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPALIVE; } 154 "--TCP-KEEPIDLE" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_KEEPIDLE; } 155 "--TCP-NODELAY" { yyextra->begin= yytext; return yyextra->previous_token= _TCP_NODELAY; } 156 "--USE-UDP" { yyextra->begin= yytext; return yyextra->previous_token= USE_UDP; } 157 "--USER-DATA" { yyextra->begin= yytext; return yyextra->previous_token= USER_DATA; } 158 "--VERIFY-KEY" { yyextra->begin= yytext; return yyextra->previous_token= VERIFY_KEY; } 159 160 "--POOL-MIN=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MIN; } 161 "--POOL-MAX=" { yyextra->begin= yytext; return yyextra->previous_token= POOL_MAX; } 162 163 "--NAMESPACE=" { yyextra->begin= yytext; return yyextra->previous_token= NAMESPACE; } 164 165 "--FETCH-VERSION" { yyextra->begin= yytext; return yyextra->previous_token= FETCH_VERSION; } 166 167 INCLUDE { yyextra->begin= yytext; return yyextra->previous_token= INCLUDE; } 168 RESET { yyextra->begin= yytext; return yyextra->previous_token= RESET; } 169 DEBUG { yyextra->begin= yytext; return yyextra->previous_token= PARSER_DEBUG; } 170 SERVERS { yyextra->begin= yytext; return yyextra->previous_token= SERVERS; } 171 END { yyextra->begin= yytext; return yyextra->previous_token= END; } 172 CSL_ERROR { yyextra->begin= yytext; return yyextra->previous_token= CSL_ERROR; } 173 174 TRUE { return yyextra->previous_token= CSL_TRUE; } 175 FALSE { return yyextra->previous_token= CSL_FALSE; } 176 177 178 "--"[[:alnum:]]* { 179 yyextra->begin= yytext; 180 return UNKNOWN_OPTION; 181 } 182 183 CONSISTENT { return CONSISTENT; } 184 MODULA { return MODULA; } 185 RANDOM { return RANDOM; } 186 187 MD5 { return MD5; } 188 CRC { return CRC; } 189 FNV1_64 { return FNV1_64; } 190 FNV1A_64 { return FNV1A_64; } 191 FNV1_32 { return FNV1_32; } 192 FNV1A_32 { return FNV1A_32; } 193 HSIEH { return HSIEH; } 194 MURMUR { return MURMUR; } 195 JENKINS { return JENKINS; } 196 197 (([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) { 198 yyextra->hostname(yytext, yyleng, yylval->server); 199 return IPADDRESS; 200 } 201 202 [[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] { 203 if (yyextra->is_server()) 204 { 205 yyextra->hostname(yytext, yyleng, yylval->server); 206 207 return HOSTNAME; 208 } 209 210 yyextra->string_buffer(yytext, yyleng, yylval->string); 211 212 return STRING; 213 } 214 215 L?\"(\\.|[^\\"])*\" { 216 yyget_text(yyscanner)[yyleng -1]= 0; 217 yyextra->string_buffer(yytext +1, yyleng -2, yylval->string); 218 return QUOTED_STRING; 219 } 220 221 . { 222 yyextra->begin= yytext; 223 return UNKNOWN; 224 } 225 226 %% 227 228 void Context::init_scanner() 229 { 230 yylex_init(&scanner); 231 yyset_extra(this, scanner); 232 } 233 234 void Context::destroy_scanner() 235 { 236 (void)yy_fatal_error; // Removes warning about unused yy_fatal_error() 237 yylex_destroy(scanner); 238 } 239 240