ImportVocabTokenManagerpublic class ImportVocabTokenManager extends SimpleTokenManager implements CloneableStatic 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.Object | clone()
ImportVocabTokenManager tm;
tm = (ImportVocabTokenManager)super.clone();
tm.filename = this.filename;
tm.grammar = this.grammar;
return tm;
| public void | define(persistence.antlr.TokenSymbol ts)define a token.
super.define(ts);
| public void | define(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 boolean | isReadOnly()importVocab token manager is read-only if output would be same as input
return readOnly;
| public int | nextTokenType()Get the next unused token type.
return super.nextTokenType();
|
|