FileDocCategorySizeDatePackage
ANTLRTokdefParser.javaAPI DocGlassfish v2 API6165Wed Feb 08 12:30:34 GMT 2006None

ANTLRTokdefParser

public class ANTLRTokdefParser extends persistence.antlr.LLkParser implements ANTLRTokdefParserTokenTypes
Simple lexer/parser for reading token definition files in support of the import/export vocab option for grammars.

Fields Summary
private persistence.antlr.Tool
antlrTool
public static final String[]
_tokenNames
public static final persistence.antlr.collections.impl.BitSet
_tokenSet_0
public static final persistence.antlr.collections.impl.BitSet
_tokenSet_1
Constructors Summary
public ANTLRTokdefParser(persistence.antlr.ParserSharedInputState state)

  super(state,3);
  tokenNames = _tokenNames;
protected ANTLRTokdefParser(persistence.antlr.TokenBuffer tokenBuf, int k)

  super(tokenBuf,k);
  tokenNames = _tokenNames;
public ANTLRTokdefParser(persistence.antlr.TokenBuffer tokenBuf)

  this(tokenBuf,3);
protected ANTLRTokdefParser(persistence.antlr.TokenStream lexer, int k)

  super(lexer,k);
  tokenNames = _tokenNames;
public ANTLRTokdefParser(persistence.antlr.TokenStream lexer)

  this(lexer,3);
Methods Summary
public final voidfile(ImportVocabTokenManager tm)

		
		Token  name = null;
		
		try {      // for error handling
			name = LT(1);
			match(ID);
			{
			_loop225:
			do {
				if ((LA(1)==ID||LA(1)==STRING)) {
					line(tm);
				}
				else {
					break _loop225;
				}
				
			} while (true);
			}
		}
		catch (RecognitionException ex) {
			reportError(ex);
			consume();
			consumeUntil(_tokenSet_0);
		}
	
protected persistence.antlr.ToolgetTool()

since
2.7.2

        return antlrTool;
    
public final voidline(ImportVocabTokenManager tm)

		
		Token  s1 = null;
		Token  lab = null;
		Token  s2 = null;
		Token  id = null;
		Token  para = null;
		Token  id2 = null;
		Token  i = null;
		Token t=null; Token s=null;
		
		try {      // for error handling
			{
			if ((LA(1)==STRING)) {
				s1 = LT(1);
				match(STRING);
				s = s1;
			}
			else if ((LA(1)==ID) && (LA(2)==ASSIGN) && (LA(3)==STRING)) {
				lab = LT(1);
				match(ID);
				t = lab;
				match(ASSIGN);
				s2 = LT(1);
				match(STRING);
				s = s2;
			}
			else if ((LA(1)==ID) && (LA(2)==LPAREN)) {
				id = LT(1);
				match(ID);
				t=id;
				match(LPAREN);
				para = LT(1);
				match(STRING);
				match(RPAREN);
			}
			else if ((LA(1)==ID) && (LA(2)==ASSIGN) && (LA(3)==INT)) {
				id2 = LT(1);
				match(ID);
				t=id2;
			}
			else {
				throw new NoViableAltException(LT(1), getFilename());
			}
			
			}
			match(ASSIGN);
			i = LT(1);
			match(INT);
			
					Integer value = Integer.valueOf(i.getText());
					// if literal found, define as a string literal
					if ( s!=null ) {
						tm.define(s.getText(), value.intValue());
						// if label, then label the string and map label to token symbol also
						if ( t!=null ) {
							StringLiteralSymbol sl =
								(StringLiteralSymbol) tm.getTokenSymbol(s.getText());
							sl.setLabel(t.getText());
							tm.mapToTokenSymbol(t.getText(), sl);
						}
					}
					// define token (not a literal)
					else if ( t!=null ) {
						tm.define(t.getText(), value.intValue());
						if ( para!=null ) {
							TokenSymbol ts = tm.getTokenSymbol(t.getText());
							ts.setParaphrase(
								para.getText()
							);
						}
					}
					
		}
		catch (RecognitionException ex) {
			reportError(ex);
			consume();
			consumeUntil(_tokenSet_1);
		}
	
private static final long[]mk_tokenSet_0()

	
	     
		long[] data = { 2L, 0L};
		return data;
	
private static final long[]mk_tokenSet_1()

	     
		long[] data = { 50L, 0L};
		return data;
	
public voidreportError(java.lang.String s)
Delegates the error message to the tool if any was registered via {@link #initTool(persistence.antlr.Tool)}

since
2.7.2

        if (getTool() != null) {
            getTool().error(s, getFilename(), -1, -1);
		}
        else {
            super.reportError(s);
		}
    
public voidreportError(persistence.antlr.RecognitionException e)
Delegates the error message to the tool if any was registered via {@link #initTool(persistence.antlr.Tool)}

since
2.7.2

        if (getTool() != null) {
            getTool().error(e.getErrorMessage(), e.getFilename(), e.getLine(), e.getColumn());
		}
        else {
            super.reportError(e);
		}
    
public voidreportWarning(java.lang.String s)
Delegates the warning message to the tool if any was registered via {@link #initTool(persistence.antlr.Tool)}

since
2.7.2

        if (getTool() != null) {
            getTool().warning(s, getFilename(), -1, -1);
		}
        else {
            super.reportWarning(s);
		}
    
public voidsetTool(persistence.antlr.Tool tool)
In order to make it so existing subclasses don't break, we won't require that the persistence.antlr.Tool instance be passed as a constructor element. Instead, the persistence.antlr.Tool instance should register itself via {@link #initTool(antlr.Tool)}

throws
IllegalStateException if a tool has already been registered
since
2.7.2

        if (antlrTool == null) {
            antlrTool = tool;
		}
        else {
            throw new IllegalStateException("persistence.antlr.Tool already registered");
		}