javalexer.java
来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· Java 代码 · 共 2,127 行 · 第 1/4 页
JAVA
2,127 行
// $ANTLR 2.7.2: "java.g" -> "JavaLexer.java"$package org.codehaus.groovy.antlr.java;import org.codehaus.groovy.antlr.*;import org.codehaus.groovy.antlr.parser.*;import java.util.*;import java.io.InputStream;import java.io.Reader;import antlr.InputBuffer;import antlr.LexerSharedInputState;import java.io.InputStream;import antlr.TokenStreamException;import antlr.TokenStreamIOException;import antlr.TokenStreamRecognitionException;import antlr.CharStreamException;import antlr.CharStreamIOException;import antlr.ANTLRException;import java.io.Reader;import java.util.Hashtable;import antlr.CharScanner;import antlr.InputBuffer;import antlr.ByteBuffer;import antlr.CharBuffer;import antlr.Token;import antlr.CommonToken;import antlr.RecognitionException;import antlr.NoViableAltForCharException;import antlr.MismatchedCharException;import antlr.TokenStream;import antlr.ANTLRHashString;import antlr.LexerSharedInputState;import antlr.collections.impl.BitSet;import antlr.SemanticException;public class JavaLexer extends antlr.CharScanner implements JavaTokenTypes, TokenStream { protected static final int SCS_TYPE = 3, SCS_VAL = 4, SCS_LIT = 8, SCS_LIMIT = 16; protected static final int SCS_SQ_TYPE = 0, SCS_TQ_TYPE = 1, SCS_RE_TYPE = 2; protected int stringCtorState = 0; // hack string and regexp constructor boundaries protected int lastSigTokenType = EOF; // last returned non-whitespace token /** flag for enabling the "assert" keyword */ private boolean assertEnabled = true; /** flag for enabling the "enum" keyword */ private boolean enumEnabled = true; /** flag for including whitespace tokens (for IDE preparsing) */ private boolean whitespaceIncluded = false; /** Enable the "assert" keyword */ public void enableAssert(boolean shouldEnable) { assertEnabled = shouldEnable; } /** Query the "assert" keyword state */ public boolean isAssertEnabled() { return assertEnabled; } /** Enable the "enum" keyword */ public void enableEnum(boolean shouldEnable) { enumEnabled = shouldEnable; } /** Query the "enum" keyword state */ public boolean isEnumEnabled() { return enumEnabled; } /** This is a bit of plumbing which resumes collection of string constructor bodies, * after an embedded expression has been parsed. * Usage: new JavaRecognizer(new JavaLexer(in).plumb()). */ public TokenStream plumb() { return new TokenStream() { public Token nextToken() throws TokenStreamException { if (stringCtorState >= SCS_LIT) { // This goo is modeled upon the ANTLR code for nextToken: int quoteType = (stringCtorState & SCS_TYPE); stringCtorState = 0; // get out of this mode, now resetText();/* try { switch (quoteType) { case SCS_SQ_TYPE://todo: suitable replacement??? mSTRING_CTOR_END(true, false, false); break; case SCS_TQ_TYPE:// mSTRING_CTOR_END(true, false, true); break; case SCS_RE_TYPE:// mREGEXP_CTOR_END(true, false); break; default: throw new AssertionError(false); } lastSigTokenType = _returnToken.getType(); return _returnToken; }*//* catch (RecognitionException e) { throw new TokenStreamRecognitionException(e); }*/ /*catch (CharStreamException cse) { if ( cse instanceof CharStreamIOException ) { throw new TokenStreamIOException(((CharStreamIOException)cse).io); } else { throw new TokenStreamException(cse.getMessage()); } }*/ } Token token = JavaLexer.this.nextToken(); int lasttype = token.getType(); if (whitespaceIncluded) { switch (lasttype) { // filter out insignificant types case WS: case SL_COMMENT: case ML_COMMENT: lasttype = lastSigTokenType; // back up! } } lastSigTokenType = lasttype; return token; } }; } protected JavaRecognizer parser; // little-used link; TODO: get rid ofpublic JavaLexer(InputStream in) { this(new ByteBuffer(in));}public JavaLexer(Reader in) { this(new CharBuffer(in));}public JavaLexer(InputBuffer ib) { this(new LexerSharedInputState(ib));}public JavaLexer(LexerSharedInputState state) { super(state); caseSensitiveLiterals = true; setCaseSensitive(true); literals = new Hashtable(); literals.put(new ANTLRHashString("byte", this), new Integer(79)); literals.put(new ANTLRHashString("public", this), new Integer(88)); literals.put(new ANTLRHashString("case", this), new Integer(121)); literals.put(new ANTLRHashString("short", this), new Integer(81)); literals.put(new ANTLRHashString("break", this), new Integer(114)); literals.put(new ANTLRHashString("while", this), new Integer(113)); literals.put(new ANTLRHashString("new", this), new Integer(157)); literals.put(new ANTLRHashString("instanceof", this), new Integer(144)); literals.put(new ANTLRHashString("implements", this), new Integer(106)); literals.put(new ANTLRHashString("synchronized", this), new Integer(93)); literals.put(new ANTLRHashString("float", this), new Integer(83)); literals.put(new ANTLRHashString("package", this), new Integer(61)); literals.put(new ANTLRHashString("return", this), new Integer(116)); literals.put(new ANTLRHashString("throw", this), new Integer(118)); literals.put(new ANTLRHashString("null", this), new Integer(156)); literals.put(new ANTLRHashString("threadsafe", this), new Integer(92)); literals.put(new ANTLRHashString("protected", this), new Integer(89)); literals.put(new ANTLRHashString("class", this), new Integer(101)); literals.put(new ANTLRHashString("throws", this), new Integer(108)); literals.put(new ANTLRHashString("strictfp", this), new Integer(40)); literals.put(new ANTLRHashString("super", this), new Integer(71)); literals.put(new ANTLRHashString("transient", this), new Integer(90)); literals.put(new ANTLRHashString("native", this), new Integer(91)); literals.put(new ANTLRHashString("interface", this), new Integer(102)); literals.put(new ANTLRHashString("final", this), new Integer(38)); literals.put(new ANTLRHashString("if", this), new Integer(111)); literals.put(new ANTLRHashString("double", this), new Integer(85)); literals.put(new ANTLRHashString("volatile", this), new Integer(94)); literals.put(new ANTLRHashString("assert", this), new Integer(119)); literals.put(new ANTLRHashString("catch", this), new Integer(124)); literals.put(new ANTLRHashString("try", this), new Integer(122)); literals.put(new ANTLRHashString("enum", this), new Integer(103)); literals.put(new ANTLRHashString("int", this), new Integer(82)); literals.put(new ANTLRHashString("for", this), new Integer(120)); literals.put(new ANTLRHashString("extends", this), new Integer(70)); literals.put(new ANTLRHashString("boolean", this), new Integer(78)); literals.put(new ANTLRHashString("char", this), new Integer(80)); literals.put(new ANTLRHashString("private", this), new Integer(87)); literals.put(new ANTLRHashString("default", this), new Integer(105)); literals.put(new ANTLRHashString("false", this), new Integer(155)); literals.put(new ANTLRHashString("this", this), new Integer(107)); literals.put(new ANTLRHashString("static", this), new Integer(64)); literals.put(new ANTLRHashString("abstract", this), new Integer(39)); literals.put(new ANTLRHashString("continue", this), new Integer(115)); literals.put(new ANTLRHashString("finally", this), new Integer(123)); literals.put(new ANTLRHashString("else", this), new Integer(112)); literals.put(new ANTLRHashString("import", this), new Integer(63)); literals.put(new ANTLRHashString("void", this), new Integer(77)); literals.put(new ANTLRHashString("switch", this), new Integer(117)); literals.put(new ANTLRHashString("true", this), new Integer(154)); literals.put(new ANTLRHashString("long", this), new Integer(84));}public Token nextToken() throws TokenStreamException { Token theRetToken=null;tryAgain: for (;;) { Token _token = null; int _ttype = Token.INVALID_TYPE; resetText(); try { // for char stream error handling try { // for lexical error handling switch ( LA(1)) { case '?': { mQUESTION(true); theRetToken=_returnToken; break; } case '(': { mLPAREN(true); theRetToken=_returnToken; break; } case ')': { mRPAREN(true); theRetToken=_returnToken; break; } case '[': { mLBRACK(true); theRetToken=_returnToken; break; } case ']': { mRBRACK(true); theRetToken=_returnToken; break; } case '{': { mLCURLY(true); theRetToken=_returnToken; break; } case '}': { mRCURLY(true); theRetToken=_returnToken; break; } case ':': { mCOLON(true); theRetToken=_returnToken; break; } case ',': { mCOMMA(true); theRetToken=_returnToken; break; } case '~': { mBNOT(true); theRetToken=_returnToken; break; } case ';': { mSEMI(true); theRetToken=_returnToken; break; } case '\t': case '\n': case '\u000c': case '\r': case ' ': { mWS(true); theRetToken=_returnToken; break; } case '"': case '\'': { mSTRING_LITERAL(true); theRetToken=_returnToken; break; } case '$': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': { mIDENT(true); theRetToken=_returnToken; break; } case '.': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { mNUM_INT(true); theRetToken=_returnToken; break; } case '@': { mAT(true); theRetToken=_returnToken; break; } default: if ((LA(1)=='>') && (LA(2)=='>') && (LA(3)=='>') && (LA(4)=='=')) { mBSR_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='>') && (LA(2)=='>') && (LA(3)=='=')) { mSR_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='>') && (LA(2)=='>') && (LA(3)=='>') && (true)) { mBSR(true); theRetToken=_returnToken; } else if ((LA(1)=='<') && (LA(2)=='<') && (LA(3)=='=')) { mSL_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='=') && (LA(2)=='=')) { mEQUAL(true); theRetToken=_returnToken; } else if ((LA(1)=='!') && (LA(2)=='=')) { mNOT_EQUAL(true); theRetToken=_returnToken; } else if ((LA(1)=='/') && (LA(2)=='=')) { mDIV_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='+') && (LA(2)=='=')) { mPLUS_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='+') && (LA(2)=='+')) { mINC(true); theRetToken=_returnToken; } else if ((LA(1)=='-') && (LA(2)=='=')) { mMINUS_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='-') && (LA(2)=='-')) { mDEC(true); theRetToken=_returnToken; } else if ((LA(1)=='*') && (LA(2)=='=')) { mSTAR_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='%') && (LA(2)=='=')) { mMOD_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='>') && (LA(2)=='>') && (true)) { mSR(true); theRetToken=_returnToken; } else if ((LA(1)=='>') && (LA(2)=='=')) { mGE(true); theRetToken=_returnToken; } else if ((LA(1)=='<') && (LA(2)=='<') && (true)) { mSL(true); theRetToken=_returnToken; } else if ((LA(1)=='<') && (LA(2)=='=')) { mLE(true); theRetToken=_returnToken; } else if ((LA(1)=='^') && (LA(2)=='=')) { mBXOR_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='|') && (LA(2)=='=')) { mBOR_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='|') && (LA(2)=='|')) { mLOR(true); theRetToken=_returnToken; } else if ((LA(1)=='&') && (LA(2)=='=')) { mBAND_ASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='&') && (LA(2)=='&')) { mLAND(true); theRetToken=_returnToken; } else if ((LA(1)=='/') && (LA(2)=='/')) { mSL_COMMENT(true); theRetToken=_returnToken; } else if ((LA(1)=='/') && (LA(2)=='*')) { mML_COMMENT(true); theRetToken=_returnToken; } else if ((LA(1)=='=') && (true)) { mASSIGN(true); theRetToken=_returnToken; } else if ((LA(1)=='!') && (true)) { mLNOT(true); theRetToken=_returnToken; } else if ((LA(1)=='/') && (true)) { mDIV(true); theRetToken=_returnToken; } else if ((LA(1)=='+') && (true)) { mPLUS(true); theRetToken=_returnToken; } else if ((LA(1)=='-') && (true)) { mMINUS(true); theRetToken=_returnToken; } else if ((LA(1)=='*') && (true)) { mSTAR(true); theRetToken=_returnToken; } else if ((LA(1)=='%') && (true)) { mMOD(true); theRetToken=_returnToken; } else if ((LA(1)=='>') && (true)) { mGT(true); theRetToken=_returnToken; } else if ((LA(1)=='<') && (true)) { mLT(true); theRetToken=_returnToken; } else if ((LA(1)=='^') && (true)) { mBXOR(true); theRetToken=_returnToken; } else if ((LA(1)=='|') && (true)) { mBOR(true); theRetToken=_returnToken; } else if ((LA(1)=='&') && (true)) { mBAND(true); theRetToken=_returnToken; } else { if (LA(1)==EOF_CHAR) {uponEOF(); _returnToken = makeToken(Token.EOF_TYPE);} else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());} } } if ( _returnToken==null ) continue tryAgain; // found SKIP token _ttype = _returnToken.getType(); _returnToken.setType(_ttype); return _returnToken; } catch (RecognitionException e) { throw new TokenStreamRecognitionException(e); } } catch (CharStreamException cse) { if ( cse instanceof CharStreamIOException ) { throw new TokenStreamIOException(((CharStreamIOException)cse).io); } else { throw new TokenStreamException(cse.getMessage()); } } }} public final void mQUESTION(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { int _ttype; Token _token=null; int _begin=text.length(); _ttype = QUESTION; int _saveIndex; match('?'); if ( _createToken && _token==null && _ttype!=Token.SKIP ) { _token = makeToken(_ttype); _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); } _returnToken = _token; } public final void mLPAREN(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { int _ttype; Token _token=null; int _begin=text.length(); _ttype = LPAREN; int _saveIndex; match('('); if ( _createToken && _token==null && _ttype!=Token.SKIP ) { _token = makeToken(_ttype); _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); } _returnToken = _token; } public final void mRPAREN(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { int _ttype; Token _token=null; int _begin=text.length(); _ttype = RPAREN; int _saveIndex; match(')'); if ( _createToken && _token==null && _ttype!=Token.SKIP ) { _token = makeToken(_ttype); _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); } _returnToken = _token; } public final void mLBRACK(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { int _ttype; Token _token=null; int _begin=text.length(); _ttype = LBRACK; int _saveIndex; match('['); if ( _createToken && _token==null && _ttype!=Token.SKIP ) { _token = makeToken(_ttype); _token.setText(new String(text.getBuffer(), _begin, text.length()-_begin)); } _returnToken = _token; } public final void mRBRACK(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException { int _ttype; Token _token=null; int _begin=text.length(); _ttype = RBRACK; int _saveIndex; match(']'); if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?