parser::abort_func(context, error);
}
-int config_parse(Context*, yyscan_t *);
-
-void Context::start()
-{
- config_parse(this, scanner);
-}
-
%}
%token COMMENT
%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
%nonassoc ','
%nonassoc '='
-%token <number> NUMBER
%token <number> FLOAT
-%token <string> HOSTNAME
-%token <string> HOSTNAME_WITH_PORT
-%token <string> IPADDRESS
-%token <string> IPADDRESS_WITH_PORT
+%token <number> NUMBER
+%token PORT
+%token WEIGHT_START
+%token <server> IPADDRESS
+%token <server> HOSTNAME
%token <string> STRING
%token <string> QUOTED_STRING
%token <string> FILE_PATH
-%type <server> server
%type <string> string
%type <distribution> distribution
%type <hash> hash
expression:
- SERVER '=' server
- {
- if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
+ 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();
}
- | SERVERS_OPTION '=' server_list
+ | 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();
}
- | CONFIGURE_FILE '=' string
+ | CONFIGURE_FILE string
{
- memcached_set_configuration_file(context->memc, $3.c_str, $3.length);
+ memcached_set_configuration_file(context->memc, $2.c_str, $2.length);
}
| behaviors
;
parser_abort(context, NULL);;
}
}
- | HASH hash
+ | DISTRIBUTION distribution ',' hash
{
- if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ parser_abort(context, NULL);;
+ }
+ if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, NULL);;
}
}
- | KETAMA_HASH hash
+ | HASH hash
{
- if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_KETAMA_HASH, $2)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ parser_abort(context, NULL);;
}
}
- | behavior_number '=' NUMBER
+ | behavior_number NUMBER
{
- if ((context->rc= memcached_behavior_set(context->memc, $1, $3)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
{
parser_abort(context, NULL);;
}
{
$$= MEMCACHED_BEHAVIOR_BUFFER_REQUESTS;
}
- | CACHE_LOOKUPS
- {
- $$= MEMCACHED_BEHAVIOR_CACHE_LOOKUPS;
- }
- | _CORK
- {
- $$= MEMCACHED_BEHAVIOR_CORK;
- }
| HASH_WITH_PREFIX_KEY
{
$$= MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY;
}
- | KETAMA
- {
- $$= MEMCACHED_BEHAVIOR_KETAMA;
- }
- | KETAMA_WEIGHTED
- {
- $$= MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED;
- }
| NOREPLY
{
$$= MEMCACHED_BEHAVIOR_NOREPLY;
}
-server_list:
- server
- {
- 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
- {
- if ((context->rc= memcached_server_add_parsed(context->memc, $3.c_str, $3.length, $3.port, 0)) != MEMCACHED_SUCCESS)
- {
- parser_abort(context, NULL);;
- }
- }
+optional_port:
+ { }
+ | PORT
+ { };
;
-server:
- HOSTNAME_WITH_PORT NUMBER
- {
- $$.c_str= $1.c_str;
- $$.length= $1.length -1; // -1 to remove :
- $$.port= $2;
- }
- | 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;
- $$.port= MEMCACHED_DEFAULT_PORT;
- }
- | IPADDRESS_WITH_PORT NUMBER
- {
- $$.c_str= $1.c_str;
- $$.length= $1.length -1; // -1 to remove :
- $$.port= $2;
- }
- | IPADDRESS
- {
- $$.c_str= $1.c_str;
- $$.length= $1.length;
- $$.port= MEMCACHED_DEFAULT_PORT;
- }
+optional_weight:
+ { }
+ | WEIGHT_START
+ { }
;
hash:
$$= MEMCACHED_DISTRIBUTION_RANDOM;
}
;
+
+%%
+
+void Context::start()
+{
+ config_parse(this, (void **)scanner);
+}
+