FileDocCategorySizeDatePackage
RuleBlock.javaAPI DocGlassfish v2 API7290Wed Aug 30 15:34:10 BST 2006persistence.antlr

RuleBlock

public class RuleBlock extends AlternativeBlock
A list of alternatives and info contained in the rule definition.

Fields Summary
protected String
ruleName
protected String
argAction
protected String
throwsSpec
protected String
returnAction
protected RuleEndElement
endNode
protected boolean
testLiterals
persistence.antlr.collections.impl.Vector
labeledElements
protected boolean[]
lock
protected Lookahead[]
cache
Hashtable
exceptionSpecs
protected boolean
defaultErrorHandler
protected String
ignoreRule
Constructors Summary
public RuleBlock(Grammar g, String r)
Construct a named rule.


         
         
        super(g);
        ruleName = r;
        labeledElements = new Vector();
        cache = new Lookahead[g.maxk + 1];
        exceptionSpecs = new Hashtable();
        setAutoGen(g instanceof ParserGrammar);
    
public RuleBlock(Grammar g, String r, int line, boolean doAutoGen_)
Construct a named rule with line number information

        this(g, r);
        this.line = line;
        setAutoGen(doAutoGen_);
    
Methods Summary
public voidaddExceptionSpec(ExceptionSpec ex)

        if (findExceptionSpec(ex.label) != null) {
            if (ex.label != null) {
                grammar.antlrTool.error("Rule '" + ruleName + "' already has an exception handler for label: " + ex.label);
            }
            else {
                grammar.antlrTool.error("Rule '" + ruleName + "' already has an exception handler");
            }
        }
        else {
            exceptionSpecs.put((ex.label == null ? "" : ex.label.getText()), ex);
        }
    
public ExceptionSpecfindExceptionSpec(Token label)

        return (ExceptionSpec)exceptionSpecs.get(label == null ? "" : label.getText());
    
public ExceptionSpecfindExceptionSpec(java.lang.String label)

        return (ExceptionSpec)exceptionSpecs.get(label == null ? "" : label);
    
public voidgenerate()

        grammar.generator.gen(this);
    
public booleangetDefaultErrorHandler()

        return defaultErrorHandler;
    
public RuleEndElementgetEndElement()

        return endNode;
    
public java.lang.StringgetIgnoreRule()

        return ignoreRule;
    
public java.lang.StringgetRuleName()

        return ruleName;
    
public booleangetTestLiterals()

        return testLiterals;
    
public booleanisLexerAutoGenRule()

        return ruleName.equals("nextToken");
    
public Lookaheadlook(int k)

        return grammar.theLLkAnalyzer.look(k, this);
    
public voidprepareForAnalysis()

        super.prepareForAnalysis();
        lock = new boolean[grammar.maxk + 1];
    
public voidsetDefaultErrorHandler(boolean value)

        defaultErrorHandler = value;
    
public voidsetEndElement(RuleEndElement re)

        endNode = re;
    
public voidsetOption(Token key, Token value)

        if (key.getText().equals("defaultErrorHandler")) {
            if (value.getText().equals("true")) {
                defaultErrorHandler = true;
            }
            else if (value.getText().equals("false")) {
                defaultErrorHandler = false;
            }
            else {
                grammar.antlrTool.error("Value for defaultErrorHandler must be true or false", grammar.getFilename(), key.getLine(), key.getColumn());
            }
        }
        else if (key.getText().equals("testLiterals")) {
            if (!(grammar instanceof LexerGrammar)) {
                grammar.antlrTool.error("testLiterals option only valid for lexer rules", grammar.getFilename(), key.getLine(), key.getColumn());
            }
            else {
                if (value.getText().equals("true")) {
                    testLiterals = true;
                }
                else if (value.getText().equals("false")) {
                    testLiterals = false;
                }
                else {
                    grammar.antlrTool.error("Value for testLiterals must be true or false", grammar.getFilename(), key.getLine(), key.getColumn());
                }
            }
        }
        else if (key.getText().equals("ignore")) {
            if (!(grammar instanceof LexerGrammar)) {
                grammar.antlrTool.error("ignore option only valid for lexer rules", grammar.getFilename(), key.getLine(), key.getColumn());
            }
            else {
                ignoreRule = value.getText();
            }
        }
        else if (key.getText().equals("paraphrase")) {
            if (!(grammar instanceof LexerGrammar)) {
                grammar.antlrTool.error("paraphrase option only valid for lexer rules", grammar.getFilename(), key.getLine(), key.getColumn());
            }
            else {
                // find token def associated with this rule
                TokenSymbol ts = grammar.tokenManager.getTokenSymbol(ruleName);
                if (ts == null) {
                    grammar.antlrTool.panic("cannot find token associated with rule " + ruleName);
                }
                ts.setParaphrase(value.getText());
            }
        }
        else if (key.getText().equals("generateAmbigWarnings")) {
            if (value.getText().equals("true")) {
                generateAmbigWarnings = true;
            }
            else if (value.getText().equals("false")) {
                generateAmbigWarnings = false;
            }
            else {
                grammar.antlrTool.error("Value for generateAmbigWarnings must be true or false", grammar.getFilename(), key.getLine(), key.getColumn());
            }
        }
        else {
            grammar.antlrTool.error("Invalid rule option: " + key.getText(), grammar.getFilename(), key.getLine(), key.getColumn());
        }
    
public java.lang.StringtoString()

        String s = " FOLLOW={";
        Lookahead cache[] = endNode.cache;
        int k = grammar.maxk;
        boolean allNull = true;
        for (int j = 1; j <= k; j++) {
            if (cache[j] == null) continue;
            s += cache[j].toString(",", grammar.tokenManager.getVocabulary());
            allNull = false;
            if (j < k && cache[j + 1] != null) s += ";";
        }
        s += "}";
        if (allNull) s = "";
        return ruleName + ": " + super.toString() + " ;" + s;