Merge in namespace fixes for binary protocol.
[awesomized/libmemcached] / libmemcached / options / parser.yy
index adf3dc019bc41f7324604c7950a465684d711571..8e87230ade8c10e534d2d3c8db618ea31c3948c3 100644 (file)
@@ -25,7 +25,7 @@
 %output "libmemcached/options/parser.cc"
 %defines "libmemcached/options/parser.h"
 %lex-param { yyscan_t *scanner }
-%name-prefix="libmemcached_"
+%name-prefix="config_"
 %parse-param { Context *context }
 %parse-param { yyscan_t *scanner }
 %pure-parser
 
 #include <stdint.h>
 
+#include <libmemcached/common.h>
+#include <libmemcached/options.hpp>
+
 #include <libmemcached/options/context.h>
-#include <libmemcached/options/string.h>
 #include <libmemcached/options/symbol.h>
-
-#pragma GCC diagnostic ignored "-Wold-style-cast"
 #include <libmemcached/options/scanner.h>
 
-int libmemcached_lex(YYSTYPE* lvalp, void* scanner);
+#pragma GCC diagnostic ignored "-Wold-style-cast"
 
-#define parser_abort(A, B) do { parser_abort_func((A), (B)); YYABORT; } while (0) 
+int conf_lex(YYSTYPE* lvalp, void* scanner);
 
-inline void parser_abort_func(Context *context, const char *error)
-{
-  (void)error;
-  if (context->rc == MEMCACHED_SUCCESS)
-    context->rc= MEMCACHED_PARSE_ERROR;
-
-  std::string error_message;
-  error_message+= "Error occured while parsing: ";
-  error_message+= context->begin;
-  error_message+= " (";
-  if (context->rc == MEMCACHED_PARSE_ERROR and error)
-  {
-    error_message+= error;
-  }
-  else
-  {
-    error_message+= memcached_strerror(NULL, context->rc);
-  }
-  error_message+= ")";
-
-  memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size());
-}
+#define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0) 
 
-inline void libmemcached_error(Context *context, yyscan_t *scanner, const char *error)
+inline void config_error(Context *context, yyscan_t *scanner, const char *error)
 {
   if (not context->end())
-    parser_abort_func(context, error);
-}
-
-int libmemcached_parse(Context*, yyscan_t *);
-void Context::start() 
-{
-  libmemcached_parse(this, scanner);
+    context->abort(error);
 }
 
 %}
@@ -102,19 +75,15 @@ void Context::start()
 %token UNKNOWN
 
 /* All behavior options */
-%token AUTO_EJECT_HOSTS
 %token BINARY_PROTOCOL
 %token BUFFER_REQUESTS
-%token CACHE_LOOKUPS
 %token CONNECT_TIMEOUT
-%token _CORK
 %token DISTRIBUTION
 %token HASH
-%token HASH_WITH_PREFIX_KEY
+%token HASH_WITH_NAMESPACE
 %token IO_BYTES_WATERMARK
 %token IO_KEY_PREFETCH
 %token IO_MSG_WATERMARK
-%token KETAMA
 %token KETAMA_HASH
 %token KETAMA_WEIGHTED
 %token NOREPLY
@@ -122,22 +91,26 @@ void Context::start()
 %token POLL_TIMEOUT
 %token RANDOMIZE_REPLICA_READ
 %token RCV_TIMEOUT
+%token REMOVE_FAILED_SERVERS
 %token RETRY_TIMEOUT
-%token SERVER_FAILURE_LIMIT
 %token SND_TIMEOUT
 %token SOCKET_RECV_SIZE
 %token SOCKET_SEND_SIZE
 %token SORT_HOSTS
 %token SUPPORT_CAS
-%token _TCP_NODELAY
-%token _TCP_KEEPALIVE
-%token _TCP_KEEPIDLE
 %token USER_DATA
 %token USE_UDP
 %token VERIFY_KEY
+%token _TCP_KEEPALIVE
+%token _TCP_KEEPIDLE
+%token _TCP_NODELAY
 
 /* Callbacks */
-%token PREFIX_KEY
+%token NAMESPACE
+
+/* Pool */
+%token POOL_MIN
+%token POOL_MAX
 
 /* Hash types */
 %token MD5
@@ -162,22 +135,23 @@ void Context::start()
 %nonassoc ','
 %nonassoc '='
 
-%token <number> NUMBER
 %token <number> FLOAT
-%token <string> HOSTNAME
-%token <string> HOSTNAME_WITH_PORT
-%token <string> IPADDRESS
-%token <string> IPADDRESS_WITH_PORT
+%token <number> NUMBER
+%token <number> PORT
+%token <number> WEIGHT_START
+%token <server> IPADDRESS
+%token <server> HOSTNAME
 %token <string> STRING
 %token <string> QUOTED_STRING
 %token <string> FILE_PATH
 
-%type <server> server
-%type <string> string
-%type <distribution> distribution
-%type <hash> hash
 %type <behavior> behavior_boolean
 %type <behavior> behavior_number
+%type <distribution> distribution
+%type <hash> hash
+%type <number> optional_port
+%type <number> optional_weight
+%type <string> string
 
 %%
 
@@ -213,7 +187,7 @@ statement:
           }
         | INCLUDE ' ' string
           {
-            if ((context->rc= memcached_parse_configure_file(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS)
+            if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
             {
               parser_abort(context, NULL);
             }
@@ -222,55 +196,73 @@ statement:
 
 
 expression:
-          SERVER '=' server
-          { 
-            if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
+          SERVER HOSTNAME optional_port optional_weight
+          {
+            if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
+            {
+              parser_abort(context, NULL);
+            }
+            context->unset_server();
+          }
+        | SERVER IPADDRESS optional_port optional_weight
+          {
+            if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
             {
               parser_abort(context, NULL);
             }
+            context->unset_server();
           }
-        | SERVERS_OPTION '=' server_list
+        | CONFIGURE_FILE string
           {
+            memcached_set_configuration_file(context->memc, $2.c_str, $2.size);
           }
-        | CONFIGURE_FILE '=' string
+        | POOL_MIN NUMBER
           {
-            memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
+            context->memc->configure.initial_pool_size= $2;
+          }
+        | POOL_MAX NUMBER
+          {
+            context->memc->configure.max_pool_size= $2;
           }
         | behaviors
         ;
 
 behaviors:
-          PREFIX_KEY '=' string
+          NAMESPACE string
           {
-            if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
+            if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
             {
               parser_abort(context, NULL);;
             }
           }
-        | DISTRIBUTION '=' distribution
+        | DISTRIBUTION distribution
           {
-            if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
+            if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
             {
               parser_abort(context, NULL);;
             }
           }
-        | HASH '=' hash
+        | DISTRIBUTION distribution ',' hash
           {
-            if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
+            if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
             {
-              parser_abort(context, NULL);; 
+              parser_abort(context, NULL);;
+            }
+            if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
+            {
+              parser_abort(context, NULL);;
             }
           }
-        | KETAMA_HASH '=' hash
+        | HASH hash
           {
-            if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
+            if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
             {
-              parser_abort(context, NULL);;
+              parser_abort(context, NULL);; 
             }
           }
-        | behavior_number '=' NUMBER
+        | behavior_number NUMBER
           {
-            if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
+            if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
             {
               parser_abort(context, NULL);;
             }
@@ -288,7 +280,11 @@ behaviors:
         ;
 
 behavior_number:
-          CONNECT_TIMEOUT
+          REMOVE_FAILED_SERVERS
+          {
+            $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS;
+          }
+        | CONNECT_TIMEOUT
           {
             $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
           }
@@ -320,10 +316,6 @@ behavior_number:
           {
             $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
           }
-        |  SERVER_FAILURE_LIMIT
-          {
-            $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
-          }
         |  SND_TIMEOUT
           {
             $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
@@ -339,11 +331,7 @@ behavior_number:
         ;
 
 behavior_boolean: 
-          AUTO_EJECT_HOSTS
-          {
-            $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
-          }
-        | BINARY_PROTOCOL
+          BINARY_PROTOCOL
           {
             $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
           }
@@ -351,26 +339,10 @@ behavior_boolean:
           {
             $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
           }
-        | CACHE_LOOKUPS
-          {
-            $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
-          }
-        | _CORK
-          {
-            $$= MEMCACHED_BEHAVIOR_CORK;
-          }
-        | HASH_WITH_PREFIX_KEY
+        | HASH_WITH_NAMESPACE
           {
             $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
           }
-        | KETAMA
-          {
-            $$= MEMCACHED_BEHAVIOR_KETAMA;
-          }
-        | KETAMA_WEIGHTED
-          {
-            $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
-          }
         | NOREPLY
           {
             $$= MEMCACHED_BEHAVIOR_NOREPLY;
@@ -409,54 +381,16 @@ behavior_boolean:
           }
 
 
-server_list:
-           server
-          {
-            if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
-            {
-              parser_abort(context, NULL);;
-            }
-          }
-        | server_list ',' server
-          {
-            if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
-            {
-              parser_abort(context, NULL);;
-            }
-          }
+optional_port:
+          { $$= MEMCACHED_DEFAULT_PORT;}
+        | PORT
+          { };
         ;
 
-server:
-          HOSTNAME_WITH_PORT NUMBER
-          {
-            $$.c_str= $1.c_str;
-            $$.length= $1.length -1; // -1 to remove :
-            $$.port= $2;
-          }
-        | HOSTNAME
-          {
-            $$.c_str= $1.c_str;
-            $$.length= $1.length;
-            $$.port= MEMCACHED_DEFAULT_PORT;
-          }
-        | STRING /* a match can be against "localhost" which is just a string */
-          {
-            $$.c_str= $1.c_str;
-            $$.length= $1.length;
-            $$.port= MEMCACHED_DEFAULT_PORT;
-          }
-        | IPADDRESS_WITH_PORT NUMBER
-          {
-            $$.c_str= $1.c_str;
-            $$.length= $1.length -1; // -1 to remove :
-            $$.port= $2;
-          }
-        | IPADDRESS
-          {
-            $$.c_str= $1.c_str;
-            $$.length= $1.length;
-            $$.port= MEMCACHED_DEFAULT_PORT;
-          }
+optional_weight:
+          { $$= 1; }
+        | WEIGHT_START
+          { }
         ;
 
 hash:
@@ -506,7 +440,7 @@ string:
         | QUOTED_STRING
           {
             $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
-            $$.length= $1.length -1; // -1 removes the end quote
+            $$.size= $1.size -2; // -2 removes the begin and end quote
           }
         ;
 
@@ -524,3 +458,11 @@ distribution:
             $$= MEMCACHED_DISTRIBUTION_RANDOM;
           }
         ;
+
+%% 
+
+void Context::start() 
+{
+  config_parse(this, (void **)scanner);
+}
+