001: // $ANTLR 2.7.2: "ValidWhenParser.g" -> "ValidWhenLexer.java"$
002:
003: /*
004: * $Id: ValidWhenLexer.java 504715 2007-02-07 22:10:26Z bayard $
005: *
006: * Licensed to the Apache Software Foundation (ASF) under one
007: * or more contributor license agreements. See the NOTICE file
008: * distributed with this work for additional information
009: * regarding copyright ownership. The ASF licenses this file
010: * to you under the Apache License, Version 2.0 (the
011: * "License"); you may not use this file except in compliance
012: * with the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing,
017: * software distributed under the License is distributed on an
018: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019: * KIND, either express or implied. See the License for the
020: * specific language governing permissions and limitations
021: * under the License.
022: */
023:
024: package org.apache.struts.validator.validwhen;
025:
026: import java.util.Stack;
027: import org.apache.commons.validator.util.ValidatorUtils;
028:
029: import java.io.InputStream;
030: import antlr.TokenStreamException;
031: import antlr.TokenStreamIOException;
032: import antlr.TokenStreamRecognitionException;
033: import antlr.CharStreamException;
034: import antlr.CharStreamIOException;
035: import antlr.ANTLRException;
036: import java.io.Reader;
037: import java.util.Hashtable;
038: import antlr.CharScanner;
039: import antlr.InputBuffer;
040: import antlr.ByteBuffer;
041: import antlr.CharBuffer;
042: import antlr.Token;
043: import antlr.CommonToken;
044: import antlr.RecognitionException;
045: import antlr.NoViableAltForCharException;
046: import antlr.MismatchedCharException;
047: import antlr.TokenStream;
048: import antlr.ANTLRHashString;
049: import antlr.LexerSharedInputState;
050: import antlr.collections.impl.BitSet;
051: import antlr.SemanticException;
052:
053: public class ValidWhenLexer extends antlr.CharScanner implements
054: ValidWhenParserTokenTypes, TokenStream {
055: public ValidWhenLexer(InputStream in) {
056: this (new ByteBuffer(in));
057: }
058:
059: public ValidWhenLexer(Reader in) {
060: this (new CharBuffer(in));
061: }
062:
063: public ValidWhenLexer(InputBuffer ib) {
064: this (new LexerSharedInputState(ib));
065: }
066:
067: public ValidWhenLexer(LexerSharedInputState state) {
068: super (state);
069: caseSensitiveLiterals = true;
070: setCaseSensitive(false);
071: literals = new Hashtable();
072: literals
073: .put(new ANTLRHashString("null", this ), new Integer(11));
074: literals.put(new ANTLRHashString("or", this ), new Integer(16));
075: literals.put(new ANTLRHashString("and", this ), new Integer(15));
076: }
077:
078: public Token nextToken() throws TokenStreamException {
079: Token theRetToken = null;
080: tryAgain: for (;;) {
081: Token _token = null;
082: int _ttype = Token.INVALID_TYPE;
083: resetText();
084: try { // for char stream error handling
085: try { // for lexical error handling
086: switch (LA(1)) {
087: case '\t':
088: case '\n':
089: case '\r':
090: case ' ': {
091: mWS(true);
092: theRetToken = _returnToken;
093: break;
094: }
095: case '-':
096: case '1':
097: case '2':
098: case '3':
099: case '4':
100: case '5':
101: case '6':
102: case '7':
103: case '8':
104: case '9': {
105: mDECIMAL_LITERAL(true);
106: theRetToken = _returnToken;
107: break;
108: }
109: case '"':
110: case '\'': {
111: mSTRING_LITERAL(true);
112: theRetToken = _returnToken;
113: break;
114: }
115: case '[': {
116: mLBRACKET(true);
117: theRetToken = _returnToken;
118: break;
119: }
120: case ']': {
121: mRBRACKET(true);
122: theRetToken = _returnToken;
123: break;
124: }
125: case '(': {
126: mLPAREN(true);
127: theRetToken = _returnToken;
128: break;
129: }
130: case ')': {
131: mRPAREN(true);
132: theRetToken = _returnToken;
133: break;
134: }
135: case '*': {
136: mTHIS(true);
137: theRetToken = _returnToken;
138: break;
139: }
140: case '.':
141: case '_':
142: case 'a':
143: case 'b':
144: case 'c':
145: case 'd':
146: case 'e':
147: case 'f':
148: case 'g':
149: case 'h':
150: case 'i':
151: case 'j':
152: case 'k':
153: case 'l':
154: case 'm':
155: case 'n':
156: case 'o':
157: case 'p':
158: case 'q':
159: case 'r':
160: case 's':
161: case 't':
162: case 'u':
163: case 'v':
164: case 'w':
165: case 'x':
166: case 'y':
167: case 'z': {
168: mIDENTIFIER(true);
169: theRetToken = _returnToken;
170: break;
171: }
172: case '=': {
173: mEQUALSIGN(true);
174: theRetToken = _returnToken;
175: break;
176: }
177: case '!': {
178: mNOTEQUALSIGN(true);
179: theRetToken = _returnToken;
180: break;
181: }
182: default:
183: if ((LA(1) == '0') && (LA(2) == 'x')) {
184: mHEX_LITERAL(true);
185: theRetToken = _returnToken;
186: } else if ((LA(1) == '<') && (LA(2) == '=')) {
187: mLESSEQUALSIGN(true);
188: theRetToken = _returnToken;
189: } else if ((LA(1) == '>') && (LA(2) == '=')) {
190: mGREATEREQUALSIGN(true);
191: theRetToken = _returnToken;
192: } else if ((LA(1) == '0') && (true)) {
193: mOCTAL_LITERAL(true);
194: theRetToken = _returnToken;
195: } else if ((LA(1) == '<') && (true)) {
196: mLESSTHANSIGN(true);
197: theRetToken = _returnToken;
198: } else if ((LA(1) == '>') && (true)) {
199: mGREATERTHANSIGN(true);
200: theRetToken = _returnToken;
201: } else {
202: if (LA(1) == EOF_CHAR) {
203: uponEOF();
204: _returnToken = makeToken(Token.EOF_TYPE);
205: } else {
206: throw new NoViableAltForCharException(
207: (char) LA(1), getFilename(),
208: getLine(), getColumn());
209: }
210: }
211: }
212: if (_returnToken == null)
213: continue tryAgain; // found SKIP token
214: _ttype = _returnToken.getType();
215: _ttype = testLiteralsTable(_ttype);
216: _returnToken.setType(_ttype);
217: return _returnToken;
218: } catch (RecognitionException e) {
219: throw new TokenStreamRecognitionException(e);
220: }
221: } catch (CharStreamException cse) {
222: if (cse instanceof CharStreamIOException) {
223: throw new TokenStreamIOException(
224: ((CharStreamIOException) cse).io);
225: } else {
226: throw new TokenStreamException(cse.getMessage());
227: }
228: }
229: }
230: }
231:
232: public final void mWS(boolean _createToken)
233: throws RecognitionException, CharStreamException,
234: TokenStreamException {
235: int _ttype;
236: Token _token = null;
237: int _begin = text.length();
238: _ttype = WS;
239: int _saveIndex;
240:
241: {
242: int _cnt15 = 0;
243: _loop15: do {
244: switch (LA(1)) {
245: case ' ': {
246: match(' ');
247: break;
248: }
249: case '\t': {
250: match('\t');
251: break;
252: }
253: case '\n': {
254: match('\n');
255: break;
256: }
257: case '\r': {
258: match('\r');
259: break;
260: }
261: default: {
262: if (_cnt15 >= 1) {
263: break _loop15;
264: } else {
265: throw new NoViableAltForCharException(
266: (char) LA(1), getFilename(), getLine(),
267: getColumn());
268: }
269: }
270: }
271: _cnt15++;
272: } while (true);
273: }
274: _ttype = Token.SKIP;
275: if (_createToken && _token == null && _ttype != Token.SKIP) {
276: _token = makeToken(_ttype);
277: _token.setText(new String(text.getBuffer(), _begin, text
278: .length()
279: - _begin));
280: }
281: _returnToken = _token;
282: }
283:
284: public final void mDECIMAL_LITERAL(boolean _createToken)
285: throws RecognitionException, CharStreamException,
286: TokenStreamException {
287: int _ttype;
288: Token _token = null;
289: int _begin = text.length();
290: _ttype = DECIMAL_LITERAL;
291: int _saveIndex;
292:
293: {
294: switch (LA(1)) {
295: case '-': {
296: match('-');
297: break;
298: }
299: case '1':
300: case '2':
301: case '3':
302: case '4':
303: case '5':
304: case '6':
305: case '7':
306: case '8':
307: case '9': {
308: break;
309: }
310: default: {
311: throw new NoViableAltForCharException((char) LA(1),
312: getFilename(), getLine(), getColumn());
313: }
314: }
315: }
316: {
317: matchRange('1', '9');
318: }
319: {
320: _loop20: do {
321: if (((LA(1) >= '0' && LA(1) <= '9'))) {
322: matchRange('0', '9');
323: } else {
324: break _loop20;
325: }
326:
327: } while (true);
328: }
329: if (_createToken && _token == null && _ttype != Token.SKIP) {
330: _token = makeToken(_ttype);
331: _token.setText(new String(text.getBuffer(), _begin, text
332: .length()
333: - _begin));
334: }
335: _returnToken = _token;
336: }
337:
338: public final void mHEX_LITERAL(boolean _createToken)
339: throws RecognitionException, CharStreamException,
340: TokenStreamException {
341: int _ttype;
342: Token _token = null;
343: int _begin = text.length();
344: _ttype = HEX_LITERAL;
345: int _saveIndex;
346:
347: match('0');
348: match('x');
349: {
350: int _cnt23 = 0;
351: _loop23: do {
352: switch (LA(1)) {
353: case '0':
354: case '1':
355: case '2':
356: case '3':
357: case '4':
358: case '5':
359: case '6':
360: case '7':
361: case '8':
362: case '9': {
363: matchRange('0', '9');
364: break;
365: }
366: case 'a':
367: case 'b':
368: case 'c':
369: case 'd':
370: case 'e':
371: case 'f': {
372: matchRange('a', 'f');
373: break;
374: }
375: default: {
376: if (_cnt23 >= 1) {
377: break _loop23;
378: } else {
379: throw new NoViableAltForCharException(
380: (char) LA(1), getFilename(), getLine(),
381: getColumn());
382: }
383: }
384: }
385: _cnt23++;
386: } while (true);
387: }
388: if (_createToken && _token == null && _ttype != Token.SKIP) {
389: _token = makeToken(_ttype);
390: _token.setText(new String(text.getBuffer(), _begin, text
391: .length()
392: - _begin));
393: }
394: _returnToken = _token;
395: }
396:
397: public final void mOCTAL_LITERAL(boolean _createToken)
398: throws RecognitionException, CharStreamException,
399: TokenStreamException {
400: int _ttype;
401: Token _token = null;
402: int _begin = text.length();
403: _ttype = OCTAL_LITERAL;
404: int _saveIndex;
405:
406: match('0');
407: {
408: _loop26: do {
409: if (((LA(1) >= '0' && LA(1) <= '7'))) {
410: matchRange('0', '7');
411: } else {
412: break _loop26;
413: }
414:
415: } while (true);
416: }
417: if (_createToken && _token == null && _ttype != Token.SKIP) {
418: _token = makeToken(_ttype);
419: _token.setText(new String(text.getBuffer(), _begin, text
420: .length()
421: - _begin));
422: }
423: _returnToken = _token;
424: }
425:
426: public final void mSTRING_LITERAL(boolean _createToken)
427: throws RecognitionException, CharStreamException,
428: TokenStreamException {
429: int _ttype;
430: Token _token = null;
431: int _begin = text.length();
432: _ttype = STRING_LITERAL;
433: int _saveIndex;
434:
435: switch (LA(1)) {
436: case '\'': {
437: {
438: match('\'');
439: {
440: int _cnt30 = 0;
441: _loop30: do {
442: if ((_tokenSet_0.member(LA(1)))) {
443: matchNot('\'');
444: } else {
445: if (_cnt30 >= 1) {
446: break _loop30;
447: } else {
448: throw new NoViableAltForCharException(
449: (char) LA(1), getFilename(),
450: getLine(), getColumn());
451: }
452: }
453:
454: _cnt30++;
455: } while (true);
456: }
457: match('\'');
458: }
459: break;
460: }
461: case '"': {
462: {
463: match('\"');
464: {
465: int _cnt33 = 0;
466: _loop33: do {
467: if ((_tokenSet_1.member(LA(1)))) {
468: matchNot('\"');
469: } else {
470: if (_cnt33 >= 1) {
471: break _loop33;
472: } else {
473: throw new NoViableAltForCharException(
474: (char) LA(1), getFilename(),
475: getLine(), getColumn());
476: }
477: }
478:
479: _cnt33++;
480: } while (true);
481: }
482: match('\"');
483: }
484: break;
485: }
486: default: {
487: throw new NoViableAltForCharException((char) LA(1),
488: getFilename(), getLine(), getColumn());
489: }
490: }
491: if (_createToken && _token == null && _ttype != Token.SKIP) {
492: _token = makeToken(_ttype);
493: _token.setText(new String(text.getBuffer(), _begin, text
494: .length()
495: - _begin));
496: }
497: _returnToken = _token;
498: }
499:
500: public final void mLBRACKET(boolean _createToken)
501: throws RecognitionException, CharStreamException,
502: TokenStreamException {
503: int _ttype;
504: Token _token = null;
505: int _begin = text.length();
506: _ttype = LBRACKET;
507: int _saveIndex;
508:
509: match('[');
510: if (_createToken && _token == null && _ttype != Token.SKIP) {
511: _token = makeToken(_ttype);
512: _token.setText(new String(text.getBuffer(), _begin, text
513: .length()
514: - _begin));
515: }
516: _returnToken = _token;
517: }
518:
519: public final void mRBRACKET(boolean _createToken)
520: throws RecognitionException, CharStreamException,
521: TokenStreamException {
522: int _ttype;
523: Token _token = null;
524: int _begin = text.length();
525: _ttype = RBRACKET;
526: int _saveIndex;
527:
528: match(']');
529: if (_createToken && _token == null && _ttype != Token.SKIP) {
530: _token = makeToken(_ttype);
531: _token.setText(new String(text.getBuffer(), _begin, text
532: .length()
533: - _begin));
534: }
535: _returnToken = _token;
536: }
537:
538: public final void mLPAREN(boolean _createToken)
539: throws RecognitionException, CharStreamException,
540: TokenStreamException {
541: int _ttype;
542: Token _token = null;
543: int _begin = text.length();
544: _ttype = LPAREN;
545: int _saveIndex;
546:
547: match('(');
548: if (_createToken && _token == null && _ttype != Token.SKIP) {
549: _token = makeToken(_ttype);
550: _token.setText(new String(text.getBuffer(), _begin, text
551: .length()
552: - _begin));
553: }
554: _returnToken = _token;
555: }
556:
557: public final void mRPAREN(boolean _createToken)
558: throws RecognitionException, CharStreamException,
559: TokenStreamException {
560: int _ttype;
561: Token _token = null;
562: int _begin = text.length();
563: _ttype = RPAREN;
564: int _saveIndex;
565:
566: match(')');
567: if (_createToken && _token == null && _ttype != Token.SKIP) {
568: _token = makeToken(_ttype);
569: _token.setText(new String(text.getBuffer(), _begin, text
570: .length()
571: - _begin));
572: }
573: _returnToken = _token;
574: }
575:
576: public final void mTHIS(boolean _createToken)
577: throws RecognitionException, CharStreamException,
578: TokenStreamException {
579: int _ttype;
580: Token _token = null;
581: int _begin = text.length();
582: _ttype = THIS;
583: int _saveIndex;
584:
585: match("*this*");
586: if (_createToken && _token == null && _ttype != Token.SKIP) {
587: _token = makeToken(_ttype);
588: _token.setText(new String(text.getBuffer(), _begin, text
589: .length()
590: - _begin));
591: }
592: _returnToken = _token;
593: }
594:
595: public final void mIDENTIFIER(boolean _createToken)
596: throws RecognitionException, CharStreamException,
597: TokenStreamException {
598: int _ttype;
599: Token _token = null;
600: int _begin = text.length();
601: _ttype = IDENTIFIER;
602: int _saveIndex;
603:
604: {
605: switch (LA(1)) {
606: case 'a':
607: case 'b':
608: case 'c':
609: case 'd':
610: case 'e':
611: case 'f':
612: case 'g':
613: case 'h':
614: case 'i':
615: case 'j':
616: case 'k':
617: case 'l':
618: case 'm':
619: case 'n':
620: case 'o':
621: case 'p':
622: case 'q':
623: case 'r':
624: case 's':
625: case 't':
626: case 'u':
627: case 'v':
628: case 'w':
629: case 'x':
630: case 'y':
631: case 'z': {
632: matchRange('a', 'z');
633: break;
634: }
635: case '.': {
636: match('.');
637: break;
638: }
639: case '_': {
640: match('_');
641: break;
642: }
643: default: {
644: throw new NoViableAltForCharException((char) LA(1),
645: getFilename(), getLine(), getColumn());
646: }
647: }
648: }
649: {
650: int _cnt42 = 0;
651: _loop42: do {
652: switch (LA(1)) {
653: case 'a':
654: case 'b':
655: case 'c':
656: case 'd':
657: case 'e':
658: case 'f':
659: case 'g':
660: case 'h':
661: case 'i':
662: case 'j':
663: case 'k':
664: case 'l':
665: case 'm':
666: case 'n':
667: case 'o':
668: case 'p':
669: case 'q':
670: case 'r':
671: case 's':
672: case 't':
673: case 'u':
674: case 'v':
675: case 'w':
676: case 'x':
677: case 'y':
678: case 'z': {
679: matchRange('a', 'z');
680: break;
681: }
682: case '0':
683: case '1':
684: case '2':
685: case '3':
686: case '4':
687: case '5':
688: case '6':
689: case '7':
690: case '8':
691: case '9': {
692: matchRange('0', '9');
693: break;
694: }
695: case '.': {
696: match('.');
697: break;
698: }
699: case '_': {
700: match('_');
701: break;
702: }
703: default: {
704: if (_cnt42 >= 1) {
705: break _loop42;
706: } else {
707: throw new NoViableAltForCharException(
708: (char) LA(1), getFilename(), getLine(),
709: getColumn());
710: }
711: }
712: }
713: _cnt42++;
714: } while (true);
715: }
716: if (_createToken && _token == null && _ttype != Token.SKIP) {
717: _token = makeToken(_ttype);
718: _token.setText(new String(text.getBuffer(), _begin, text
719: .length()
720: - _begin));
721: }
722: _returnToken = _token;
723: }
724:
725: public final void mEQUALSIGN(boolean _createToken)
726: throws RecognitionException, CharStreamException,
727: TokenStreamException {
728: int _ttype;
729: Token _token = null;
730: int _begin = text.length();
731: _ttype = EQUALSIGN;
732: int _saveIndex;
733:
734: match('=');
735: match('=');
736: if (_createToken && _token == null && _ttype != Token.SKIP) {
737: _token = makeToken(_ttype);
738: _token.setText(new String(text.getBuffer(), _begin, text
739: .length()
740: - _begin));
741: }
742: _returnToken = _token;
743: }
744:
745: public final void mNOTEQUALSIGN(boolean _createToken)
746: throws RecognitionException, CharStreamException,
747: TokenStreamException {
748: int _ttype;
749: Token _token = null;
750: int _begin = text.length();
751: _ttype = NOTEQUALSIGN;
752: int _saveIndex;
753:
754: match('!');
755: match('=');
756: if (_createToken && _token == null && _ttype != Token.SKIP) {
757: _token = makeToken(_ttype);
758: _token.setText(new String(text.getBuffer(), _begin, text
759: .length()
760: - _begin));
761: }
762: _returnToken = _token;
763: }
764:
765: public final void mLESSTHANSIGN(boolean _createToken)
766: throws RecognitionException, CharStreamException,
767: TokenStreamException {
768: int _ttype;
769: Token _token = null;
770: int _begin = text.length();
771: _ttype = LESSTHANSIGN;
772: int _saveIndex;
773:
774: match('<');
775: if (_createToken && _token == null && _ttype != Token.SKIP) {
776: _token = makeToken(_ttype);
777: _token.setText(new String(text.getBuffer(), _begin, text
778: .length()
779: - _begin));
780: }
781: _returnToken = _token;
782: }
783:
784: public final void mGREATERTHANSIGN(boolean _createToken)
785: throws RecognitionException, CharStreamException,
786: TokenStreamException {
787: int _ttype;
788: Token _token = null;
789: int _begin = text.length();
790: _ttype = GREATERTHANSIGN;
791: int _saveIndex;
792:
793: match('>');
794: if (_createToken && _token == null && _ttype != Token.SKIP) {
795: _token = makeToken(_ttype);
796: _token.setText(new String(text.getBuffer(), _begin, text
797: .length()
798: - _begin));
799: }
800: _returnToken = _token;
801: }
802:
803: public final void mLESSEQUALSIGN(boolean _createToken)
804: throws RecognitionException, CharStreamException,
805: TokenStreamException {
806: int _ttype;
807: Token _token = null;
808: int _begin = text.length();
809: _ttype = LESSEQUALSIGN;
810: int _saveIndex;
811:
812: match('<');
813: match('=');
814: if (_createToken && _token == null && _ttype != Token.SKIP) {
815: _token = makeToken(_ttype);
816: _token.setText(new String(text.getBuffer(), _begin, text
817: .length()
818: - _begin));
819: }
820: _returnToken = _token;
821: }
822:
823: public final void mGREATEREQUALSIGN(boolean _createToken)
824: throws RecognitionException, CharStreamException,
825: TokenStreamException {
826: int _ttype;
827: Token _token = null;
828: int _begin = text.length();
829: _ttype = GREATEREQUALSIGN;
830: int _saveIndex;
831:
832: match('>');
833: match('=');
834: if (_createToken && _token == null && _ttype != Token.SKIP) {
835: _token = makeToken(_ttype);
836: _token.setText(new String(text.getBuffer(), _begin, text
837: .length()
838: - _begin));
839: }
840: _returnToken = _token;
841: }
842:
843: private static final long[] mk_tokenSet_0() {
844: long[] data = { -554050771456L, 9223372036854775807L, 0L, 0L };
845: return data;
846: }
847:
848: public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
849:
850: private static final long[] mk_tokenSet_1() {
851: long[] data = { -21474826752L, 9223372036854775807L, 0L, 0L };
852: return data;
853: }
854:
855: public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
856:
857: }
|