4bba48a22aa5121bd4b407cea8fc56494109f748
[m6w6/libmemcached] / libmemcached / options / parser.yy
1 /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
2 *
3 * Libmemcached library
4 *
5 * Copyright (C) 2011 Data Differential, http://datadifferential.com/
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following disclaimer
17 * in the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * * The names of its contributors may not be used to endorse or
21 * promote products derived from this software without specific prior
22 * written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 */
37
38 %{
39
40 #include <stdint.h>
41 #include <iostream>
42
43 #include <libmemcached/options/type.h>
44 #include <libmemcached/options/string.h>
45 #include <libmemcached/options/symbol.h>
46
47 #pragma GCC diagnostic ignored "-Wold-style-cast"
48 #include <libmemcached/options/scanner.h>
49
50 inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner, const char *str)
51 {
52 std::cerr << str << std::endl;
53 return 0;
54 }
55
56
57 %}
58
59 %error-verbose
60 %debug
61 %defines
62 %expect 0
63 %output "libmemcached/options/parser.cc"
64 %defines "libmemcached/options/parser.h"
65 %lex-param { yyscan_t *scanner }
66 %name-prefix="libmemcached_"
67 %parse-param { type_st *parser }
68 %parse-param { yyscan_t *scanner }
69 %locations
70 %pure-parser
71 %require "2.2"
72 %start statement
73 %verbose
74
75 %token SERVER
76 %token SERVERS
77 %token TCPNODELAY
78 %token UNKNOWN
79 %token VERIFY_KEY
80 %nonassoc ','
81 %nonassoc '='
82
83 %token <number> NUMBER
84 %token <number> FLOAT
85 %token <string> IDENTIFIER
86 %token <string> SERVER_WITH_PORT
87 %token <string> IPADDRESS
88 %token <string> IPADDRESS_WITH_PORT
89
90 %type <server> server
91
92 %%
93
94 statement:
95 expression
96 { }
97 | statement expression
98 { }
99 ;
100
101
102 expression:
103 SERVER '=' server
104 {
105 (void) memcached_server_add(parser->memc, $3.c_str, $3.port);
106 }
107 | SERVERS '=' server_list
108 { }
109 | TCPNODELAY
110 {
111 memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true);
112 }
113 | VERIFY_KEY
114 {
115 memcached_behavior_set(parser->memc, MEMCACHED_BEHAVIOR_VERIFY_KEY, true);
116 }
117 ;
118
119 server_list:
120 server
121 {
122 (void) memcached_server_add(parser->memc, $1.c_str, $1.port);
123 }
124 | server_list ',' server
125 {
126 (void) memcached_server_add(parser->memc, $3.c_str, $3.port);
127 }
128 ;
129
130 server:
131 SERVER_WITH_PORT NUMBER
132 {
133 $$.c_str= $1.c_str;
134 $$.length= $1.length -1;
135 $$.port= $2;
136 }
137 | IDENTIFIER
138 {
139 $$.c_str= $1.c_str;
140 $$.length= $1.length;
141 $$.port= MEMCACHED_DEFAULT_PORT;
142 }
143 | IPADDRESS_WITH_PORT NUMBER
144 {
145 $$.c_str= $1.c_str;
146 $$.length= $1.length -1;
147 $$.port= $2;
148 }
149 | IPADDRESS
150 {
151 $$.c_str= $1.c_str;
152 $$.length= $1.length;
153 $$.port= MEMCACHED_DEFAULT_PORT;
154 }
155 ;