X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions%2Fparser.yy;h=81415226e82e002e49b947de5645abd11df9b3f9;hb=5febc397f702ce74f79f3e590432c85b025a32fc;hp=b67052b34edef7dd15b1378c1ad49551b41f9aea;hpb=a4303fb9aa783e5f0575d6ba00d3fe286905d658;p=awesomized%2Flibmemcached diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index b67052b3..81415226 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -25,77 +25,64 @@ %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 } -%locations %pure-parser -%require "2.2" -%start statement +%require "2.4" +%start begin %verbose %{ -#include - -#include -#include -#include -#include +#include +#include #include -#include #include - -#pragma GCC diagnostic ignored "-Wold-style-cast" #include -int libmemcached_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner); +#include -inline void parser_abort(Context *context, const char *error) -{ - (void)error; - if (context->rc == MEMCACHED_SUCCESS) - context->rc= MEMCACHED_PARSE_ERROR; +#pragma GCC diagnostic ignored "-Wold-style-cast" - std::string error_message; - error_message+= context->begin; - error_message+= " ("; - error_message+= memcached_strerror(NULL, context->rc); - error_message+= ")"; +int conf_lex(YYSTYPE* lvalp, void* scanner); - 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(YYLTYPE *locp, Context *context, yyscan_t *scanner, const char *error) +inline void config_error(Context *context, yyscan_t *scanner, const char *error) { - parser_abort(context, error); + if (not context->end()) + context->abort(error); } %} %token COMMENT +%token END +%token ERROR +%token RESET +%token PARSER_DEBUG +%token INCLUDE %token CONFIGURE_FILE %token EMPTY_LINE %token SERVER +%token SOCKET %token SERVERS +%token SERVERS_OPTION %token UNKNOWN_OPTION %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 @@ -103,22 +90,26 @@ inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanne %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 @@ -136,89 +127,148 @@ inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanne %token MODULA %token RANDOM +/* Boolean values */ +%token TRUE +%token FALSE + %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 %type behavior_boolean %type behavior_number +%type distribution +%type hash +%type optional_port +%type optional_weight +%type string %% +begin: + statement + | begin ' ' statement + ; + statement: expression { } - | statement ' ' expression - { } | COMMENT { } | EMPTY_LINE { } + | END + { + context->set_end(); + YYACCEPT; + } + | ERROR + { + context->rc= MEMCACHED_PARSE_USER_ERROR; + parser_abort(context, NULL); + } + | RESET + { + memcached_reset(context->memc); + } + | PARSER_DEBUG + { + yydebug= 1; + } + | INCLUDE ' ' string + { + if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL); + } + } ; 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(); + } + | SOCKET string optional_weight + { + if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3))) { parser_abort(context, NULL); } } - | SERVERS '=' 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);; } @@ -236,7 +286,11 @@ behaviors: ; behavior_number: - CONNECT_TIMEOUT + REMOVE_FAILED_SERVERS + { + $$= MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS; + } + | CONNECT_TIMEOUT { $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT; } @@ -268,10 +322,6 @@ behavior_number: { $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT; } - | SERVER_FAILURE_LIMIT - { - $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT; - } | SND_TIMEOUT { $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT; @@ -287,11 +337,7 @@ behavior_number: ; behavior_boolean: - AUTO_EJECT_HOSTS - { - $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS; - } - | BINARY_PROTOCOL + BINARY_PROTOCOL { $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL; } @@ -299,26 +345,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; @@ -357,54 +387,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; - $$.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; - $$.port= $2; - } - | IPADDRESS - { - $$.c_str= $1.c_str; - $$.length= $1.length; - $$.port= MEMCACHED_DEFAULT_PORT; - } +optional_weight: + { $$= 1; } + | WEIGHT_START + { } ; hash: @@ -453,8 +445,11 @@ string: } | QUOTED_STRING { - $$.c_str= $1.c_str +1; - $$.length= $1.length -2; + $$= $1; + #if 0 + $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote + $$.size= $1.size -2; // -2 removes the begin and end quote + #endif } ; @@ -472,3 +467,11 @@ distribution: $$= MEMCACHED_DISTRIBUTION_RANDOM; } ; + +%% + +void Context::start() +{ + config_parse(this, (void **)scanner); +} +