X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions%2Fparser.yy;h=d309c2278e0b6691c732cf7e35610390036815d0;hb=c4f9265e4f61a10ba1d4b6999c856a8c7df97f56;hp=6aa477920ce5259444af0c33ece6eb5164a6e64f;hpb=2a34f4dcac48917e41a1b6aee37edbe886aa9f7b;p=m6w6%2Flibmemcached diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index 6aa47792..d309c227 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -40,7 +40,6 @@ #include #include -#include #include #include #include @@ -51,19 +50,12 @@ int conf_lex(YYSTYPE* lvalp, void* scanner); -#define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0) +#define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0) inline void config_error(Context *context, yyscan_t *scanner, const char *error) { if (not context->end()) - parser::abort_func(context, error); -} - -int config_parse(Context*, yyscan_t *); - -void Context::start() -{ - config_parse(this, scanner); + context->abort(error); } %} @@ -86,7 +78,6 @@ void Context::start() %token AUTO_EJECT_HOSTS %token BINARY_PROTOCOL %token BUFFER_REQUESTS -%token CACHE_LOOKUPS %token CONNECT_TIMEOUT %token DISTRIBUTION %token HASH @@ -141,17 +132,16 @@ void Context::start() %nonassoc ',' %nonassoc '=' -%token NUMBER %token FLOAT -%token HOSTNAME -%token HOSTNAME_WITH_PORT -%token IPADDRESS -%token IPADDRESS_WITH_PORT +%token NUMBER +%token PORT +%token WEIGHT_START +%token IPADDRESS +%token HOSTNAME %token STRING %token QUOTED_STRING %token FILE_PATH -%type server %type string %type distribution %type hash @@ -201,15 +191,21 @@ statement: expression: - SERVER server - { - if ((context->rc= memcached_server_add_parsed(context->memc, $2.c_str, $2.length, $2.port, 0)) != MEMCACHED_SUCCESS) + SERVER HOSTNAME optional_port optional_weight + { + if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS) { parser_abort(context, NULL); } + context->unset_server(); } - | SERVERS_OPTION server_list + | SERVER IPADDRESS optional_port optional_weight { + if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL); + } + context->unset_server(); } | CONFIGURE_FILE string { @@ -334,18 +330,10 @@ behavior_boolean: { $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS; } - | CACHE_LOOKUPS - { - $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS; - } | HASH_WITH_PREFIX_KEY { $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY; } - | KETAMA_WEIGHTED - { - $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED; - } | NOREPLY { $$= MEMCACHED_BEHAVIOR_NOREPLY; @@ -384,54 +372,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: + { } + | 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: + { } + | WEIGHT_START + { } ; hash: @@ -499,3 +449,11 @@ distribution: $$= MEMCACHED_DISTRIBUTION_RANDOM; } ; + +%% + +void Context::start() +{ + config_parse(this, (void **)scanner); +} +