1 karl 1.15 /*
2 //%LICENSE////////////////////////////////////////////////////////////////
|
3 martin 1.13 //
|
4 martin 1.12 // Licensed to The Open Group (TOG) under one or more contributor license
5 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
6 // this work for additional information regarding copyright ownership.
7 // Each contributor licenses this file to you under the OpenPegasus Open
8 // Source License; you may not use this file except in compliance with the
9 // License.
|
10 martin 1.13 //
|
11 martin 1.12 // Permission is hereby granted, free of charge, to any person obtaining a
12 // copy of this software and associated documentation files (the "Software"),
13 // to deal in the Software without restriction, including without limitation
14 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 // and/or sell copies of the Software, and to permit persons to whom the
16 // Software is furnished to do so, subject to the following conditions:
|
17 martin 1.13 //
|
18 martin 1.12 // The above copyright notice and this permission notice shall be included
19 // in all copies or substantial portions of the Software.
|
20 martin 1.13 //
|
21 martin 1.12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
22 martin 1.13 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23 martin 1.12 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28 martin 1.13 //
|
29 karl 1.15 /////////////////////////////////////////////////////////////////////////
30 */
|
31 karl 1.9
|
32 kumpf 1.10
|
33 mike 1.2 %option never-interactive
34 %{
35
36 extern int WQLInput(char* buffer, int& numRead, int numRequested);
|
37 kumpf 1.3 extern int WQL_error(const char*);
|
38 mike 1.2
39 #define YY_INPUT(BUF, NREAD, NREQUESTED) WQLInput(BUF, NREAD, NREQUESTED)
40
41 #include <Pegasus/Common/Config.h>
42 #include <Pegasus/WQL/WQLParserState.h>
43 #include <cstring>
44 #include <cassert>
45 #include "WQLYACC.h"
46
47 #if 0
48 # define WQL_TRACE(X) printf X
49 #else
50 # define WQL_TRACE(X)
51 #endif
52
|
53 kumpf 1.10 /* Avoid warn_unused_result warnings in Linux RPM build */
|
54 kumpf 1.11 #ifndef ECHO
55 # define ECHO do { size_t ignored = fwrite(yytext, yyleng, 1, yyout); } while(0)
56 #endif
|
57 kumpf 1.10
|
58 mike 1.2 PEGASUS_NAMESPACE_BEGIN
59
60 extern WQLParserState* globalParserState;
61
62 static char* CloneString(const char* str, Uint32 size = (Uint32)-1);
63
64 PEGASUS_NAMESPACE_END
65
66 PEGASUS_USING_PEGASUS;
67
68 %}
69
70 POSITIVE_DECIMAL_DIGIT [1-9]
71 DECIMAL_DIGIT [0-9]
72 BLANK [ \t\n]
73 IDENT_CHAR [A-Za-z_]
74
75 %%
76
77 [Ss][Ee][Ll][Ee][Cc][Tt] {
78
79 mike 1.2 WQL_TRACE(("LEX: %s [TOK_SELECT]\n", yytext));
80 return TOK_SELECT;
81 }
82
83 [Ff][Rr][Oo][Mm] {
84
85 WQL_TRACE(("LEX: %s [TOK_FROM]\n", yytext));
86 return TOK_FROM;
87 }
88
89 [Ww][Hh][Ee][Rr][Ee] {
90
91 WQL_TRACE(("LEX: %s [TOK_WHERE]\n", yytext));
92 return TOK_WHERE;
93 }
94
|
95 karl 1.7 [Ii][Ss][Aa] {
96
97 WQL_TRACE(("LEX: %s [TOK_ISA]\n", yytext));
98 return TOK_ISA;
99 }
100
|
101 karl 1.8 "\." {
102 WQL_TRACE(("LEX: %s [TOK_DOT]\n", yytext));
103 return TOK_DOT;
104 }
105
106
|
107 karl 1.7
|
108 mike 1.2 [Tt][Rr][Uu][Ee] {
109
110 WQL_TRACE(("LEX: %s [TOK_TRUE]\n", yytext));
111 return TOK_TRUE;
112 }
113
114 [Ff][Aa][Ll][Ss][Ee] {
115
116 WQL_TRACE(("LEX: %s [TOK_FALSE]\n", yytext));
117 return TOK_FALSE;
118 }
119
120 [Nn][Uu][Ll][Ll] {
121
122 WQL_TRACE(("LEX: %s [TOK_NULL]\n", yytext));
123 return TOK_NULL;
124 }
125
126 [Nn][Oo][Tt] {
127
128 WQL_TRACE(("LEX: %s [TOK_NOT]\n", yytext));
129 mike 1.2 return TOK_NOT;
130 }
131
132 [Aa][Nn][Dd] {
133
134 WQL_TRACE(("LEX: %s [TOK_AND]\n", yytext));
135 return TOK_AND;
136 }
137
138 [Oo][Rr] {
139
140 WQL_TRACE(("LEX: %s [TOK_OR]\n", yytext));
141 return TOK_OR;
142 }
143
144 [Ii][Ss] {
145
146 WQL_TRACE(("LEX: %s [TOK_IS]\n", yytext));
147 return TOK_IS;
148 }
149
150 mike 1.2 [-+]?{POSITIVE_DECIMAL_DIGIT}{DECIMAL_DIGIT}* {
151
152 WQL_TRACE(("LEX: %s [TOK_INTEGER]\n", yytext));
153 WQL_lval.intValue = strtol(yytext, (char**)0, 10);
154 return TOK_INTEGER;
155 }
156
157 [+-]?0 {
158
159 WQL_TRACE(("LEX: %s [TOK_INTEGER]\n", yytext));
160 WQL_lval.intValue = 0;
161 return TOK_INTEGER;
162 }
163
164 [-+]?{DECIMAL_DIGIT}*\.{DECIMAL_DIGIT}+([eE][+-]?{DECIMAL_DIGIT}+)? {
165
166 WQL_TRACE(("LEX: %s [TOK_DOUBLE]\n", yytext));
167 WQL_lval.doubleValue = strtod((char*)yytext, (char**)0);
168 return TOK_DOUBLE;
169 }
170
171 mike 1.2 \"[^\"\n]*\" {
172
173 /* ATTN-B: handle long literals by using yyinput(). */
174 /* ATTN-B: Handle expansion of special characters */
175
176 WQL_TRACE(("LEX: %s [TOK_STRING]\n", yytext));
177
178 /* Copy the string (but remove the surrounding quotes */
179
180 {
|
181 karl 1.14 size_t n = strlen(yytext) - 2;
182 char* strValue = new char[n + 1];
183 memcpy(strValue, yytext + 1, n);
184 strValue[n] = '\0';
185 WQL_lval.strValue = strValue;
186 globalParserState->outstandingStrings.append(strValue);
|
187 mike 1.2 }
188
189 return TOK_STRING;
190 }
191
192 \"[^\"\n]*$ {
193
194 WQL_error("Unterminated string");
195 }
196
197 [\*(),] {
198
199 WQL_TRACE(("LEX: %c\n", yytext[0]));
200 return yytext[0];
201 }
202
203 "=" {
204 WQL_TRACE(("LEX: %s [TOK_EQ]\n", yytext));
205 return TOK_EQ;
206 }
207
208 mike 1.2 "!=" {
209
210 WQL_TRACE(("LEX: %s [TOK_NE]\n", yytext));
211 return TOK_NE;
212 }
213
214 "<=" {
215
216 WQL_TRACE(("LEX: %s [TOK_LE]\n", yytext));
217 return TOK_LE;
218 }
219
220 "<" {
221
222 WQL_TRACE(("LEX: %s [TOK_LT]\n", yytext));
223 return TOK_LT;
224 }
225
226 ">=" {
227
228 WQL_TRACE(("LEX: %s [TOK_GE]\n", yytext));
229 mike 1.2 return TOK_GE;
230 }
231
|
232 karl 1.6 "<>" {
233
234 WQL_TRACE(("LEX: %s [TOK_NE]\n", yytext));
235 return TOK_NE;
236 }
237
|
238 mike 1.2 ">" {
239
240 WQL_TRACE(("LEX: %s [TOK_GT]\n", yytext));
241 return TOK_GT;
242 }
243
244 {IDENT_CHAR}({IDENT_CHAR}|{DECIMAL_DIGIT})* {
245
246 WQL_TRACE(("LEX: %s [TOK_IDENTIFIER]\n", yytext));
247
248 {
|
249 karl 1.14 size_t n = strlen(yytext);
250 char* strValue = new char[n + 1];
251 memcpy(strValue, yytext, n);
252 strValue[n] = '\0';
253 WQL_lval.strValue = strValue;
254 globalParserState->outstandingStrings.append(strValue);
|
255 mike 1.2 }
256
257 return TOK_IDENTIFIER;
258 }
259
260 {BLANK}+ {
261
262 /* Ignore blanks */
263 }
264
265 . {
266 WQL_lval.intValue = 0;
267 return TOK_UNEXPECTED_CHAR;
268 }
269
270 %%
271
272 extern "C" int WQL_wrap()
273 {
274 return 1;
275 }
|