⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgnlexer.java

📁 chess 一个beguanyu国际象棋的一个Java源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// $ANTLR 2.7.1: "pgn.g" -> "PGNLexer.java"$package de.java_chess.javaChess.pgn;import antlr.*;import antlr.collections.*;  import de.java_chess.javaChess.notation.*;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;/** * A lexer for PGN files. */public class PGNLexer extends antlr.CharScanner implements PGNTokenTypes, TokenStream {public PGNLexer(InputStream in) {	this(new ByteBuffer(in));}public PGNLexer(Reader in) {	this(new CharBuffer(in));}public PGNLexer(InputBuffer ib) {	this(new LexerSharedInputState(ib));}public PGNLexer(LexerSharedInputState state) {	super(state);	literals = new Hashtable();caseSensitiveLiterals = true;setCaseSensitive(true);}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 '\t':  case '\n':  case '\u000c':  case '\r':				case ' ':				{					mWS(true);					theRetToken=_returnToken;					break;				}				case '.':				{					mDOT(true);					theRetToken=_returnToken;					break;				}				case '[':				{					mLBRACK(true);					theRetToken=_returnToken;					break;				}				case ']':				{					mRBRACK(true);					theRetToken=_returnToken;					break;				}				case ';':				{					mSL_COMMENT(true);					theRetToken=_returnToken;					break;				}				case '"':				{					mSTRING_LITERAL(true);					theRetToken=_returnToken;					break;				}				case 'a':  case 'b':  case 'c':  case 'd':				case 'e':  case 'f':  case 'g':  case 'h':				{					mSQUARE_NAME(true);					theRetToken=_returnToken;					break;				}				case '-':				{					mPIECE_MOVE(true);					theRetToken=_returnToken;					break;				}				case 'x':				{					mPIECE_CAPTURE(true);					theRetToken=_returnToken;					break;				}				case '=':				{					mPAWN_PROMOTION(true);					theRetToken=_returnToken;					break;				}				case 'W':				{					mTAG_WHITE(true);					theRetToken=_returnToken;					break;				}				case 'D':				{					mTAG_DATE(true);					theRetToken=_returnToken;					break;				}				case 'E':				{					mTAG_EVENT(true);					theRetToken=_returnToken;					break;				}				case 'S':				{					mTAG_SITE(true);					theRetToken=_returnToken;					break;				}				default:					if ((LA(1)=='O') && (LA(2)=='-')) {						mRIGHT_CASTLING(true);						theRetToken=_returnToken;					}					else if (((LA(1) >= '1' && LA(1) <= '9')) && (_tokenSet_0.member(LA(2)))) {						mMOVE_INDEX(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='B') && (LA(2)=='l')) {						mTAG_BLACK(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='R') && (LA(2)=='o')) {						mTAG_ROUND(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='R') && (LA(2)=='e')) {						mTAG_RESULT(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='O') && (LA(2)=='p')) {						mTAG_OPENING(true);						theRetToken=_returnToken;					}					else if ((_tokenSet_1.member(LA(1))) && (true)) {						mFIGURINE_LETTER_CODE(true);						theRetToken=_returnToken;					}					else if ((LA(1)=='*'||LA(1)=='0'||LA(1)=='1') && (true)) {						mGAME_TERMINATOR(true);						theRetToken=_returnToken;					}				else {					if (LA(1)==EOF_CHAR) {uponEOF(); _returnToken = makeToken(Token.EOF_TYPE);}				else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine());}				}				}				if ( _returnToken==null ) continue tryAgain; // found SKIP token				_ttype = _returnToken.getType();				_ttype = testLiteralsTable(_ttype);				_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 mWS(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {		int _ttype; Token _token=null; int _begin=text.length();		_ttype = WS;		int _saveIndex;				{		switch ( LA(1)) {		case ' ':		{			match(' ');			break;		}		case '\t':		{			match('\t');			break;		}		case '\u000c':		{			match('\f');			break;		}		case '\n':  case '\r':		{			{			if ((LA(1)=='\r') && (LA(2)=='\n')) {				match("\r\n");			}			else if ((LA(1)=='\r') && (true)) {				match('\r');			}			else if ((LA(1)=='\n')) {				match('\n');			}			else {				throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine());			}						}			newline();			break;		}		default:		{			throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine());		}		}		}		/* $setType(Token.SKIP); */		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 mDOT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {		int _ttype; Token _token=null; int _begin=text.length();		_ttype = DOT;		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 ) {			_token = makeToken(_ttype);			_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));		}		_returnToken = _token;	}		public final void mSL_COMMENT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {		int _ttype; Token _token=null; int _begin=text.length();		_ttype = SL_COMMENT;		int _saveIndex;				match(";");		{		_loop39:		do {			if ((_tokenSet_2.member(LA(1)))) {				{				match(_tokenSet_2);				}			}			else {				break _loop39;			}					} while (true);		}		{		if ((LA(1)=='\r') && (LA(2)=='\n')) {			match("\r\n");		}		else if ((LA(1)=='\n')) {			match("\n");		}		else if ((LA(1)=='\r') && (true)) {			match("\r");		}		else {			throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine());		}				}		_ttype = Token.SKIP; newline();		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 mSTRING_LITERAL(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -