/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: * * Libmemcached library * * Copyright (C) 2011 Data Differential, http://datadifferential.com/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * * The names of its contributors may not be used to endorse or * promote products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ %{ #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) { std::cerr << str << std::endl; return 0; } %} %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 SERVER %token SERVERS %token TCPNODELAY %token UNKNOWN %token VERIFY_KEY %nonassoc ',' %nonassoc '=' %token NUMBER %token FLOAT %token IDENTIFIER %token SERVER_WITH_PORT %token IPADDRESS %token IPADDRESS_WITH_PORT %type server %% statement: expression { } | statement expression { } ; expression: SERVER '=' server { (void) memcached_server_add_parsed(parser->memc, $3.c_str, $3.length, $3.port, 0); } | SERVERS '=' server_list { } | TCPNODELAY { memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true); } | VERIFY_KEY { memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, true); } ; 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); } ; 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; } ;