1 | // $ANTLR 2.7.6 (2005-12-22): "constraint.g" -> "ConstraintLexer.java"$ |
2 | |
3 | package net.sourceforge.hiveevents; |
4 | |
5 | import java.util.HashMap; |
6 | import java.util.Map; |
7 | |
8 | import net.sourceforge.hiveutils.util.PropertyPathUtils; |
9 | |
10 | import java.io.InputStream; |
11 | import antlr.TokenStreamException; |
12 | import antlr.TokenStreamIOException; |
13 | import antlr.TokenStreamRecognitionException; |
14 | import antlr.CharStreamException; |
15 | import antlr.CharStreamIOException; |
16 | import antlr.ANTLRException; |
17 | import java.io.Reader; |
18 | import java.util.Hashtable; |
19 | import antlr.CharScanner; |
20 | import antlr.InputBuffer; |
21 | import antlr.ByteBuffer; |
22 | import antlr.CharBuffer; |
23 | import antlr.Token; |
24 | import antlr.CommonToken; |
25 | import antlr.RecognitionException; |
26 | import antlr.NoViableAltForCharException; |
27 | import antlr.MismatchedCharException; |
28 | import antlr.TokenStream; |
29 | import antlr.ANTLRHashString; |
30 | import antlr.LexerSharedInputState; |
31 | import antlr.collections.impl.BitSet; |
32 | import antlr.SemanticException; |
33 | |
34 | public class ConstraintLexer extends antlr.CharScanner implements ConstraintParserTokenTypes, TokenStream |
35 | { |
36 | |
37 | private final Map<String, Class> _variables = new HashMap<String, Class>(); |
38 | |
39 | public void initVariables(Map<String, Class> classes) |
40 | { |
41 | _variables.putAll(classes); |
42 | _variables.put("null", Comparable.class); |
43 | } |
44 | |
45 | public void initVariable(String name, Class clazz) |
46 | { |
47 | _variables.put(name, clazz); |
48 | } |
49 | |
50 | private Class getPropertyType(String name) |
51 | { |
52 | int index = name.indexOf('.'); |
53 | if (index < 0) |
54 | return _variables.get(name); |
55 | |
56 | return PropertyPathUtils.getType( _variables.get(name.substring(0, index)), |
57 | name.substring(index + 1)); |
58 | } |
59 | public ConstraintLexer(InputStream in) { |
60 | this(new ByteBuffer(in)); |
61 | } |
62 | public ConstraintLexer(Reader in) { |
63 | this(new CharBuffer(in)); |
64 | } |
65 | public ConstraintLexer(InputBuffer ib) { |
66 | this(new LexerSharedInputState(ib)); |
67 | } |
68 | public ConstraintLexer(LexerSharedInputState state) { |
69 | super(state); |
70 | caseSensitiveLiterals = true; |
71 | setCaseSensitive(true); |
72 | literals = new Hashtable(); |
73 | } |
74 | |
75 | public Token nextToken() throws TokenStreamException { |
76 | Token theRetToken=null; |
77 | tryAgain: |
78 | for (;;) { |
79 | Token _token = null; |
80 | int _ttype = Token.INVALID_TYPE; |
81 | resetText(); |
82 | try { // for char stream error handling |
83 | try { // for lexical error handling |
84 | switch ( LA(1)) { |
85 | case '\t': case ' ': |
86 | { |
87 | mWS(true); |
88 | theRetToken=_returnToken; |
89 | break; |
90 | } |
91 | case '|': |
92 | { |
93 | mOR(true); |
94 | theRetToken=_returnToken; |
95 | break; |
96 | } |
97 | case '&': |
98 | { |
99 | mAND(true); |
100 | theRetToken=_returnToken; |
101 | break; |
102 | } |
103 | case '=': |
104 | { |
105 | mEQ(true); |
106 | theRetToken=_returnToken; |
107 | break; |
108 | } |
109 | case '!': |
110 | { |
111 | mNE(true); |
112 | theRetToken=_returnToken; |
113 | break; |
114 | } |
115 | case '.': |
116 | { |
117 | mDOT(true); |
118 | theRetToken=_returnToken; |
119 | break; |
120 | } |
121 | case '(': |
122 | { |
123 | mLPAREN(true); |
124 | theRetToken=_returnToken; |
125 | break; |
126 | } |
127 | case ')': |
128 | { |
129 | mRPAREN(true); |
130 | theRetToken=_returnToken; |
131 | break; |
132 | } |
133 | case 'A': case 'B': case 'C': case 'D': |
134 | case 'E': case 'F': case 'G': case 'H': |
135 | case 'I': case 'J': case 'K': case 'L': |
136 | case 'M': case 'N': case 'O': case 'P': |
137 | case 'Q': case 'R': case 'S': case 'T': |
138 | case 'U': case 'V': case 'W': case 'X': |
139 | case 'Y': case 'Z': case '_': case 'a': |
140 | case 'b': case 'c': case 'd': case 'e': |
141 | case 'f': case 'g': case 'h': case 'i': |
142 | case 'j': case 'k': case 'l': case 'm': |
143 | case 'n': case 'o': case 'p': case 'q': |
144 | case 'r': case 's': case 't': case 'u': |
145 | case 'v': case 'w': case 'x': case 'y': |
146 | case 'z': |
147 | { |
148 | mPROPERTY(true); |
149 | theRetToken=_returnToken; |
150 | break; |
151 | } |
152 | case '+': case '-': case '0': case '1': |
153 | case '2': case '3': case '4': case '5': |
154 | case '6': case '7': case '8': case '9': |
155 | { |
156 | mNUM_LITERAL(true); |
157 | theRetToken=_returnToken; |
158 | break; |
159 | } |
160 | case '\'': |
161 | { |
162 | mSTR_LITERAL(true); |
163 | theRetToken=_returnToken; |
164 | break; |
165 | } |
166 | default: |
167 | if ((LA(1)=='<') && (LA(2)=='=')) { |
168 | mLE(true); |
169 | theRetToken=_returnToken; |
170 | } |
171 | else if ((LA(1)=='>') && (LA(2)=='=')) { |
172 | mGE(true); |
173 | theRetToken=_returnToken; |
174 | } |
175 | else if ((LA(1)=='<') && (true)) { |
176 | mLT(true); |
177 | theRetToken=_returnToken; |
178 | } |
179 | else if ((LA(1)=='>') && (true)) { |
180 | mGT(true); |
181 | theRetToken=_returnToken; |
182 | } |
183 | else { |
184 | if (LA(1)==EOF_CHAR) {uponEOF(); _returnToken = makeToken(Token.EOF_TYPE);} |
185 | else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());} |
186 | } |
187 | } |
188 | if ( _returnToken==null ) continue tryAgain; // found SKIP token |
189 | _ttype = _returnToken.getType(); |
190 | _ttype = testLiteralsTable(_ttype); |
191 | _returnToken.setType(_ttype); |
192 | return _returnToken; |
193 | } |
194 | catch (RecognitionException e) { |
195 | throw new TokenStreamRecognitionException(e); |
196 | } |
197 | } |
198 | catch (CharStreamException cse) { |
199 | if ( cse instanceof CharStreamIOException ) { |
200 | throw new TokenStreamIOException(((CharStreamIOException)cse).io); |
201 | } |
202 | else { |
203 | throw new TokenStreamException(cse.getMessage()); |
204 | } |
205 | } |
206 | } |
207 | } |
208 | |
209 | public final void mWS(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
210 | int _ttype; Token _token=null; int _begin=text.length(); |
211 | _ttype = WS; |
212 | int _saveIndex; |
213 | |
214 | { |
215 | switch ( LA(1)) { |
216 | case ' ': |
217 | { |
218 | match(' '); |
219 | break; |
220 | } |
221 | case '\t': |
222 | { |
223 | match('\t'); |
224 | break; |
225 | } |
226 | default: |
227 | { |
228 | throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn()); |
229 | } |
230 | } |
231 | } |
232 | _ttype = Token.SKIP; |
233 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
234 | _token = makeToken(_ttype); |
235 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
236 | } |
237 | _returnToken = _token; |
238 | } |
239 | |
240 | public final void mOR(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
241 | int _ttype; Token _token=null; int _begin=text.length(); |
242 | _ttype = OR; |
243 | int _saveIndex; |
244 | |
245 | match("||"); |
246 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
247 | _token = makeToken(_ttype); |
248 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
249 | } |
250 | _returnToken = _token; |
251 | } |
252 | |
253 | public final void mAND(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
254 | int _ttype; Token _token=null; int _begin=text.length(); |
255 | _ttype = AND; |
256 | int _saveIndex; |
257 | |
258 | match("&&"); |
259 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
260 | _token = makeToken(_ttype); |
261 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
262 | } |
263 | _returnToken = _token; |
264 | } |
265 | |
266 | public final void mLT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
267 | int _ttype; Token _token=null; int _begin=text.length(); |
268 | _ttype = LT; |
269 | int _saveIndex; |
270 | |
271 | match("<"); |
272 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
273 | _token = makeToken(_ttype); |
274 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
275 | } |
276 | _returnToken = _token; |
277 | } |
278 | |
279 | public final void mLE(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
280 | int _ttype; Token _token=null; int _begin=text.length(); |
281 | _ttype = LE; |
282 | int _saveIndex; |
283 | |
284 | match("<="); |
285 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
286 | _token = makeToken(_ttype); |
287 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
288 | } |
289 | _returnToken = _token; |
290 | } |
291 | |
292 | public final void mGT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
293 | int _ttype; Token _token=null; int _begin=text.length(); |
294 | _ttype = GT; |
295 | int _saveIndex; |
296 | |
297 | match(">"); |
298 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
299 | _token = makeToken(_ttype); |
300 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
301 | } |
302 | _returnToken = _token; |
303 | } |
304 | |
305 | public final void mGE(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
306 | int _ttype; Token _token=null; int _begin=text.length(); |
307 | _ttype = GE; |
308 | int _saveIndex; |
309 | |
310 | match(">="); |
311 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
312 | _token = makeToken(_ttype); |
313 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
314 | } |
315 | _returnToken = _token; |
316 | } |
317 | |
318 | public final void mEQ(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
319 | int _ttype; Token _token=null; int _begin=text.length(); |
320 | _ttype = EQ; |
321 | int _saveIndex; |
322 | |
323 | match("=="); |
324 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
325 | _token = makeToken(_ttype); |
326 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
327 | } |
328 | _returnToken = _token; |
329 | } |
330 | |
331 | public final void mNE(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
332 | int _ttype; Token _token=null; int _begin=text.length(); |
333 | _ttype = NE; |
334 | int _saveIndex; |
335 | |
336 | match("!="); |
337 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
338 | _token = makeToken(_ttype); |
339 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
340 | } |
341 | _returnToken = _token; |
342 | } |
343 | |
344 | public final void mDOT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
345 | int _ttype; Token _token=null; int _begin=text.length(); |
346 | _ttype = DOT; |
347 | int _saveIndex; |
348 | |
349 | match("."); |
350 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
351 | _token = makeToken(_ttype); |
352 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
353 | } |
354 | _returnToken = _token; |
355 | } |
356 | |
357 | public final void mLPAREN(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
358 | int _ttype; Token _token=null; int _begin=text.length(); |
359 | _ttype = LPAREN; |
360 | int _saveIndex; |
361 | |
362 | match('('); |
363 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
364 | _token = makeToken(_ttype); |
365 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
366 | } |
367 | _returnToken = _token; |
368 | } |
369 | |
370 | public final void mRPAREN(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
371 | int _ttype; Token _token=null; int _begin=text.length(); |
372 | _ttype = RPAREN; |
373 | int _saveIndex; |
374 | |
375 | match(')'); |
376 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
377 | _token = makeToken(_ttype); |
378 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
379 | } |
380 | _returnToken = _token; |
381 | } |
382 | |
383 | protected final void mID(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
384 | int _ttype; Token _token=null; int _begin=text.length(); |
385 | _ttype = ID; |
386 | int _saveIndex; |
387 | |
388 | { |
389 | switch ( LA(1)) { |
390 | case 'a': case 'b': case 'c': case 'd': |
391 | case 'e': case 'f': case 'g': case 'h': |
392 | case 'i': case 'j': case 'k': case 'l': |
393 | case 'm': case 'n': case 'o': case 'p': |
394 | case 'q': case 'r': case 's': case 't': |
395 | case 'u': case 'v': case 'w': case 'x': |
396 | case 'y': case 'z': |
397 | { |
398 | matchRange('a','z'); |
399 | break; |
400 | } |
401 | case 'A': case 'B': case 'C': case 'D': |
402 | case 'E': case 'F': case 'G': case 'H': |
403 | case 'I': case 'J': case 'K': case 'L': |
404 | case 'M': case 'N': case 'O': case 'P': |
405 | case 'Q': case 'R': case 'S': case 'T': |
406 | case 'U': case 'V': case 'W': case 'X': |
407 | case 'Y': case 'Z': |
408 | { |
409 | matchRange('A','Z'); |
410 | break; |
411 | } |
412 | case '_': |
413 | { |
414 | match('_'); |
415 | break; |
416 | } |
417 | default: |
418 | { |
419 | throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn()); |
420 | } |
421 | } |
422 | } |
423 | { |
424 | _loop26: |
425 | do { |
426 | switch ( LA(1)) { |
427 | case 'a': case 'b': case 'c': case 'd': |
428 | case 'e': case 'f': case 'g': case 'h': |
429 | case 'i': case 'j': case 'k': case 'l': |
430 | case 'm': case 'n': case 'o': case 'p': |
431 | case 'q': case 'r': case 's': case 't': |
432 | case 'u': case 'v': case 'w': case 'x': |
433 | case 'y': case 'z': |
434 | { |
435 | matchRange('a','z'); |
436 | break; |
437 | } |
438 | case 'A': case 'B': case 'C': case 'D': |
439 | case 'E': case 'F': case 'G': case 'H': |
440 | case 'I': case 'J': case 'K': case 'L': |
441 | case 'M': case 'N': case 'O': case 'P': |
442 | case 'Q': case 'R': case 'S': case 'T': |
443 | case 'U': case 'V': case 'W': case 'X': |
444 | case 'Y': case 'Z': |
445 | { |
446 | matchRange('A','Z'); |
447 | break; |
448 | } |
449 | case '_': |
450 | { |
451 | match('_'); |
452 | break; |
453 | } |
454 | case '0': case '1': case '2': case '3': |
455 | case '4': case '5': case '6': case '7': |
456 | case '8': case '9': |
457 | { |
458 | matchRange('0','9'); |
459 | break; |
460 | } |
461 | default: |
462 | { |
463 | break _loop26; |
464 | } |
465 | } |
466 | } while (true); |
467 | } |
468 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
469 | _token = makeToken(_ttype); |
470 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
471 | } |
472 | _returnToken = _token; |
473 | } |
474 | |
475 | public final void mPROPERTY(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
476 | int _ttype; Token _token=null; int _begin=text.length(); |
477 | _ttype = PROPERTY; |
478 | int _saveIndex; |
479 | |
480 | mID(false); |
481 | { |
482 | _loop29: |
483 | do { |
484 | if ((LA(1)=='.')) { |
485 | mDOT(false); |
486 | mID(false); |
487 | } |
488 | else { |
489 | break _loop29; |
490 | } |
491 | |
492 | } while (true); |
493 | } |
494 | |
495 | Class type = getPropertyType(new String(text.getBuffer(),_begin,text.length()-_begin)); |
496 | if (type == boolean.class || type == Boolean.class) |
497 | { |
498 | _ttype = BOOL_PROPERTY; |
499 | } |
500 | else if ( type.isPrimitive() |
501 | || Comparable.class.isAssignableFrom(type)) |
502 | { |
503 | _ttype = PROPERTY; |
504 | } |
505 | else |
506 | { |
507 | throw new SemanticException(new String(text.getBuffer(),_begin,text.length()-_begin) + " property has unexpected type " + type, |
508 | getFilename(), |
509 | getLine(), |
510 | getColumn()); |
511 | } |
512 | |
513 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
514 | _token = makeToken(_ttype); |
515 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
516 | } |
517 | _returnToken = _token; |
518 | } |
519 | |
520 | public final void mNUM_LITERAL(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
521 | int _ttype; Token _token=null; int _begin=text.length(); |
522 | _ttype = NUM_LITERAL; |
523 | int _saveIndex; |
524 | |
525 | switch ( LA(1)) { |
526 | case '0': case '1': case '2': case '3': |
527 | case '4': case '5': case '6': case '7': |
528 | case '8': case '9': |
529 | { |
530 | { |
531 | int _cnt32=0; |
532 | _loop32: |
533 | do { |
534 | if (((LA(1) >= '0' && LA(1) <= '9'))) { |
535 | matchRange('0','9'); |
536 | } |
537 | else { |
538 | if ( _cnt32>=1 ) { break _loop32; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());} |
539 | } |
540 | |
541 | _cnt32++; |
542 | } while (true); |
543 | } |
544 | break; |
545 | } |
546 | case '+': |
547 | { |
548 | match('+'); |
549 | { |
550 | int _cnt34=0; |
551 | _loop34: |
552 | do { |
553 | if (((LA(1) >= '0' && LA(1) <= '9'))) { |
554 | matchRange('0','9'); |
555 | } |
556 | else { |
557 | if ( _cnt34>=1 ) { break _loop34; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());} |
558 | } |
559 | |
560 | _cnt34++; |
561 | } while (true); |
562 | } |
563 | break; |
564 | } |
565 | case '-': |
566 | { |
567 | match('-'); |
568 | { |
569 | int _cnt36=0; |
570 | _loop36: |
571 | do { |
572 | if (((LA(1) >= '0' && LA(1) <= '9'))) { |
573 | matchRange('0','9'); |
574 | } |
575 | else { |
576 | if ( _cnt36>=1 ) { break _loop36; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());} |
577 | } |
578 | |
579 | _cnt36++; |
580 | } while (true); |
581 | } |
582 | break; |
583 | } |
584 | default: |
585 | { |
586 | throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn()); |
587 | } |
588 | } |
589 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
590 | _token = makeToken(_ttype); |
591 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
592 | } |
593 | _returnToken = _token; |
594 | } |
595 | |
596 | public final void mSTR_LITERAL(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { |
597 | int _ttype; Token _token=null; int _begin=text.length(); |
598 | _ttype = STR_LITERAL; |
599 | int _saveIndex; |
600 | |
601 | match('\''); |
602 | { |
603 | _loop39: |
604 | do { |
605 | if ((_tokenSet_0.member(LA(1)))) { |
606 | matchNot('\''); |
607 | } |
608 | else { |
609 | break _loop39; |
610 | } |
611 | |
612 | } while (true); |
613 | } |
614 | match('\''); |
615 | if ( _createToken && _token==null && _ttype!=Token.SKIP ) { |
616 | _token = makeToken(_ttype); |
617 | _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); |
618 | } |
619 | _returnToken = _token; |
620 | } |
621 | |
622 | |
623 | private static final long[] mk_tokenSet_0() { |
624 | long[] data = { -549755813889L, -1L, 0L, 0L}; |
625 | return data; |
626 | } |
627 | public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0()); |
628 | |
629 | } |