X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions%2Fparser.yy;h=6071a99bd02c83087c3259b94870a69d6c090646;hb=8ddd817cd74d85db3f945920fb02f4cc4daa8050;hp=8cd16d538f287cfb2d2518ad01faef065e50d1c8;hpb=1f5cf20c75c7187df1d648a5a200b52db3f17db1;p=awesomized%2Flibmemcached diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index 8cd16d53..6071a99b 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -18,51 +18,70 @@ * along with this program. If not, see . */ +%error-verbose +%debug +%defines +%expect 0 +%output "libmemcached/options/parser.cc" +%defines "libmemcached/options/parser.h" +%lex-param { yyscan_t *scanner } +%name-prefix="config_" +%parse-param { Context *context } +%parse-param { yyscan_t *scanner } +%pure-parser +%require "2.2" +%start begin +%verbose + %{ +#include + #include -#include -#include +#include +#include #include #include +#include +#include #pragma GCC diagnostic ignored "-Wold-style-cast" #include -inline void libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner, const char *str) +int conf_lex(YYSTYPE* lvalp, void* scanner); + +#define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0) + +inline void config_error(Context *context, yyscan_t *scanner, const char *error) { - memcached_string_t local_string; - local_string.size= strlen(str); - local_string.c_str= str; - memcached_set_error(parser->memc, MEMCACHED_FAILURE, &local_string); + if (not context->end()) + parser::abort_func(context, error); } +int config_parse(Context*, yyscan_t *); -%} +void Context::start() +{ + config_parse(this, scanner); +} -%error-verbose -%debug -%defines -%expect 0 -%output "libmemcached/options/parser.cc" -%defines "libmemcached/options/parser.h" -%lex-param { yyscan_t *scanner } -%name-prefix="libmemcached_" -%parse-param { type_st *parser } -%parse-param { yyscan_t *scanner } -%locations -%pure-parser -%require "2.2" -%start statement -%verbose +%} +%token COMMENT +%token END +%token ERROR +%token RESET +%token PARSER_DEBUG +%token INCLUDE +%token CONFIGURE_FILE +%token EMPTY_LINE %token SERVER %token SERVERS +%token SERVERS_OPTION +%token UNKNOWN_OPTION %token UNKNOWN -%token DASH_OPTION - /* All behavior options */ %token AUTO_EJECT_HOSTS %token BINARY_PROTOCOL @@ -117,6 +136,10 @@ inline void libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner %token MODULA %token RANDOM +/* Boolean values */ +%token TRUE +%token FALSE + %nonassoc ',' %nonassoc '=' @@ -128,6 +151,7 @@ inline void libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner %token IPADDRESS_WITH_PORT %token STRING %token QUOTED_STRING +%token FILE_PATH %type server %type string @@ -138,49 +162,106 @@ inline void libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner %% +begin: + statement + | begin ' ' statement + ; + statement: - DASH_OPTION expression + expression + { } + | COMMENT { } - | statement ' ' DASH_OPTION expression + | 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.length)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL); + } + } ; expression: - SERVER '=' server + SERVER server { - (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0); + 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 '=' server_list + | CONFIGURE_FILE string { + memcached_set_configuration_file(context->memc, $2.c_str, $2.length); } | behaviors ; behaviors: - PREFIX_KEY '=' string + PREFIX_KEY string { - memcached_callback_set(parser->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str()); + if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } } - | DISTRIBUTION '=' distribution + | DISTRIBUTION distribution { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3); + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } } - | HASH '=' hash + | HASH hash { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3); + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } } - | KETAMA_HASH '=' hash + | KETAMA_HASH hash { - memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3); + if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $2)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } } - | behavior_number '=' NUMBER + | behavior_number NUMBER { - memcached_behavior_set(parser->memc, $1, $3); + if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } } | behavior_boolean { - memcached_behavior_set(parser->memc, $1, true); + if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } } | USER_DATA { @@ -312,11 +393,17 @@ behavior_boolean: server_list: server { - (void) memcached_server_add_parsed(parser->memc, $1.c_str, $1.length, $1.port, 0); + 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 { - (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0); + if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL);; + } } ; @@ -324,7 +411,7 @@ server: HOSTNAME_WITH_PORT NUMBER { $$.c_str= $1.c_str; - $$.length= $1.length -1; + $$.length= $1.length -1; // -1 to remove : $$.port= $2; } | HOSTNAME @@ -342,7 +429,7 @@ server: | IPADDRESS_WITH_PORT NUMBER { $$.c_str= $1.c_str; - $$.length= $1.length -1; + $$.length= $1.length -1; // -1 to remove : $$.port= $2; } | IPADDRESS @@ -399,8 +486,8 @@ string: } | QUOTED_STRING { - $$.c_str= $1.c_str +1; - $$.length= $1.length -2; + $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote + $$.length= $1.length -1; // -1 removes the end quote } ;