X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Foptions%2Fparser.yy;h=dd19ef8b52d3c98a58722b6fcaff2f3a3b24d645;hb=d9752c25d2f723d27e355d0c7090b65b0445c4a4;hp=3a7cee2eed170492600305dba1d031c33aee1fa7;hpb=696240873d8c6ca5edc482a7395984aac14d5b32;p=m6w6%2Flibmemcached
diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy
index 3a7cee2e..dd19ef8b 100644
--- a/libmemcached/options/parser.yy
+++ b/libmemcached/options/parser.yy
@@ -18,51 +18,85 @@
* 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
+
#include
#include
+#include
+#include
-#include
+#include
#include
#include
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include
-inline int 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)
{
-#if 0
- std::cerr << str << std::endl;
-#endif
- return 0;
+ (void)error;
+ if (context->rc == MEMCACHED_SUCCESS)
+ context->rc= MEMCACHED_PARSE_ERROR;
+
+ std::string error_message;
+ 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)
+{
+ 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
@@ -98,6 +132,9 @@ inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner,
%token USE_UDP
%token VERIFY_KEY
+/* Callbacks */
+%token PREFIX_KEY
+
/* Hash types */
%token MD5
%token CRC
@@ -114,17 +151,25 @@ inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner,
%token MODULA
%token RANDOM
+/* Boolean values */
+%token TRUE
+%token FALSE
+
%nonassoc ','
%nonassoc '='
%token NUMBER
%token FLOAT
-%token IDENTIFIER
-%token SERVER_WITH_PORT
+%token HOSTNAME
+%token HOSTNAME_WITH_PORT
%token IPADDRESS
%token IPADDRESS_WITH_PORT
+%token STRING
+%token QUOTED_STRING
+%token FILE_PATH
%type server
+%type string
%type distribution
%type hash
%type behavior_boolean
@@ -132,45 +177,114 @@ inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner,
%%
+begin:
+ statement
+ | begin ' ' statement
+ ;
+
statement:
- DASH_OPTION expression
+ expression
{ }
- | statement ' ' DASH_OPTION 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 FILE_PATH
+ {
+ std::cerr << "Got into INCLUDE" << std::endl;
+ if ((context->rc= memcached_parse_configure_file(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);
+ }
+ }
;
expression:
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, $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(context->memc, $3.c_str, $3.length);
+ }
| behaviors
;
behaviors:
+ 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)
+ {
+ parser_abort(context, NULL);;
+ }
+ }
| DISTRIBUTION '=' distribution
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3);
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
| HASH '=' hash
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3);
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $3)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
| 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, $3)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
| behavior_number '=' NUMBER
{
- memcached_behavior_set(parser->memc, $1, $3);
+ if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != 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
{
@@ -302,22 +416,34 @@ 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);;
+ }
}
;
server:
- SERVER_WITH_PORT NUMBER
+ HOSTNAME_WITH_PORT NUMBER
{
$$.c_str= $1.c_str;
$$.length= $1.length -1;
$$.port= $2;
}
- | IDENTIFIER
+ | 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;
@@ -376,6 +502,18 @@ hash:
}
;
+string:
+ STRING
+ {
+ $$= $1;
+ }
+ | QUOTED_STRING
+ {
+ $$.c_str= $1.c_str +1;
+ $$.length= $1.length -2;
+ }
+ ;
+
distribution:
CONSISTENT
{