X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=inline;f=libmemcached%2Foptions%2Fparser.yy;h=d309c2278e0b6691c732cf7e35610390036815d0;hb=c4f9265e4f61a10ba1d4b6999c856a8c7df97f56;hp=d4275a09e32ad2eae697ea7ef127cf6d460474b7;hpb=b95041363ea69ccfb9eacb6bba1852814c32b4ee;p=m6w6%2Flibmemcached
diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy
index d4275a09..d309c227 100644
--- a/libmemcached/options/parser.yy
+++ b/libmemcached/options/parser.yy
@@ -18,65 +18,73 @@
* 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
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include
-inline int 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 { (A)->abort((B)); YYABORT; } while (0)
+
+inline void config_error(Context *context, yyscan_t *scanner, const char *error)
{
-#if 0
- std::cerr << str << std::endl;
-#endif
- return 0;
+ if (not context->end())
+ context->abort(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 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
%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
@@ -98,6 +106,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,210 +125,263 @@ 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 IPADDRESS
-%token IPADDRESS_WITH_PORT
+%token NUMBER
+%token PORT
+%token WEIGHT_START
+%token IPADDRESS
+%token HOSTNAME
+%token STRING
+%token QUOTED_STRING
+%token FILE_PATH
-%type server
+%type string
%type distribution
%type hash
+%type behavior_boolean
+%type behavior_number
%%
+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
- {
- (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0);
+ SERVER HOSTNAME optional_port optional_weight
+ {
+ if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);
+ }
+ context->unset_server();
+ }
+ | SERVER IPADDRESS optional_port optional_weight
+ {
+ if ((context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $2.port, $2.weight)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);
+ }
+ context->unset_server();
}
- | SERVERS '=' server_list
+ | CONFIGURE_FILE string
{
+ memcached_set_configuration_file(context->memc, $2.c_str, $2.length);
}
| behaviors
;
behaviors:
- AUTO_EJECT_HOSTS
+ PREFIX_KEY string
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS, 1);
+ if ((context->rc= memcached_set_prefix_key(context->memc, $2.c_str, $2.length)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
- | BINARY_PROTOCOL
+ | DISTRIBUTION distribution
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
- | BUFFER_REQUESTS
+ | DISTRIBUTION distribution ',' hash
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
+ if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
- | CACHE_LOOKUPS
+ | HASH hash
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_CACHE_LOOKUPS, 1);
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
- | CONNECT_TIMEOUT '=' NUMBER
+ | behavior_number NUMBER
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, $3);
+ if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
- | _CORK
+ | behavior_boolean
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_CORK, 1);
+ if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
+ }
}
- | DISTRIBUTION '=' distribution
+ | USER_DATA
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3);
}
- | HASH '=' hash
+ ;
+
+behavior_number:
+ CONNECT_TIMEOUT
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $3);
+ $$= MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT;
}
- | HASH_WITH_PREFIX_KEY
+ | IO_MSG_WATERMARK
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY, 1);
+ $$= MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK;
}
- | IO_BYTES_WATERMARK '=' NUMBER
+ | IO_BYTES_WATERMARK
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, $3);
+ $$= MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK;
}
- | IO_KEY_PREFETCH '=' NUMBER
+ | IO_KEY_PREFETCH
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH, $3);
+ $$= MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH;
}
- | IO_MSG_WATERMARK '=' NUMBER
+ | NUMBER_OF_REPLICAS
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, $3);
+ $$= MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS;
}
- | KETAMA
+ | POLL_TIMEOUT
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA, true);
+ $$= MEMCACHED_BEHAVIOR_POLL_TIMEOUT;
}
- | KETAMA_HASH
+ | RCV_TIMEOUT
{
+ $$= MEMCACHED_BEHAVIOR_RCV_TIMEOUT;
}
- | KETAMA_WEIGHTED
+ | RETRY_TIMEOUT
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, true);
+ $$= MEMCACHED_BEHAVIOR_RETRY_TIMEOUT;
}
- | NOREPLY
+ | SERVER_FAILURE_LIMIT
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_NOREPLY, 1);
+ $$= MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT;
}
- | NUMBER_OF_REPLICAS '=' NUMBER
+ | SND_TIMEOUT
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, $3);
+ $$= MEMCACHED_BEHAVIOR_SND_TIMEOUT;
}
- | POLL_TIMEOUT '=' NUMBER
+ | SOCKET_RECV_SIZE
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, $3);
+ $$= MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE;
}
- | RANDOMIZE_REPLICA_READ
+ | SOCKET_SEND_SIZE
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, true);
+ $$= MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE;
}
- | RCV_TIMEOUT '=' NUMBER
+ ;
+
+behavior_boolean:
+ AUTO_EJECT_HOSTS
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, $3);
+ $$= MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS;
}
- | RETRY_TIMEOUT '=' NUMBER
+ | BINARY_PROTOCOL
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, $3);
+ $$= MEMCACHED_BEHAVIOR_BINARY_PROTOCOL;
}
- | SERVER_FAILURE_LIMIT '=' NUMBER
+ | BUFFER_REQUESTS
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, $3);
+ $$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
}
- | SND_TIMEOUT '=' NUMBER
+ | HASH_WITH_PREFIX_KEY
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, $3);
+ $$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
}
- | SOCKET_RECV_SIZE '=' NUMBER
+ | NOREPLY
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE, $3);
+ $$= MEMCACHED_BEHAVIOR_NOREPLY;
}
- | SOCKET_SEND_SIZE '=' NUMBER
+ | RANDOMIZE_REPLICA_READ
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE, $3);
+ $$= MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ;
}
| SORT_HOSTS
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SORT_HOSTS, true);
+ $$= MEMCACHED_BEHAVIOR_SORT_HOSTS;
}
| SUPPORT_CAS
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true);
+ $$= MEMCACHED_BEHAVIOR_SUPPORT_CAS;
}
| _TCP_NODELAY
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true);
+ $$= MEMCACHED_BEHAVIOR_TCP_NODELAY;
}
| _TCP_KEEPALIVE
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_KEEPALIVE, true);
+ $$= MEMCACHED_BEHAVIOR_TCP_KEEPALIVE;
}
| _TCP_KEEPIDLE
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_KEEPIDLE, true);
- }
- | USER_DATA
- {
+ $$= MEMCACHED_BEHAVIOR_TCP_KEEPIDLE;
}
| USE_UDP
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_USE_UDP, true);
+ $$= MEMCACHED_BEHAVIOR_USE_UDP;
}
| VERIFY_KEY
{
- memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, true);
+ $$= MEMCACHED_BEHAVIOR_VERIFY_KEY;
}
- ;
-server_list:
- server
- {
- (void) memcached_server_add_parsed(parser->memc, $1.c_str, $1.length, $1.port, 0);
- }
- | server_list ',' server
- {
- (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0);
- }
+
+optional_port:
+ { }
+ | PORT
+ { };
;
-server:
- SERVER_WITH_PORT NUMBER
- {
- $$.c_str= $1.c_str;
- $$.length= $1.length -1;
- $$.port= $2;
- }
- | IDENTIFIER
- {
- $$.c_str= $1.c_str;
- $$.length= $1.length;
- $$.port= MEMCACHED_DEFAULT_PORT;
- }
- | IPADDRESS_WITH_PORT NUMBER
- {
- $$.c_str= $1.c_str;
- $$.length= $1.length -1;
- $$.port= $2;
- }
- | IPADDRESS
- {
- $$.c_str= $1.c_str;
- $$.length= $1.length;
- $$.port= MEMCACHED_DEFAULT_PORT;
- }
+optional_weight:
+ { }
+ | WEIGHT_START
+ { }
;
hash:
@@ -359,6 +423,18 @@ hash:
}
;
+string:
+ STRING
+ {
+ $$= $1;
+ }
+ | QUOTED_STRING
+ {
+ $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote
+ $$.length= $1.length -1; // -1 removes the end quote
+ }
+ ;
+
distribution:
CONSISTENT
{
@@ -373,3 +449,11 @@ distribution:
$$= MEMCACHED_DISTRIBUTION_RANDOM;
}
;
+
+%%
+
+void Context::start()
+{
+ config_parse(this, (void **)scanner);
+}
+