X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions%2Fparser.yy;h=db311402b45c7795908d6b447c11d0cdd6417e43;hb=81416ab2d4fe60d5c71ea11326a351993c539002;hp=e7b95bdfc5a1705c1eec1009c9c69dd8e0136133;hpb=5238132fd18ec3e16cdd81148614c1a351056660;p=awesomized%2Flibmemcached diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index e7b95bdf..db311402 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -25,10 +25,9 @@ %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 begin @@ -39,54 +38,25 @@ #include #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); +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 { parser::abort_func((A), (B)); YYABORT; } while (0) -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()); -} - -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) { if (not context->end()) - parser_abort_func(context, error); -} - -int libmemcached_parse(Context*, yyscan_t *); -void Context::start() -{ - libmemcached_parse(this, scanner); + parser::abort_func(context, error); } %} @@ -111,14 +81,12 @@ void Context::start() %token BUFFER_REQUESTS %token CACHE_LOOKUPS %token CONNECT_TIMEOUT -%token _CORK %token DISTRIBUTION %token HASH %token HASH_WITH_PREFIX_KEY %token IO_BYTES_WATERMARK %token IO_KEY_PREFETCH %token IO_MSG_WATERMARK -%token KETAMA %token KETAMA_HASH %token KETAMA_WEIGHTED %token NOREPLY @@ -226,55 +194,59 @@ statement: expression: - SERVER '=' server + SERVER server { - if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS) + if ((context->rc= memcached_server_add_parsed(context->memc, $2.c_str, $2.length, $2.port, 0)) != MEMCACHED_SUCCESS) { parser_abort(context, NULL); } } - | SERVERS_OPTION '=' server_list + | SERVERS_OPTION server_list { } - | CONFIGURE_FILE '=' string + | CONFIGURE_FILE string { - memcached_set_configuration_file(context->memc, $3.c_str, $3.length); + memcached_set_configuration_file(context->memc, $2.c_str, $2.length); } | behaviors ; behaviors: - PREFIX_KEY '=' string + PREFIX_KEY 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_prefix_key(context->memc, $2.c_str, $2.length)) != 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);; } @@ -359,18 +331,10 @@ behavior_boolean: { $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS; } - | _CORK - { - $$= MEMCACHED_BEHAVIOR_CORK; - } | HASH_WITH_PREFIX_KEY { $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY; } - | KETAMA - { - $$= MEMCACHED_BEHAVIOR_KETAMA; - } | KETAMA_WEIGHTED { $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED; @@ -528,3 +492,11 @@ distribution: $$= MEMCACHED_DISTRIBUTION_RANDOM; } ; + +%% + +void Context::start() +{ + config_parse(this, (void **)scanner); +} +