From aa6d65c93cadc9869623af385919db1394116934 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Wed, 23 Mar 2011 13:17:20 -0700 Subject: [PATCH] Adding additional END, RESET, DEBUG, and INCLUDE options. --- libmemcached/options/context.h | 17 +++++++++- libmemcached/options/parser.yy | 59 ++++++++++++++++++++++++++++++---- libmemcached/options/scanner.l | 12 ++++++- libmemcached/options/symbol.h | 1 + 4 files changed, 81 insertions(+), 8 deletions(-) diff --git a/libmemcached/options/context.h b/libmemcached/options/context.h index f7c6d592..e650b5ee 100644 --- a/libmemcached/options/context.h +++ b/libmemcached/options/context.h @@ -48,7 +48,8 @@ public: begin(NULL), pos(0), memc(NULL), - rc(rc_arg) + rc(rc_arg), + _end(false) { buf= option_string; length= option_string_length; @@ -57,6 +58,17 @@ public: rc= MEMCACHED_SUCCESS; } + bool end() + { + return _end; + } + + void set_end() + { + rc= MEMCACHED_SUCCESS; + _end= true; + } + ~Context() { destroy_scanner(); @@ -73,4 +85,7 @@ public: protected: void init_scanner(); void destroy_scanner(); + +private: + bool _end; }; diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index b67052b3..bff5b28d 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -31,7 +31,7 @@ %locations %pure-parser %require "2.2" -%start statement +%start begin %verbose %{ @@ -52,7 +52,9 @@ int libmemcached_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner); -inline void parser_abort(Context *context, const char *error) +#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) @@ -69,16 +71,22 @@ inline void parser_abort(Context *context, const char *error) inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanner, const char *error) { - parser_abort(context, error); + if (not context->end()) + parser_abort_func(context, error); } %} %token COMMENT +%token END +%token RESET +%token DEBUG +%token INCLUDE %token CONFIGURE_FILE %token EMPTY_LINE %token SERVER %token SERVERS +%token SERVERS_OPTION %token UNKNOWN_OPTION %token UNKNOWN @@ -136,6 +144,10 @@ inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanne %token MODULA %token RANDOM +/* Boolean values */ +%token TRUE +%token FALSE + %nonassoc ',' %nonassoc '=' @@ -157,15 +169,50 @@ inline void libmemcached_error(YYLTYPE *locp, Context *context, yyscan_t *scanne %% +begin: + statement + | statement ' ' statement + ; + statement: expression { } - | statement ' ' expression - { } | COMMENT { } | EMPTY_LINE { } + | END + { + context->set_end(); + YYACCEPT; + } + | RESET + { + memcached_reset(context->memc); + } + | RESET SERVERS + { + memcached_servers_reset(context->memc); + } + | DEBUG + { + yydebug= 1; + } + | DEBUG TRUE + { + yydebug= 1; + } + | DEBUG FALSE + { + yydebug= 0; + } + | INCLUDE string + { + if ((context->rc= memcached_parse_configure_file(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS) + { + parser_abort(context, NULL); + } + } ; @@ -177,7 +224,7 @@ expression: parser_abort(context, NULL); } } - | SERVERS '=' server_list + | SERVERS_OPTION '=' server_list { } | CONFIGURE_FILE '=' string diff --git a/libmemcached/options/scanner.l b/libmemcached/options/scanner.l index 2a45455c..a3f91cb9 100644 --- a/libmemcached/options/scanner.l +++ b/libmemcached/options/scanner.l @@ -90,7 +90,7 @@ static void get_lex_chars(char* buffer, int& result, int max_size, Context *cont } "--SERVER" { yyextra->begin= yytext; return SERVER; } -"--SERVERS" { yyextra->begin= yytext; return SERVERS; } +"--SERVERS" { yyextra->begin= yytext; return SERVERS_OPTION; } "--VERIFY_KEY" { yyextra->begin= yytext; return VERIFY_KEY; } "--VERIFY-KEY" { yyextra->begin= yytext; return VERIFY_KEY; } @@ -159,6 +159,16 @@ static void get_lex_chars(char* buffer, int& result, int max_size, Context *cont "--PREFIX-KEY" { yyextra->begin= yytext; return PREFIX_KEY; } "--PREFIX_KEY" { yyextra->begin= yytext; return PREFIX_KEY; } +INCLUDE { yyextra->begin= yytext; return INCLUDE; } +RESET { yyextra->begin= yytext; return RESET; } +DEBUG { yyextra->begin= yytext; return DEBUG; } +SERVERS { yyextra->begin= yytext; return SERVERS; } +END { yyextra->begin= yytext; return END; } + +TRUE { return TRUE; } +FALSE { return FALSE; } + + "--"[[:alnum:]]* { yyextra->begin= yytext; return UNKNOWN_OPTION; diff --git a/libmemcached/options/symbol.h b/libmemcached/options/symbol.h index e4c58b94..b14eb331 100644 --- a/libmemcached/options/symbol.h +++ b/libmemcached/options/symbol.h @@ -51,6 +51,7 @@ union YYSTYPE memcached_server_distribution_t distribution; memcached_hash_t hash; memcached_behavior_t behavior; + bool boolean; }; typedef union YYSTYPE YYSTYPE; -- 2.30.2