%{
-#include <libmemcached/common.h>
+#include <libmemcached/csl/common.h>
#include <libmemcached/options.hpp>
#include <libmemcached/csl/context.h>
#include <libmemcached/csl/symbol.h>
#include <libmemcached/csl/scanner.h>
-#include <iostream>
-
+#ifndef __INTEL_COMPILER
#pragma GCC diagnostic ignored "-Wold-style-cast"
+#endif
int conf_lex(YYSTYPE* lvalp, void* scanner);
-#define parser_abort(A, B) do { (A)->abort((B)); YYABORT; } while (0)
+#define select_yychar(__context) yychar == UNKNOWN ? ( (__context)->previous_token == END ? UNKNOWN : (__context)->previous_token ) : yychar
+
+#define stryytname(__yytokentype) ((__yytokentype) < YYNTOKENS ) ? yytname[(__yytokentype)] : ""
-inline void config_error(Context *context, yyscan_t *scanner, const char *error)
+#define parser_abort(__context, __error_message) do { (__context)->abort((__error_message), yytokentype(select_yychar(__context)), stryytname(YYTRANSLATE(select_yychar(__context)))); YYABORT; } while (0)
+
+// This is bison calling error.
+inline void __config_error(Context *context, yyscan_t *scanner, const char *error, int last_token, const char *last_token_str)
{
if (not context->end())
- context->abort(error);
+ {
+ context->error(error, yytokentype(last_token), last_token_str);
+ }
+ else
+ {
+ context->error(error, yytokentype(last_token), last_token_str);
+ }
}
+#define config_error(__context, __scanner, __error_msg) do { __config_error((__context), (__scanner), (__error_msg), select_yychar(__context), stryytname(YYTRANSLATE(select_yychar(__context)))); } while (0)
+
+
%}
%token COMMENT
| ERROR
{
context->rc= MEMCACHED_PARSE_USER_ERROR;
- parser_abort(context, NULL);
+ parser_abort(context, "ERROR called directly");
}
| RESET
{
{
if ((context->rc= memcached_parse_configure_file(*context->memc, $3.c_str, $3.size)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);
+ parser_abort(context, "Failed to parse configuration file");
}
}
;
{
if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
{
- parser_abort(context, NULL);
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
+ parser_abort(context, buffer);
}
context->unset_server();
}
{
if (memcached_failed(context->rc= memcached_server_add_with_weight(context->memc, $2.c_str, $3, $4)))
{
- parser_abort(context, NULL);
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "Failed to add server: %s:%u", $2.c_str, uint32_t($3));
+ parser_abort(context, buffer);
}
context->unset_server();
}
{
if (memcached_failed(context->rc= memcached_server_add_unix_socket_with_weight(context->memc, $2.c_str, $3)))
{
- parser_abort(context, NULL);
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "Failed to add server: %s", $2.c_str);
+ parser_abort(context, buffer);
}
}
| CONFIGURE_FILE string
behaviors:
NAMESPACE string
{
+ if (memcached_callback_get(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, NULL))
+ {
+ parser_abort(context, "--NAMESPACE can only be called once");
+ }
+
if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ parser_abort(context, memcached_last_error_message(context->memc));
}
}
| DISTRIBUTION distribution
{
+ // Check to see if DISTRIBUTION has already been set
+ if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
+ {
+ parser_abort(context, "--DISTRIBUTION can only be called once");
+ }
+
if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ parser_abort(context, memcached_last_error_message(context->memc));;
}
}
| DISTRIBUTION distribution ',' hash
{
+ // Check to see if DISTRIBUTION has already been set
if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, $2)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ parser_abort(context, "--DISTRIBUTION can only be called once");
}
+
if ((context->rc= memcached_behavior_set_distribution_hash(context->memc, $4)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ parser_abort(context, "Unable to set the hash for the DISTRIBUTION requested");
}
}
| HASH hash
{
- if ((context->rc= memcached_behavior_set(context->memc, MEMCACHED_BEHAVIOR_HASH, $2)) != MEMCACHED_SUCCESS)
+ if (context->set_hash($2) == false)
{
- parser_abort(context, NULL);;
+ parser_abort(context, "--HASH can only be set once");
}
}
| behavior_number NUMBER
{
if ((context->rc= memcached_behavior_set(context->memc, $1, $2)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ parser_abort(context, "Unable to set behavior");
}
}
| behavior_boolean
{
if ((context->rc= memcached_behavior_set(context->memc, $1, true)) != MEMCACHED_SUCCESS)
{
- parser_abort(context, NULL);;
+ char buffer[1024];
+ snprintf(buffer, sizeof(buffer), "Could not set: %s", libmemcached_string_behavior($1));
+ parser_abort(context, buffer);
}
}
| USER_DATA