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