FileDocCategorySizeDatePackage
ImportVocabTokenManager.javaAPI DocGlassfish v2 API3233Wed Aug 30 15:34:08 BST 2006persistence.antlr

ImportVocabTokenManager

public class ImportVocabTokenManager extends SimpleTokenManager implements Cloneable
Static implementation of the TokenManager, used for importVocab option

Fields Summary
private String
filename
protected Grammar
grammar
Constructors Summary
ImportVocabTokenManager(Grammar grammar, String filename_, String name_, Tool tool_)

        // initialize
        super(name_, tool_);

        this.grammar = grammar;
        this.filename = filename_;

        // Figure out exactly where the file lives.  Check $PWD first,
        // and then search in -o <output_dir>.
        //
        File grammarFile = new File(filename);

        if (!grammarFile.exists()) {
            grammarFile = new File(antlrTool.getOutputDirectory(), filename);

            if (!grammarFile.exists()) {
                antlrTool.panic("Cannot find importVocab file '" + filename + "'");
            }
        }

        setReadOnly(true);

        // Read a file with lines of the form ID=number
        try {
            Reader fileIn = new BufferedReader(new FileReader(grammarFile));
            ANTLRTokdefLexer tokdefLexer = new ANTLRTokdefLexer(fileIn);
            ANTLRTokdefParser tokdefParser = new ANTLRTokdefParser(tokdefLexer);
            tokdefParser.setTool(antlrTool);
            tokdefParser.setFilename(filename);
            tokdefParser.file(this);
        }
        catch (FileNotFoundException fnf) {
            antlrTool.panic("Cannot find importVocab file '" + filename + "'");
        }
        catch (RecognitionException ex) {
            antlrTool.panic("Error parsing importVocab file '" + filename + "': " + ex.toString());
        }
        catch (TokenStreamException ex) {
            antlrTool.panic("Error reading importVocab file '" + filename + "'");
        }
    
Methods Summary
public java.lang.Objectclone()

        ImportVocabTokenManager tm;
        tm = (ImportVocabTokenManager)super.clone();
        tm.filename = this.filename;
        tm.grammar = this.grammar;
        return tm;
    
public voiddefine(persistence.antlr.TokenSymbol ts)
define a token.

        super.define(ts);
    
public voiddefine(java.lang.String s, int ttype)
define a token. Intended for use only when reading the importVocab file.

        TokenSymbol ts = null;
        if (s.startsWith("\"")) {
            ts = new StringLiteralSymbol(s);
        }
        else {
            ts = new TokenSymbol(s);
        }
        ts.setTokenType(ttype);
        super.define(ts);
        maxToken = (ttype + 1) > maxToken ? (ttype + 1) : maxToken;	// record maximum token type
    
public booleanisReadOnly()
importVocab token manager is read-only if output would be same as input

        return readOnly;
    
public intnextTokenType()
Get the next unused token type.

        return super.nextTokenType();