BracesLexer.java
// $ANTLR 2.7.7 (20060906): "braces.g" -> "BracesLexer.java"$
/*
** Module : BracesLexer.java
** BracesParser.java
** PreprocTokenTypes.java
** Abstract : This grammar parses the Progress Preprocessor {...} language
** elements and replaces them with evaluations on the input
** stream. Unlike the other grammars, this one works independently
** from the main line.
**
** Copyright (c) 2004-2016, Golden Code Development Corporation.
**
** -#- -I- --Date-- -T- --JPRM-- ----------------Description-----------------
** 001 GES 20041116 ADD @18834 WARNING, THIS IS A GENERATED FILE!!!
** DO NOT EDIT THIS FILE. The original source
** file is braces.g!
*/
package com.goldencode.p2j.preproc;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import com.goldencode.p2j.util.*;
import com.goldencode.p2j.convert.*;
import antlr.collections.AST;
import antlr.collections.impl.*;
import antlr.debug.misc.*;
import antlr.*;
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;
/**
* Tokenizes the input stream of characters from the portion of Progress
* source file between braces and returns tokens to the caller according
* to the needs of preprocessor.
* <p>
* There is only a single context for this lexer as no comments are honored
* inside the braces and strings are treated in a special way: only double
* quoted strings are recognized, they can be adjacent to text and even
* unclosed.
*
* @see BracesParser
*/
public class BracesLexer extends antlr.CharScanner implements PreprocTokenTypes, TokenStream
{
/** keeps the reference to the shared environment */
private Environment env = null;
/** Flag to denote if the backslash is honored as an escape sequence. */
private boolean isUnixEscapes = false;
/**
* Constructor. Creates a lexer attached to the input stream
* taken from the environment. Saves the environment for future needs.
*
* @param env
* Shared preprocessor environment.
*/
public BracesLexer(Environment env)
{
this(new CharBuffer(env.getIns()));
this.env = env;
this.env.setLsi(this.getInputState());
this.isUnixEscapes = env.getOpt().isUnixEscapes();
}
public BracesLexer(InputStream in) {
this(new ByteBuffer(in));
}
public BracesLexer(Reader in) {
this(new CharBuffer(in));
}
public BracesLexer(InputBuffer ib) {
this(new LexerSharedInputState(ib));
}
public BracesLexer(LexerSharedInputState state) {
super(state);
caseSensitiveLiterals = true;
setCaseSensitive(true);
literals = new Hashtable();
}
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 ' ':
{
mWS(true);
theRetToken=_returnToken;
break;
}
case '=':
{
mEQUALS(true);
theRetToken=_returnToken;
break;
}
case '*':
{
mSTAR(true);
theRetToken=_returnToken;
break;
}
case '&':
{
mAMPER(true);
theRetToken=_returnToken;
break;
}
case '"':
{
mQUOTE(true);
theRetToken=_returnToken;
break;
}
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
case '8': case '9':
{
mDIGITS(true);
theRetToken=_returnToken;
break;
}
default:
if ((_tokenSet_0.member(LA(1)))) {
mCODE(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();
_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());
}
}
}
}
/**
* Matches any amount of whitespace on input.
* <p>
* Spaces, tabs and newlines are all matched. This is a top level lexer rule
* which means that there is an associated <code>WS</code> token.
*/
public final void mWS(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = WS;
int _saveIndex;
{
int _cnt63=0;
_loop63:
do {
switch ( LA(1)) {
case ' ':
{
match(' ');
break;
}
case '\t':
{
match('\t');
break;
}
case '\n':
{
match('\n');
break;
}
default:
{
if ( _cnt63>=1 ) { break _loop63; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
}
}
_cnt63++;
} while (true);
}
if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
_token = makeToken(_ttype);
_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));
}
_returnToken = _token;
}
/**
* Matches a single equal character.
* <p>
* This is a top level lexer rule which means that there is an associated
* <code>EQUALS</code> token.
*/
public final void mEQUALS(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = EQUALS;
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;
}
/**
* Matches a single asterisk character.
* <p>
* This is a top level lexer rule which means that there is an associated
* <code>STAR</code> token.
*/
public final void mSTAR(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = STAR;
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;
}
/**
* Matches a single ampersand character.
* <p>
* This is a top level lexer rule which means that there is an associated
* <code>AMPER</code> token.
*/
public final void mAMPER(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = AMPER;
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;
}
/**
* Matches a single quote (not apostrophe) character.
* <p>
* This is a top level lexer rule which means that there is an associated
* <code>QUOTE</code> token.
*/
public final void mQUOTE(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = QUOTE;
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;
}
/**
* Matches any number of successive decimal digits on input.
* <p>
* This is a top level lexer rule which means that there is an associated
* <code>DIGITS</code> token.
*/
public final void mDIGITS(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = DIGITS;
int _saveIndex;
{
int _cnt70=0;
_loop70:
do {
if (((LA(1) >= '0' && LA(1) <= '9'))) {
mDIGIT(false);
}
else {
if ( _cnt70>=1 ) { break _loop70; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
}
_cnt70++;
} while (true);
}
if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
_token = makeToken(_ttype);
_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));
}
_returnToken = _token;
}
/**
* Matches a single decimal digit on input.
*/
protected final void mDIGIT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = DIGIT;
int _saveIndex;
matchRange('0','9');
if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
_token = makeToken(_ttype);
_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));
}
_returnToken = _token;
}
/**
* Matches a preprocessor input that has no other interpretation. Due to the
* fact that escaped '}' characters must be ignored here, this rule must
* include matching for the <code>RBRACE</code> token. Note that the
* {@link ClearStream} implementation returns the escape character instead
* of "eating" it when it is parsing braces. The escape character is either
* tilde or backslash (but backslash is only honored if UNIX escapes are
* honored) and must be detected here to differentiate between text and
* the <code>RBRACE</code>. If an escaped right brace is matched, note that
* the escape character is dropped unless we are parsing inside a string
* literal (further up the stack).
* <p>
* This is a top level lexer rule which means that there is an associated
* <code>CODE</code> token.
*/
public final void mCODE(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = CODE;
int _saveIndex;
if ((LA(1)=='}')) {
match('}');
_ttype = RBRACE;
}
else if ((_tokenSet_1.member(LA(1)))) {
{
int _cnt74=0;
_loop74:
do {
if (((LA(1)=='~') && (LA(2)=='}'))&&( env.isInString() )) {
match('~');
match('}');
}
else if (((LA(1)=='~') && (LA(2)=='}'))&&( !env.isInString() )) {
_saveIndex=text.length();
match('~');
text.setLength(_saveIndex);
match('}');
}
else if ((LA(1)=='~') && (LA(2)=='~')) {
_saveIndex=text.length();
match('~');
text.setLength(_saveIndex);
match('~');
}
else if ((LA(1)=='~') && (LA(2)=='\\')) {
_saveIndex=text.length();
match('~');
text.setLength(_saveIndex);
match('\\');
}
else if (((LA(1)=='\\') && (LA(2)=='}'))&&( env.isInString() && isUnixEscapes )) {
match('\\');
match('}');
}
else if (((LA(1)=='\\') && (LA(2)=='}'))&&( !env.isInString() && isUnixEscapes )) {
_saveIndex=text.length();
match('\\');
text.setLength(_saveIndex);
match('}');
}
else if (((LA(1)=='\\') && (LA(2)=='\\'))&&( isUnixEscapes )) {
_saveIndex=text.length();
match('\\');
text.setLength(_saveIndex);
match('\\');
}
else if (((LA(1)=='\\') && (LA(2)=='~'))&&( isUnixEscapes )) {
_saveIndex=text.length();
match('\\');
text.setLength(_saveIndex);
match('~');
}
else if ((LA(1)=='~') && (true)) {
match('~');
}
else if ((LA(1)=='\\') && (true)) {
match('\\');
}
else if ((_tokenSet_2.member(LA(1)))) {
{
match(_tokenSet_2);
}
}
else {
if ( _cnt74>=1 ) { break _loop74; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
}
_cnt74++;
} while (true);
}
}
else {
throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
}
if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
_token = makeToken(_ttype);
_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));
}
_returnToken = _token;
}
private static final long[] mk_tokenSet_0() {
long[] data = new long[2048];
data[0]=-2593796604787959297L;
for (int i = 1; i<=1022; i++) { data[i]=-1L; }
data[1023]=9223372036854775807L;
return data;
}
public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
private static final long[] mk_tokenSet_1() {
long[] data = new long[2048];
data[0]=-2593796604787959297L;
data[1]=-2305843009213693953L;
for (int i = 2; i<=1022; i++) { data[i]=-1L; }
data[1023]=9223372036854775807L;
return data;
}
public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
private static final long[] mk_tokenSet_2() {
long[] data = new long[2048];
data[0]=-2593796604787959297L;
data[1]=-6917529027909517313L;
for (int i = 2; i<=1022; i++) { data[i]=-1L; }
data[1023]=9223372036854775807L;
return data;
}
public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
}