/* Copyright (C) 2001,2002,2003 Ronnie Maor and Michael Brand * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * As a special exception, the copyright holders give permission * for additional uses of the text contained in its release of XPARAM. * * The exception is that, if you link the XPARAM library with other files * to produce an executable, this does not by itself cause the * resulting executable to be covered by the GNU General Public License. * Your use of that executable is in no way restricted on account of * linking the XPARAM library code into it. * * This exception does not however invalidate any other reasons why * the executable file might be covered by the GNU General Public License. * * If you write modifications of your own for XPARAM, it is your choice * whether to permit this exception to apply to your modifications. * If you do not wish that, delete this exception notice. */ #pragma warning (disable: 4101) /* $ANTLR 2.7.1: "type_name_lexer.g" -> "TypeNameLexer.cpp"$ */ #pragma warning (disable: 4786) #include <../src_include/TypeNameLexer.hpp> #include "antlr/CharBuffer.hpp" #include "antlr/TokenStreamException.hpp" #include "antlr/TokenStreamIOException.hpp" #include "antlr/TokenStreamRecognitionException.hpp" #include "antlr/CharStreamException.hpp" #include "antlr/CharStreamIOException.hpp" #include "antlr/NoViableAltForCharException.hpp" #include "../xparam/xp_error.h" using namespace xparam_antlr; using namespace std; ANTLR_BEGIN_NAMESPACE(xParam_internal) TypeNameLexer::TypeNameLexer(std::istream& in) : xparam_antlr::CharScanner(new xparam_antlr::CharBuffer(in)) { setCaseSensitive(true); initLiterals(); } TypeNameLexer::TypeNameLexer(xparam_antlr::InputBuffer& ib) : xparam_antlr::CharScanner(ib) { setCaseSensitive(true); initLiterals(); } TypeNameLexer::TypeNameLexer(const xparam_antlr::LexerSharedInputState& state) : xparam_antlr::CharScanner(state) { setCaseSensitive(true); initLiterals(); } void TypeNameLexer::initLiterals() { } bool TypeNameLexer::getCaseSensitiveLiterals() const { return true; } xparam_antlr::RefToken TypeNameLexer::nextToken() { xparam_antlr::RefToken theRetToken; for (;;) { xparam_antlr::RefToken theRetToken; int _ttype = xparam_antlr::Token::INVALID_TYPE; resetText(); try { // for char stream error handling try { // for lexical error handling if ((LA(1)==static_cast('\t')||LA(1)==static_cast('\n')||LA(1)==static_cast('\r')||LA(1)==static_cast(' ')||LA(1)==static_cast('A')||LA(1)==static_cast('B')||LA(1)==static_cast('C')||LA(1)==static_cast('D')||LA(1)==static_cast('E')||LA(1)==static_cast('F')||LA(1)==static_cast('G')||LA(1)==static_cast('H')||LA(1)==static_cast('I')||LA(1)==static_cast('J')||LA(1)==static_cast('K')||LA(1)==static_cast('L')||LA(1)==static_cast('M')||LA(1)==static_cast('N')||LA(1)==static_cast('O')||LA(1)==static_cast('P')||LA(1)==static_cast('Q')||LA(1)==static_cast('R')||LA(1)==static_cast('S')||LA(1)==static_cast('T')||LA(1)==static_cast('U')||LA(1)==static_cast('V')||LA(1)==static_cast('W')||LA(1)==static_cast('X')||LA(1)==static_cast('Y')||LA(1)==static_cast('Z')||LA(1)==static_cast('_')||LA(1)==static_cast('a')||LA(1)==static_cast('b')||LA(1)==static_cast('c')||LA(1)==static_cast('d')||LA(1)==static_cast('e')||LA(1)==static_cast('f')||LA(1)==static_cast('g')||LA(1)==static_cast('h')||LA(1)==static_cast('i')||LA(1)==static_cast('j')||LA(1)==static_cast('k')||LA(1)==static_cast('l')||LA(1)==static_cast('m')||LA(1)==static_cast('n')||LA(1)==static_cast('o')||LA(1)==static_cast('p')||LA(1)==static_cast('q')||LA(1)==static_cast('r')||LA(1)==static_cast('s')||LA(1)==static_cast('t')||LA(1)==static_cast('u')||LA(1)==static_cast('v')||LA(1)==static_cast('w')||LA(1)==static_cast('x')||LA(1)==static_cast('y')||LA(1)==static_cast('z'))) { mTYPENAME(true); theRetToken=_returnToken; } else { if (LA(1)==EOF_CHAR) {uponEOF(); _returnToken = makeToken(xparam_antlr::Token::EOF_TYPE);} else {throw xparam_antlr::NoViableAltForCharException(LA(1), getFilename(), getLine());} } if ( !_returnToken ) goto tryAgain; // found SKIP token _ttype = _returnToken->getType(); _ttype = testLiteralsTable(_ttype); _returnToken->setType(_ttype); return _returnToken; } catch (xparam_antlr::RecognitionException& e) { throw xparam_antlr::TokenStreamRecognitionException(e); } } catch (xparam_antlr::CharStreamIOException& csie) { throw xparam_antlr::TokenStreamIOException(csie.io); } catch (xparam_antlr::CharStreamException& cse) { throw xparam_antlr::TokenStreamException(cse.getMessage()); } tryAgain:; } } void TypeNameLexer::mTYPENAME(bool _createToken) { int _ttype; xparam_antlr::RefToken _token; int _begin=text.length(); _ttype = TYPENAME; int _saveIndex; try { // for error handling mGWS(false); mID(false); mGWS(false); { for (;;) { if ((LA(1)==static_cast(':'))) { match("::"); mGWS(false); mID(false); mGWS(false); } else { goto _loop3; } } _loop3:; } { if ((LA(1)==static_cast('<'))) { mTEMPLATE_ARGS(false); } else { } } } catch (RecognitionException& ex) { if (inputState->guessing==0) { throw Error("Bad Typename"); } else { throw ex; } } if ( _createToken && _token==xparam_antlr::nullToken && _ttype!=xparam_antlr::Token::SKIP ) { _token = makeToken(_ttype); _token->setText(text.substr(_begin, text.length()-_begin)); } _returnToken = _token; _saveIndex=0; } void TypeNameLexer::mGWS(bool _createToken) { int _ttype; xparam_antlr::RefToken _token; int _begin=text.length(); _ttype = GWS; int _saveIndex; { for (;;) { if ((LA(1)==static_cast('\t')||LA(1)==static_cast('\n')||LA(1)==static_cast('\r')||LA(1)==static_cast(' '))) { _saveIndex = text.length(); mWS(false); text.erase(_saveIndex); } else { goto _loop8; } } _loop8:; } if ( _createToken && _token==xparam_antlr::nullToken && _ttype!=xparam_antlr::Token::SKIP ) { _token = makeToken(_ttype); _token->setText(text.substr(_begin, text.length()-_begin)); } _returnToken = _token; _saveIndex=0; } void TypeNameLexer::mID(bool _createToken) { int _ttype; xparam_antlr::RefToken _token; int _begin=text.length(); _ttype = ID; int _saveIndex; { switch ( LA(1)) { case static_cast('a'): case static_cast('b'): case static_cast('c'): case static_cast('d'): case static_cast('e'): case static_cast('f'): case static_cast('g'): case static_cast('h'): case static_cast('i'): case static_cast('j'): case static_cast('k'): case static_cast('l'): case static_cast('m'): case static_cast('n'): case static_cast('o'): case static_cast('p'): case static_cast('q'): case static_cast('r'): case static_cast('s'): case static_cast('t'): case static_cast('u'): case static_cast('v'): case static_cast('w'): case static_cast('x'): case static_cast('y'): case static_cast('z'): { matchRange(static_cast('a'),static_cast('z')); break; } case static_cast('A'): case static_cast('B'): case static_cast('C'): case static_cast('D'): case static_cast('E'): case static_cast('F'): case static_cast('G'): case static_cast('H'): case static_cast('I'): case static_cast('J'): case static_cast('K'): case static_cast('L'): case static_cast('M'): case static_cast('N'): case static_cast('O'): case static_cast('P'): case static_cast('Q'): case static_cast('R'): case static_cast('S'): case static_cast('T'): case static_cast('U'): case static_cast('V'): case static_cast('W'): case static_cast('X'): case static_cast('Y'): case static_cast('Z'): { matchRange(static_cast('A'),static_cast('Z')); break; } case static_cast('_'): { match(static_cast('_')); break; } default: { throw xparam_antlr::NoViableAltForCharException(LA(1), getFilename(), getLine()); } } } { for (;;) { switch ( LA(1)) { case static_cast('a'): case static_cast('b'): case static_cast('c'): case static_cast('d'): case static_cast('e'): case static_cast('f'): case static_cast('g'): case static_cast('h'): case static_cast('i'): case static_cast('j'): case static_cast('k'): case static_cast('l'): case static_cast('m'): case static_cast('n'): case static_cast('o'): case static_cast('p'): case static_cast('q'): case static_cast('r'): case static_cast('s'): case static_cast('t'): case static_cast('u'): case static_cast('v'): case static_cast('w'): case static_cast('x'): case static_cast('y'): case static_cast('z'): { matchRange(static_cast('a'),static_cast('z')); break; } case static_cast('A'): case static_cast('B'): case static_cast('C'): case static_cast('D'): case static_cast('E'): case static_cast('F'): case static_cast('G'): case static_cast('H'): case static_cast('I'): case static_cast('J'): case static_cast('K'): case static_cast('L'): case static_cast('M'): case static_cast('N'): case static_cast('O'): case static_cast('P'): case static_cast('Q'): case static_cast('R'): case static_cast('S'): case static_cast('T'): case static_cast('U'): case static_cast('V'): case static_cast('W'): case static_cast('X'): case static_cast('Y'): case static_cast('Z'): { matchRange(static_cast('A'),static_cast('Z')); break; } case static_cast('_'): { match(static_cast('_')); break; } case static_cast('0'): case static_cast('1'): case static_cast('2'): case static_cast('3'): case static_cast('4'): case static_cast('5'): case static_cast('6'): case static_cast('7'): case static_cast('8'): case static_cast('9'): { matchRange(static_cast('0'),static_cast('9')); break; } default: { goto _loop12; } } } _loop12:; } if ( _createToken && _token==xparam_antlr::nullToken && _ttype!=xparam_antlr::Token::SKIP ) { _token = makeToken(_ttype); _token->setText(text.substr(_begin, text.length()-_begin)); } _returnToken = _token; _saveIndex=0; } void TypeNameLexer::mTEMPLATE_ARGS(bool _createToken) { int _ttype; xparam_antlr::RefToken _token; int _begin=text.length(); _ttype = TEMPLATE_ARGS; int _saveIndex; match(static_cast('<')); mGWS(false); mONE_TEMPLATE_ARG(false); mGWS(false); { for (;;) { if ((LA(1)==static_cast(','))) { match(static_cast(',')); mGWS(false); mONE_TEMPLATE_ARG(false); mGWS(false); } else { goto _loop15; } } _loop15:; } match(static_cast('>')); if ( _createToken && _token==xparam_antlr::nullToken && _ttype!=xparam_antlr::Token::SKIP ) { _token = makeToken(_ttype); _token->setText(text.substr(_begin, text.length()-_begin)); } _returnToken = _token; _saveIndex=0; } void TypeNameLexer::mWS(bool _createToken) { int _ttype; xparam_antlr::RefToken _token; int _begin=text.length(); _ttype = WS; int _saveIndex; switch ( LA(1)) { case static_cast(' '): { match(static_cast(' ')); break; } case static_cast('\t'): { match(static_cast('\t')); break; } case static_cast('\r'): { match(static_cast('\r')); break; } case static_cast('\n'): { match(static_cast('\n')); break; } default: { throw xparam_antlr::NoViableAltForCharException(LA(1), getFilename(), getLine()); } } if ( _createToken && _token==xparam_antlr::nullToken && _ttype!=xparam_antlr::Token::SKIP ) { _token = makeToken(_ttype); _token->setText(text.substr(_begin, text.length()-_begin)); } _returnToken = _token; _saveIndex=0; } void TypeNameLexer::mONE_TEMPLATE_ARG(bool _createToken) { int _ttype; xparam_antlr::RefToken _token; int _begin=text.length(); _ttype = ONE_TEMPLATE_ARG; int _saveIndex; mPOSSIBLE_CONST(false); mTYPENAME(false); mGWS(false); { switch ( LA(1)) { case static_cast('*'): { match(static_cast('*')); break; } case static_cast('\t'): case static_cast('\n'): case static_cast('\r'): case static_cast(' '): case static_cast(','): case static_cast('>'): { break; } default: { throw xparam_antlr::NoViableAltForCharException(LA(1), getFilename(), getLine()); } } } if ( _createToken && _token==xparam_antlr::nullToken && _ttype!=xparam_antlr::Token::SKIP ) { _token = makeToken(_ttype); _token->setText(text.substr(_begin, text.length()-_begin)); } _returnToken = _token; _saveIndex=0; } void TypeNameLexer::mPOSSIBLE_CONST(bool _createToken) { int _ttype; xparam_antlr::RefToken _token; int _begin=text.length(); _ttype = POSSIBLE_CONST; int _saveIndex; bool synPredMatched20 = false; if (((LA(1)==static_cast('c')))) { int _m20 = mark(); synPredMatched20 = true; inputState->guessing++; try { { match("const"); mWS(false); } } catch (xparam_antlr::RecognitionException& pe) { synPredMatched20 = false; } rewind(_m20); inputState->guessing--; } if ( synPredMatched20 ) { match("const"); { int _cnt22=0; for (;;) { if ((LA(1)==static_cast('\t')||LA(1)==static_cast('\n')||LA(1)==static_cast('\r')||LA(1)==static_cast(' '))) { _saveIndex = text.length(); mWS(false); text.erase(_saveIndex); } else { if ( _cnt22>=1 ) { goto _loop22; } else {throw xparam_antlr::NoViableAltForCharException(LA(1), getFilename(), getLine());} } _cnt22++; } _loop22:; } if ( inputState->guessing==0 ) { text+=' '; } } else if ((LA(1)==static_cast('\t')||LA(1)==static_cast('\n')||LA(1)==static_cast('\r')||LA(1)==static_cast(' ')||LA(1)==static_cast('A')||LA(1)==static_cast('B')||LA(1)==static_cast('C')||LA(1)==static_cast('D')||LA(1)==static_cast('E')||LA(1)==static_cast('F')||LA(1)==static_cast('G')||LA(1)==static_cast('H')||LA(1)==static_cast('I')||LA(1)==static_cast('J')||LA(1)==static_cast('K')||LA(1)==static_cast('L')||LA(1)==static_cast('M')||LA(1)==static_cast('N')||LA(1)==static_cast('O')||LA(1)==static_cast('P')||LA(1)==static_cast('Q')||LA(1)==static_cast('R')||LA(1)==static_cast('S')||LA(1)==static_cast('T')||LA(1)==static_cast('U')||LA(1)==static_cast('V')||LA(1)==static_cast('W')||LA(1)==static_cast('X')||LA(1)==static_cast('Y')||LA(1)==static_cast('Z')||LA(1)==static_cast('_')||LA(1)==static_cast('a')||LA(1)==static_cast('b')||LA(1)==static_cast('c')||LA(1)==static_cast('d')||LA(1)==static_cast('e')||LA(1)==static_cast('f')||LA(1)==static_cast('g')||LA(1)==static_cast('h')||LA(1)==static_cast('i')||LA(1)==static_cast('j')||LA(1)==static_cast('k')||LA(1)==static_cast('l')||LA(1)==static_cast('m')||LA(1)==static_cast('n')||LA(1)==static_cast('o')||LA(1)==static_cast('p')||LA(1)==static_cast('q')||LA(1)==static_cast('r')||LA(1)==static_cast('s')||LA(1)==static_cast('t')||LA(1)==static_cast('u')||LA(1)==static_cast('v')||LA(1)==static_cast('w')||LA(1)==static_cast('x')||LA(1)==static_cast('y')||LA(1)==static_cast('z'))) { } else { throw xparam_antlr::NoViableAltForCharException(LA(1), getFilename(), getLine()); } if ( _createToken && _token==xparam_antlr::nullToken && _ttype!=xparam_antlr::Token::SKIP ) { _token = makeToken(_ttype); _token->setText(text.substr(_begin, text.length()-_begin)); } _returnToken = _token; _saveIndex=0; } ANTLR_END_NAMESPACE