Adding back in conf
[m6w6/libmemcached] / libmemcached / options / scanner.l
index 4e9eccc8f5a558889656924056387250dc381ebd..cc00618d786a059e73da65c16e69711c4f860fac 100644 (file)
@@ -3,36 +3,33 @@
  *  Libmemcached Scanner and Parser
  *
  *  Copyright (C) 2011 DataDifferental, http://datadifferential.com
- *  
+ * 
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU Affero General Public License as
  *  published by the Free Software Foundation, either version 3 of the
  *  License, or (at your option) any later version.
- *  
+ * 
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU Affero General Public License for more details.
- *  
+ * 
  *  You should have received a copy of the GNU Affero General Public License
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 %top{
 
-#pragma GCC diagnostic ignored "-Wold-style-cast"
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-#pragma GCC diagnostic ignored "-fpermissive"
-
-#include <iostream>
-
+#include <libmemcached/common.h>
 #include <libmemcached/options/context.h>
 #include <libmemcached/options/parser.h>
-#include <libmemcached/options/string.h>
 #include <libmemcached/options/symbol.h>
 
+#pragma GCC diagnostic ignored "-Wold-style-cast"
+#pragma GCC diagnostic ignored "-Wsign-compare"
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+
 #define YY_EXTRA_TYPE Context*
-#define YY_USER_ACTION yylloc->first_line = yylineno;
 
 }
 
 
 #define PARAM yyget_extra(yyscanner)
 
-static void get_lex_chars(char* buffer, int& result, int max_size, Context *context)
-{
-  if (context->pos >= context->length)
-  {
-    std::cerr << "YY_NULL" << std::endl;
-    result= YY_NULL;
-  }
-  else
-  {
-    result= context->length - context->pos;
-    result > (int)max_size ? result = max_size : 0;
-    memcpy(buffer, context->buf + context->pos, result);
-    context->pos += result;
-  }
+#define get_lex_chars(buffer, result, max_size, context) \
+{ \
+  if (context->pos >= context->length) \
+  { \
+    result= YY_NULL; \
+  } \
+  else \
+  { \
+    result= (int)(context->length - context->pos); \
+    (size_t)result > (size_t)max_size ? result= max_size : 0; \
+    memcpy(buffer, context->buf + context->pos, result); \
+    context->pos += result; \
+  } \
 }
 
 
@@ -64,16 +60,15 @@ static void get_lex_chars(char* buffer, int& result, int max_size, Context *cont
 
 %}
 
+%option 8bit
 %option bison-bridge
-%option bison-locations
 %option case-insensitive
 %option debug
 %option nounput
 %option noyywrap
-%option yylineno
 %option outfile="libmemcached/options/scanner.cc" header-file="libmemcached/options/scanner.h"
 %option perf-report
-%option prefix="libmemcached_"
+%option prefix="config_"
 %option reentrant
 
 %%
@@ -81,88 +76,72 @@ static void get_lex_chars(char* buffer, int& result, int max_size, Context *cont
 
 =|,|[ ]       { return yytext[0];}
 
+[[:digit:]]+ { yylval->number= atoi(yytext); return (NUMBER); }
 
-[[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); }
+:[[:digit:]]{1,5} { yylval->number= atoi(yytext +1); return PORT; }
 
-([[:digit:]]*.[:digit:]+) { yylval->double_number = atof(yytext); return (FLOAT); }
+"/?"[[:digit:]]{1,5} { yylval->number= atoi(yytext +2); return WEIGHT_START; }
 
 [\t\r\n] ; /* skip whitespace */
 
+
 ^#.*$ {
       return COMMENT;
     }
 
-"--" { yyextra->begin= yytext; return DASH_OPTION; }
-
-SERVER                          { return SERVER; }
-SERVERS                         { return SERVERS; }
-
-VERIFY_KEY                      { return VERIFY_KEY; }
-VERIFY-KEY                      { return VERIFY_KEY; }
-AUTO_EJECT_HOSTS               { return AUTO_EJECT_HOSTS; }
-AUTO-EJECT_HOSTS               { return AUTO_EJECT_HOSTS; }
-BINARY_PROTOCOL                        { return BINARY_PROTOCOL; }
-BINARY-PROTOCOL                        { return BINARY_PROTOCOL; }
-BUFFER_REQUESTS                        { return BUFFER_REQUESTS; }
-BUFFER-REQUESTS                        { return BUFFER_REQUESTS; }
-CACHE_LOOKUPS                  { return CACHE_LOOKUPS; }
-CACHE-LOOKUPS                  { return CACHE_LOOKUPS; }
-CONFIGURE_FILE                 { return CONFIGURE_FILE; }
-CONFIGURE-FILE                 { return CONFIGURE_FILE; }
-CONNECT_TIMEOUT                        { return CONNECT_TIMEOUT; }
-CONNECT-TIMEOUT                        { return CONNECT_TIMEOUT; }
-CORK                           { return _CORK; }
-DISTRIBUTION                   { return DISTRIBUTION; }
-HASH                           { return HASH; }
-HASH_WITH_PREFIX_KEY           { return HASH_WITH_PREFIX_KEY; }
-HASH-WITH-PREFIX_KEY           { return HASH_WITH_PREFIX_KEY; }
-IO_BYTES_WATERMARK             { return IO_BYTES_WATERMARK; }
-IO-BYTES-WATERMARK             { return IO_BYTES_WATERMARK; }
-IO_KEY_PREFETCH                        { return IO_KEY_PREFETCH; }
-IO-KEY-PREFETCH                        { return IO_KEY_PREFETCH; }
-IO_MSG_WATERMARK               { return IO_MSG_WATERMARK; }
-IO-MSG-WATERMARK               { return IO_MSG_WATERMARK; }
-KETAMA                         { return KETAMA; }
-KETAMA_HASH                    { return KETAMA_HASH; }
-KETAMA-HASH                    { return KETAMA_HASH; }
-KETAMA_WEIGHTED                        { return KETAMA_WEIGHTED; }
-KETAMA-WEIGHTED                        { return KETAMA_WEIGHTED; }
-NOREPLY                         { return NOREPLY; }
-NUMBER_OF_REPLICAS             { return NUMBER_OF_REPLICAS; }
-NUMBER-OF-REPLICAS             { return NUMBER_OF_REPLICAS; }
-POLL_TIMEOUT                   { return POLL_TIMEOUT; }
-POLL-TIMEOUT                   { return POLL_TIMEOUT; }
-RANDOMIZE_REPLICA_READ         { return RANDOMIZE_REPLICA_READ; }
-RANDOMIZE-REPLICA-READ         { return RANDOMIZE_REPLICA_READ; }
-RCV_TIMEOUT                    { return RCV_TIMEOUT; }
-RCV-TIMEOUT                    { return RCV_TIMEOUT; }
-RETRY_TIMEOUT                  { return RETRY_TIMEOUT; }
-RETRY-TIMEOUT                  { return RETRY_TIMEOUT; }
-SERVER_FAILURE_LIMIT           { return SERVER_FAILURE_LIMIT; }
-SERVER-FAILURE-LIMIT           { return SERVER_FAILURE_LIMIT; }
-SND_TIMEOUT                    { return SND_TIMEOUT; }
-SND-TIMEOUT                    { return SND_TIMEOUT; }
-SOCKET_RECV_SIZE               { return SOCKET_RECV_SIZE; }
-SOCKET-RECV-SIZE               { return SOCKET_RECV_SIZE; }
-SOCKET_SEND_SIZE               { return SOCKET_SEND_SIZE; }
-SOCKET-SEND-SIZE               { return SOCKET_SEND_SIZE; }
-SORT_HOSTS                     { return SORT_HOSTS; }
-SORT-HOSTS                     { return SORT_HOSTS; }
-SUPPORT_CAS                    { return SUPPORT_CAS; }
-SUPPORT-CAS                    { return SUPPORT_CAS; }
-TCP_NODELAY                    { return _TCP_NODELAY; }
-TCP-NODELAY                    { return _TCP_NODELAY; }
-TCP_KEEPALIVE                  { return _TCP_KEEPALIVE; }
-TCP-KEEPALIVE                  { return _TCP_KEEPALIVE; }
-TCP_KEEPIDLE                   { return _TCP_KEEPIDLE; }
-TCP-KEEPIDLE                   { return _TCP_KEEPIDLE; }
-USER_DATA                      { return USER_DATA; }
-USER-DATA                      { return USER_DATA; }
-USE_UDP                                { return USE_UDP; }
-USE-UDP                                { return USE_UDP; }
-
-PREFIX-KEY                             { return PREFIX_KEY; }
-PREFIX_KEY                             { return PREFIX_KEY; }
+"--SERVER="                          { yyextra->begin= yytext; yyextra->set_server(); return SERVER; }
+
+"--SOCKET="                          { yyextra->begin= yytext; return SOCKET; }
+
+"--BINARY-PROTOCOL"                    { yyextra->begin= yytext; return BINARY_PROTOCOL; }
+"--BUFFER-REQUESTS"                    { yyextra->begin= yytext; return BUFFER_REQUESTS; }
+"--CONFIGURE-FILE="                    { yyextra->begin= yytext; return CONFIGURE_FILE; }
+"--CONNECT-TIMEOUT="                   { yyextra->begin= yytext; return CONNECT_TIMEOUT; }
+"--DISTRIBUTION="                      { yyextra->begin= yytext; return DISTRIBUTION; }
+"--HASH-WITH-NAMESPACE"                { yyextra->begin= yytext; return HASH_WITH_NAMESPACE; }
+"--HASH="                              { yyextra->begin= yytext; return HASH; }
+"--IO-BYTES-WATERMARK="                { yyextra->begin= yytext; return IO_BYTES_WATERMARK; }
+"--IO-KEY-PREFETCH="                   { yyextra->begin= yytext; return IO_KEY_PREFETCH; }
+"--IO-MSG-WATERMARK="          { yyextra->begin= yytext; return IO_MSG_WATERMARK; }
+"--NOREPLY"                         { yyextra->begin= yytext; return NOREPLY; }
+"--NUMBER-OF-REPLICAS="                { yyextra->begin= yytext; return NUMBER_OF_REPLICAS; }
+"--POLL-TIMEOUT="                      { yyextra->begin= yytext; return POLL_TIMEOUT; }
+"--RANDOMIZE-REPLICA-READ"             { yyextra->begin= yytext; return RANDOMIZE_REPLICA_READ; }
+"--RCV-TIMEOUT="                       { yyextra->begin= yytext; return RCV_TIMEOUT; }
+"--REMOVE-FAILED-SERVERS="                     { yyextra->begin= yytext; return REMOVE_FAILED_SERVERS; }
+"--RETRY-TIMEOUT="                     { yyextra->begin= yytext; return RETRY_TIMEOUT; }
+"--SND-TIMEOUT="                       { yyextra->begin= yytext; return SND_TIMEOUT; }
+"--SOCKET-RECV-SIZE="          { yyextra->begin= yytext; return SOCKET_RECV_SIZE; }
+"--SOCKET-SEND-SIZE="          { yyextra->begin= yytext; return SOCKET_SEND_SIZE; }
+"--SORT-HOSTS"                 { yyextra->begin= yytext; return SORT_HOSTS; }
+"--SUPPORT-CAS"                        { yyextra->begin= yytext; return SUPPORT_CAS; }
+"--TCP-KEEPALIVE"                      { yyextra->begin= yytext; return _TCP_KEEPALIVE; }
+"--TCP-KEEPIDLE"                       { yyextra->begin= yytext; return _TCP_KEEPIDLE; }
+"--TCP-NODELAY"                        { yyextra->begin= yytext; return _TCP_NODELAY; }
+"--USE-UDP"                            { yyextra->begin= yytext; return USE_UDP; }
+"--USER-DATA"                  { yyextra->begin= yytext; return USER_DATA; }
+"--VERIFY-KEY"                      { yyextra->begin= yytext; return VERIFY_KEY; }
+
+"--POOL-MIN="                          { yyextra->begin= yytext; return POOL_MIN; }
+"--POOL-MAX="                          { yyextra->begin= yytext; return POOL_MAX; }
+
+"--NAMESPACE="                         { yyextra->begin= yytext; return NAMESPACE; }
+
+INCLUDE           { yyextra->begin= yytext; return INCLUDE; }
+RESET           { yyextra->begin= yytext; return RESET; }
+DEBUG           { yyextra->begin= yytext; return PARSER_DEBUG; }
+SERVERS           { yyextra->begin= yytext; return SERVERS; }
+END           { yyextra->begin= yytext; return END; }
+ERROR           { yyextra->begin= yytext; return ERROR; }
+
+TRUE           { return TRUE; }
+FALSE           { return FALSE; }
+
+
+"--"[[:alnum:]]*   {
+      yyextra->begin= yytext;
+      return UNKNOWN_OPTION;
+    }
 
 CONSISTENT      { return CONSISTENT; }
 MODULA          { return MODULA; }
@@ -178,43 +157,42 @@ HSIEH                     { return HSIEH; }
 MURMUR                 { return MURMUR; }
 JENKINS                        { return JENKINS; }
 
-[[:alnum:]][[:alnum:].]*[[:alpha:]]: { 
-      yylval->string.c_str = yytext;
-      yylval->string.length = yyleng;
-      return HOSTNAME_WITH_PORT;
+(([[:digit:]]{1,3}"."){3}([[:digit:]]{1,3})) {
+      yylval->server.port= MEMCACHED_DEFAULT_PORT;
+      yylval->server.weight= 1;
+      yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
+      if (yylval->server.c_str)
+        yylval->server.size= yyleng;
+      return IPADDRESS;
     }
 
-[[:alnum:]]+"."[[:alpha:].]+ { 
-      yylval->string.c_str = yytext;
-      yylval->string.length = yyleng;
-      return HOSTNAME;
-    }
+[[:alnum:]]["."[:alnum:]_-]+[[:alnum:]] {
+      if (yyextra->is_server())
+      {
+        yylval->server.port= MEMCACHED_DEFAULT_PORT;
+        yylval->server.weight= 1;
+        yylval->server.c_str= yyextra->set_hostname(yytext, yyleng);
+        if (yylval->server.c_str)
+          yylval->server.size= yyleng;
 
-[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}: { 
-      yylval->string.c_str = yytext;
-      yylval->string.length = yyleng;
-      return IPADDRESS_WITH_PORT;
-    }
+        return HOSTNAME;
+      }
 
-[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}  { 
       yylval->string.c_str = yytext;
-      yylval->string.length = yyleng;
-      return IPADDRESS;
-    }
+      yylval->string.size = yyleng;
 
-[[:alnum:]]+ { 
-      yylval->string.c_str = yytext;
-      yylval->string.length = yyleng;
       return STRING;
     }
 
-\".*\" { 
-      yylval->string.c_str = yytext;
-      yylval->string.length = yyleng;
+L?\"(\\.|[^\\"])*\" {
+      yyget_text(yyscanner)[yyleng -1]= 0;
+      yylval->string.c_str= yytext +1;
+      yylval->string.size= yyleng -2;
       return QUOTED_STRING;
     }
 
 .   {
+      yyextra->begin= yytext;
       return UNKNOWN;
     }
 
@@ -230,3 +208,4 @@ void Context::destroy_scanner()
 {
   yylex_destroy(scanner);
 }
+