1 package persistence.antlr; 2 3 8 9 import java.io.*; 10 import java.util.Hashtable ; 11 import java.util.Enumeration ; 12 13 import persistence.antlr.collections.impl.Vector; 14 15 16 class ImportVocabTokenManager extends SimpleTokenManager implements Cloneable { 17 private String filename; 18 protected Grammar grammar; 19 20 ImportVocabTokenManager(Grammar grammar, String filename_, String name_, Tool tool_) { 23 super(name_, tool_); 25 26 this.grammar = grammar; 27 this.filename = filename_; 28 29 File grammarFile = new File(filename); 33 34 if (!grammarFile.exists()) { 35 grammarFile = new File(antlrTool.getOutputDirectory(), filename); 36 37 if (!grammarFile.exists()) { 38 antlrTool.panic("Cannot find importVocab file '" + filename + "'"); 39 } 40 } 41 42 setReadOnly(true); 43 44 try { 46 Reader fileIn = new BufferedReader(new FileReader(grammarFile)); 47 ANTLRTokdefLexer tokdefLexer = new ANTLRTokdefLexer(fileIn); 48 ANTLRTokdefParser tokdefParser = new ANTLRTokdefParser(tokdefLexer); 49 tokdefParser.setTool(antlrTool); 50 tokdefParser.setFilename(filename); 51 tokdefParser.file(this); 52 } 53 catch (FileNotFoundException fnf) { 54 antlrTool.panic("Cannot find importVocab file '" + filename + "'"); 55 } 56 catch (RecognitionException ex) { 57 antlrTool.panic("Error parsing importVocab file '" + filename + "': " + ex.toString()); 58 } 59 catch (TokenStreamException ex) { 60 antlrTool.panic("Error reading importVocab file '" + filename + "'"); 61 } 62 } 63 64 public Object clone() { 65 ImportVocabTokenManager tm; 66 tm = (ImportVocabTokenManager)super.clone(); 67 tm.filename = this.filename; 68 tm.grammar = this.grammar; 69 return tm; 70 } 71 72 73 public void define(TokenSymbol ts) { 74 super.define(ts); 75 } 76 77 78 public void define(String s, int ttype) { 79 TokenSymbol ts = null; 80 if (s.startsWith("\"")) { 81 ts = new StringLiteralSymbol(s); 82 } 83 else { 84 ts = new TokenSymbol(s); 85 } 86 ts.setTokenType(ttype); 87 super.define(ts); 88 maxToken = (ttype + 1) > maxToken ? (ttype + 1) : maxToken; } 90 91 92 public boolean isReadOnly() { 93 return readOnly; 94 } 95 96 97 public int nextTokenType() { 98 return super.nextTokenType(); 99 } 100 } 101 | Popular Tags |