// $ANTLR 2.7.4: "writerformat.g" -> "WriterFormatLexer.java"$
package org.jostraca;
import org.jostraca.util.Standard;
import org.jostraca.util.PropertySet;
import org.jostraca.section.SectionSet;
import org.jostraca.transform.TextualTransformManager;
import java.util.Vector;
import java.util.Stack;
import java.util.ArrayList;
import java.io.InputStream;
import org.jostraca.comp.antlr.TokenStreamException;
import org.jostraca.comp.antlr.TokenStreamIOException;
import org.jostraca.comp.antlr.TokenStreamRecognitionException;
import org.jostraca.comp.antlr.CharStreamException;
import org.jostraca.comp.antlr.CharStreamIOException;
import org.jostraca.comp.antlr.ANTLRException;
import java.io.Reader;
import java.util.Hashtable;
import org.jostraca.comp.antlr.CharScanner;
import org.jostraca.comp.antlr.InputBuffer;
import org.jostraca.comp.antlr.ByteBuffer;
import org.jostraca.comp.antlr.CharBuffer;
import org.jostraca.comp.antlr.Token;
import org.jostraca.comp.antlr.CommonToken;
import org.jostraca.comp.antlr.RecognitionException;
import org.jostraca.comp.antlr.NoViableAltForCharException;
import org.jostraca.comp.antlr.MismatchedCharException;
import org.jostraca.comp.antlr.TokenStream;
import org.jostraca.comp.antlr.ANTLRHashString;
import org.jostraca.comp.antlr.LexerSharedInputState;
import org.jostraca.comp.antlr.collections.impl.BitSet;
import org.jostraca.comp.antlr.SemanticException;
public class WriterFormatLexer extends org.jostraca.comp.antlr.CharScanner implements WriterFormatLexerTokenTypes, TokenStream
{
boolean iAppend = true;
Stack iAppendIdentifiers = new Stack();
String iAppendRestartOn = "";
SectionSet iSectionSet = new SectionSet();
PropertySet iPropertySet = new PropertySet();
StringBuffer iCodeWriter = new StringBuffer();
ArrayList iParseMessages = new ArrayList();
//UserErrorHandler iUserErrorHandler = new UserErrorHandler();
String iLiteral = "";
private TextualTransformManager iStringEscape = new TextualTransformManager( "StringEscape" );
public void setSectionSet( SectionSet pSectionSet ) {
iSectionSet = pSectionSet;
}
public void setPropertySet( PropertySet pPropertySet ) throws Exception {
iPropertySet = pPropertySet;
String classList = Standard.EMPTY;
classList = iPropertySet.get( Property.lang_StringEscapeTransform );
iStringEscape.loadClasses( classList );
}
public String getCodeWriter() {
iCodeWriter.append( iLiteral );
return iCodeWriter.toString();
}
public void reportError( RecognitionException pRecognitionException ) {
iParseMessages.add( new ParseMessage( ParseMessage.TYPE_error,
pRecognitionException.getErrorMessage(),
pRecognitionException.getLine(),
pRecognitionException.getColumn() ) );
//iUserErrorHandler.addUserError( ""+pRecognitionException );
}
public void reportError( String pErrorMsg ) {
iParseMessages.add( new ParseMessage( ParseMessage.TYPE_error, pErrorMsg ) );
//iUserErrorHandler.addUserError( pErrorMsg );
}
public void reportWarning( String pWarningMsg ) {
iParseMessages.add( new ParseMessage( ParseMessage.TYPE_warning, pWarningMsg ) );
//iUserErrorHandler.addUserError( pWarningMsg );
}
public void init() {
iLiteral = "";
iParseMessages = new ArrayList();
}
public boolean hasParseMessages() {
return 0 < iParseMessages.size();
}
public ArrayList getParseMessages() {
return iParseMessages;
}
public WriterFormatLexer(InputStream in) {
this(new ByteBuffer(in));
}
public WriterFormatLexer(Reader in) {
this(new CharBuffer(in));
}
public WriterFormatLexer(InputBuffer ib) {
this(new LexerSharedInputState(ib));
}
public WriterFormatLexer(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 '!':
{
mSECTION(true);
theRetToken=_returnToken;
break;
}
case '$':
{
mPROPERTY(true);
theRetToken=_returnToken;
break;
}
case '\'':
{
mLITERAL(true);
theRetToken=_returnToken;
break;
}
default:
if ((_tokenSet_0.member(LA(1)))) {
mTEXT(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());
}
}
}
}
public final void mSECTION(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = SECTION;
int _saveIndex;
if ((LA(1)=='!') && (LA(2)=='<') && (_tokenSet_1.member(LA(3)))) {
match('!');
match('<');
mIDENTIFIER(false);
match('>');
if( iAppend ) {
if( 0 < iLiteral.length() ) {
iCodeWriter.append( iLiteral.substring(0, iLiteral.length()-1) );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
else {
String section = new String(text.getBuffer(),_begin,text.length()-_begin);
section = section.substring(2, section.length()-1);
if( iSectionSet.hasSection( section ) )
iCodeWriter.append( iSectionSet.getSection( section ).getContent() );
// if undefined, ignore
}
}
}
else if ((LA(1)=='!') && (LA(2)=='<') && (LA(3)=='{')) {
match('!');
match('<');
match('{');
mIDENTIFIER(false);
match('>');
if( iAppend && 0 < iLiteral.length() ) {
iCodeWriter.append( iLiteral.substring(0, iLiteral.length()-1) );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
else {
String section = new String(text.getBuffer(),_begin,text.length()-_begin);
section = section.substring(3, section.length()-1);
if( iSectionSet.hasSection( section ) ) {
if( 0 < iSectionSet.getSection( section ).getContent().trim().length() ) {
iAppend = true;
}
else {
iAppend = false;
iAppendIdentifiers.push( section );
}
}
else {
iAppend = false;
iAppendIdentifiers.push( section );
}
}
}
else if ((LA(1)=='!') && (LA(2)=='<') && (LA(3)=='}')) {
match('!');
match('<');
match('}');
mIDENTIFIER(false);
match('>');
if( iAppend && 0 < iLiteral.length() ) {
iCodeWriter.append( iLiteral.substring(0, iLiteral.length()-1) );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
else {
String section = new String(text.getBuffer(),_begin,text.length()-_begin);
section = section.substring(3, section.length()-1);
if( ! iAppendIdentifiers.empty() ) {
if( section.equals( (String) iAppendIdentifiers.peek() ) ) {
iAppendIdentifiers.pop();
iAppend = true;
}
}
}
}
else if ((LA(1)=='!') && (_tokenSet_2.member(LA(2)))) {
match('!');
matchNot('<');
if( iAppend ) {
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
}
}
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;
}
protected final void mIDENTIFIER(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = IDENTIFIER;
int _saveIndex;
{
switch ( LA(1)) {
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':
{
matchRange('a','z');
break;
}
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':
{
matchRange('A','Z');
break;
}
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
case '8': case '9':
{
matchRange('0','9');
break;
}
case '_':
{
match('_');
break;
}
case ':':
{
match(':');
break;
}
case '.':
{
match('.');
break;
}
default:
{
throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());
}
}
}
{
_loop9:
do {
switch ( LA(1)) {
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':
{
matchRange('a','z');
break;
}
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':
{
matchRange('A','Z');
break;
}
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
case '8': case '9':
{
matchRange('0','9');
break;
}
case '_':
{
match('_');
break;
}
case ':':
{
match(':');
break;
}
case '.':
{
match('.');
break;
}
default:
{
break _loop9;
}
}
} while (true);
}
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 mPROPERTY(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = PROPERTY;
int _saveIndex;
if ((LA(1)=='$') && (LA(2)=='<') && (_tokenSet_1.member(LA(3)))) {
match('$');
match('<');
mIDENTIFIER(false);
match('>');
if( iAppend ) {
if( 0 < iLiteral.length() ) {
iCodeWriter.append( iLiteral.substring(0, iLiteral.length()-1) );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
else {
String property = new String(text.getBuffer(),_begin,text.length()-_begin);
property = property.substring(2, property.length()-1);
if( iPropertySet.has( property ) )
iCodeWriter.append( iPropertySet.get( property ) );
// if undefined, ignore
}
}
}
else if ((LA(1)=='$') && (LA(2)=='<') && (LA(3)=='\\')) {
match('$');
match('<');
match('\\');
mIDENTIFIER(false);
match('>');
if( iAppend ) {
if( 0 < iLiteral.length() ) {
iCodeWriter.append( iLiteral.substring(0, iLiteral.length()-1) );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
else {
String property = new String(text.getBuffer(),_begin,text.length()-_begin);
property = property.substring(3, property.length()-1);
if( iPropertySet.has( property ) ) {
try {
iCodeWriter.append( iStringEscape.transform( iPropertySet.get( property ) ) );
}
catch( Exception e ) {
iCodeWriter.append( iPropertySet.get( property ) );
}
}
}
}
}
else if ((LA(1)=='$') && (LA(2)=='<') && (LA(3)=='{')) {
match('$');
match('<');
match('{');
mIDENTIFIER(false);
match('>');
if( iAppend && 0 < iLiteral.length() ) {
iCodeWriter.append( iLiteral.substring(0, iLiteral.length()-1) );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
else {
String property = new String(text.getBuffer(),_begin,text.length()-_begin);
property = property.substring(3, property.length()-1);
if( iPropertySet.has( property ) ) {
if( 0 == iPropertySet.get( property ).trim().length() ) {
iAppend = false;
iAppendRestartOn = property;
}
} else {
iAppend = false;
iAppendRestartOn = property;
}
iAppendIdentifiers.push( property );
}
}
else if ((LA(1)=='$') && (LA(2)=='<') && (LA(3)=='}')) {
match('$');
match('<');
match('}');
mIDENTIFIER(false);
match('>');
if( iAppend && 0 < iLiteral.length() ) {
iCodeWriter.append( iLiteral.substring(0, iLiteral.length()-1) );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
else {
String property = new String(text.getBuffer(),_begin,text.length()-_begin);
property = property.substring(3, property.length()-1);
if( ! iAppendIdentifiers.empty() ) {
if( property.equals( (String) iAppendIdentifiers.peek() ) ) {
String topOfStack = (String) iAppendIdentifiers.pop();
if( iAppendRestartOn.equals( topOfStack ) ) {
iAppend = true;
iAppendRestartOn = "";
}
}
}
}
}
else if ((LA(1)=='$') && (_tokenSet_2.member(LA(2)))) {
match('$');
matchNot('<');
if( iAppend ) {
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
}
}
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;
}
public final void mLITERAL(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = LITERAL;
int _saveIndex;
{
int _cnt5=0;
_loop5:
do {
if ((LA(1)=='\'')) {
match('\'');
}
else {
if ( _cnt5>=1 ) { break _loop5; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
}
_cnt5++;
} while (true);
}
iLiteral = new String(text.getBuffer(),_begin,text.length()-_begin);
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 mTEXT(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = TEXT;
int _saveIndex;
if ((_tokenSet_3.member(LA(1)))) {
{
int _cnt13=0;
_loop13:
do {
if ((_tokenSet_3.member(LA(1)))) {
{
match(_tokenSet_3);
}
}
else {
if ( _cnt13>=1 ) { break _loop13; } else {throw new NoViableAltForCharException((char)LA(1), getFilename(), getLine(), getColumn());}
}
_cnt13++;
} while (true);
}
if( iAppend) {
iCodeWriter.append( iLiteral );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
}
else if ((LA(1)=='\n')) {
match('\n');
newline();
if( iAppend) {
iCodeWriter.append( iLiteral );
iCodeWriter.append( new String(text.getBuffer(),_begin,text.length()-_begin) );
iLiteral = "";
}
}
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[8];
data[0]=-627065225224L;
for (int i = 1; i<=3; i++) { data[i]=-1L; }
return data;
}
public static final BitSet _tokenSet_0 = new BitSet(mk_tokenSet_0());
private static final long[] mk_tokenSet_1() {
long[] data = { 576249646070890496L, 576460745995190270L, 0L, 0L, 0L};
return data;
}
public static final BitSet _tokenSet_1 = new BitSet(mk_tokenSet_1());
private static final long[] mk_tokenSet_2() {
long[] data = new long[8];
data[0]=-1152921504606846984L;
for (int i = 1; i<=3; i++) { data[i]=-1L; }
return data;
}
public static final BitSet _tokenSet_2 = new BitSet(mk_tokenSet_2());
private static final long[] mk_tokenSet_3() {
long[] data = new long[8];
data[0]=-627065226248L;
for (int i = 1; i<=3; i++) { data[i]=-1L; }
return data;
}
public static final BitSet _tokenSet_3 = new BitSet(mk_tokenSet_3());
}