X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions%2Fparser.yy;h=bff5b28df69bb7eaea48033927040399f2547b76;hb=aa6d65c93cadc9869623af385919db1394116934;hp=20f17c752fce3097a91ffc59d873ba28764bec7c;hpb=faae971a1b825275ed3585c9692be3d84a62ce01;p=m6w6%2Flibmemcached
diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy
index 20f17c75..bff5b28d 100644
--- a/libmemcached/options/parser.yy
+++ b/libmemcached/options/parser.yy
@@ -18,6 +18,22 @@
* 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="libmemcached_"
+%parse-param { Context *context }
+%parse-param { yyscan_t *scanner }
+%locations
+%pure-parser
+%require "2.2"
+%start begin
+%verbose
+
%{
#include
@@ -27,49 +43,53 @@
#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 libmemcached_lex(YYSTYPE* lvalp, YYLTYPE* llocp, void* scanner);
+
+#define parser_abort(A, B) do { parser_abort_func((A), (B)); YYABORT; } while (0)
+
+inline void parser_abort_func(Context *context, 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);
+ (void)error;
+ if (context->rc == MEMCACHED_SUCCESS)
+ context->rc= MEMCACHED_PARSE_ERROR;
+
+ std::string error_message;
+ error_message+= context->begin;
+ error_message+= " (";
+ 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)
+{
+ if (not context->end())
+ parser_abort_func(context, error);
+}
%}
-%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 RESET
+%token 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
@@ -124,6 +144,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 '='
@@ -145,30 +169,67 @@ inline void libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner
%%
+begin:
+ statement
+ | statement ' ' statement
+ ;
+
statement:
- DASH_OPTION expression
- { }
- | statement ' ' DASH_OPTION expression
+ 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);
+ }
+ }
;
expression:
SERVER '=' server
{
- if (memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0) != MEMCACHED_SUCCESS)
- YYERROR;
+ if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);
+ }
}
- | SERVERS '=' server_list
+ | SERVERS_OPTION '=' server_list
{
}
| CONFIGURE_FILE '=' string
{
- memcached_set_configuration_file(parser->memc, $3.c_str, $3.length);
+ memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
}
| behaviors
;
@@ -176,67 +237,44 @@ expression:
behaviors:
PREFIX_KEY '=' string
{
- memcached_return_t rc;
- if ((rc= memcached_callback_set(parser->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS)
{
- std::string error_message("--PREFIX-KEY");
- error_message.append($3.c_str, $3.length);
- memcached_string_t tmp= memcached_string_make(error_message.c_str(), error_message.size());
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
| DISTRIBUTION '=' distribution
{
- memcached_return_t rc;
- if ((rc= memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
{
- memcached_string_t tmp= memcached_string_make(memcached_string_with_size("--DISTRIBUTION"));
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
| HASH '=' hash
{
- memcached_return_t rc;
- if ((rc= memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
{
- std::string buffer;
- buffer+= "--HASH=";
- buffer+= libmemcached_string_hash($3);
- memcached_string_t tmp= memcached_string_make(buffer.c_str(), buffer.size());
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
| KETAMA_HASH '=' hash
{
- memcached_return_t rc;
- if ((rc= memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $3)) != MEMCACHED_SUCCESS)
{
- memcached_string_t tmp= memcached_string_make(memcached_string_with_size("--KETAMA-HASH"));
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
| behavior_number '=' NUMBER
{
- memcached_return_t rc;
- if ((rc= memcached_behavior_set(parser->memc, $1, $3)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
{
- memcached_string_t tmp= memcached_string_make(libmemcached_string_behavior($1), strlen(libmemcached_string_behavior($1)));
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
| behavior_boolean
{
- memcached_return_t rc;
- if ((rc= memcached_behavior_set(parser->memc, $1, true)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
{
- memcached_string_t tmp= memcached_string_make(libmemcached_string_behavior($1), strlen(libmemcached_string_behavior($1)));
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
| USER_DATA
@@ -369,26 +407,16 @@ behavior_boolean:
server_list:
server
{
- memcached_return_t rc;
- if ((rc= memcached_server_add_parsed(parser->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_server_add_parsed(context->memc, $1.c_str, $1.length, $1.port, 0)) != MEMCACHED_SUCCESS)
{
- std::stringstream ss;
- ss << "--SERVER=" << $1;
- memcached_string_t tmp= memcached_string_make(ss.str().c_str(), ss.str().length());
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
| server_list ',' server
{
- memcached_return_t rc;
- if ((rc= memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
{
- std::stringstream ss;
- ss << "--SERVERS=" << $3;
- memcached_string_t tmp= memcached_string_make(ss.str().c_str(), ss.str().length());
- memcached_set_error(parser->memc, rc, &tmp);
- YYERROR;
+ parser_abort(context, NULL);;
}
}
;