1 package persistence.antlr; 2 3 8 9 import java.util.Hashtable ; 10 import java.util.Enumeration ; 11 import java.io.IOException ; 12 13 import persistence.antlr.collections.impl.BitSet; 14 import persistence.antlr.collections.impl.Vector; 15 16 17 class LexerGrammar extends Grammar { 18 protected BitSet charVocabulary; 20 protected boolean testLiterals = true; 22 protected boolean caseSensitiveLiterals = true; 24 25 protected boolean caseSensitive = true; 26 27 protected boolean filterMode = false; 28 29 33 protected String filterRule = null; 34 35 LexerGrammar(String className_, Tool tool_, String superClass) { 36 super(className_, tool_, superClass); 37 charVocabulary = new BitSet(); 38 39 defaultErrorHandler = false; 41 } 42 43 44 public void generate() throws IOException { 45 generator.gen(this); 46 } 47 48 public String getSuperClass() { 49 if (debuggingOutput) 51 return "debug.DebuggingCharScanner"; 52 return "CharScanner"; 53 } 54 55 public boolean getTestLiterals() { 57 return testLiterals; 58 } 59 60 65 public void processArguments(String [] args) { 66 for (int i = 0; i < args.length; i++) { 67 if (args[i].equals("-trace")) { 68 traceRules = true; 69 antlrTool.setArgOK(i); 70 } 71 else if (args[i].equals("-traceLexer")) { 72 traceRules = true; 73 antlrTool.setArgOK(i); 74 } 75 else if (args[i].equals("-debug")) { 76 debuggingOutput = true; 77 antlrTool.setArgOK(i); 78 } 79 } 80 } 81 82 83 public void setCharVocabulary(BitSet b) { 84 charVocabulary = b; 85 } 86 87 88 public boolean setOption(String key, Token value) { 89 String s = value.getText(); 90 if (key.equals("buildAST")) { 91 antlrTool.warning("buildAST option is not valid for lexer", getFilename(), value.getLine(), value.getColumn()); 92 return true; 93 } 94 if (key.equals("testLiterals")) { 95 if (s.equals("true")) { 96 testLiterals = true; 97 } 98 else if (s.equals("false")) { 99 testLiterals = false; 100 } 101 else { 102 antlrTool.warning("testLiterals option must be true or false", getFilename(), value.getLine(), value.getColumn()); 103 } 104 return true; 105 } 106 if (key.equals("interactive")) { 107 if (s.equals("true")) { 108 interactive = true; 109 } 110 else if (s.equals("false")) { 111 interactive = false; 112 } 113 else { 114 antlrTool.error("interactive option must be true or false", getFilename(), value.getLine(), value.getColumn()); 115 } 116 return true; 117 } 118 if (key.equals("caseSensitive")) { 119 if (s.equals("true")) { 120 caseSensitive = true; 121 } 122 else if (s.equals("false")) { 123 caseSensitive = false; 124 } 125 else { 126 antlrTool.warning("caseSensitive option must be true or false", getFilename(), value.getLine(), value.getColumn()); 127 } 128 return true; 129 } 130 if (key.equals("caseSensitiveLiterals")) { 131 if (s.equals("true")) { 132 caseSensitiveLiterals = true; 133 } 134 else if (s.equals("false")) { 135 caseSensitiveLiterals = false; 136 } 137 else { 138 antlrTool.warning("caseSensitiveLiterals option must be true or false", getFilename(), value.getLine(), value.getColumn()); 139 } 140 return true; 141 } 142 if (key.equals("filter")) { 143 if (s.equals("true")) { 144 filterMode = true; 145 } 146 else if (s.equals("false")) { 147 filterMode = false; 148 } 149 else if (value.getType() == ANTLRTokenTypes.TOKEN_REF) { 150 filterMode = true; 151 filterRule = s; 152 } 153 else { 154 antlrTool.warning("filter option must be true, false, or a lexer rule name", getFilename(), value.getLine(), value.getColumn()); 155 } 156 return true; 157 } 158 if (key.equals("longestPossible")) { 159 antlrTool.warning("longestPossible option has been deprecated; ignoring it...", getFilename(), value.getLine(), value.getColumn()); 160 return true; 161 } 162 if (super.setOption(key, value)) { 163 return true; 164 } 165 antlrTool.error("Invalid option: " + key, getFilename(), value.getLine(), value.getColumn()); 166 return false; 167 } 168 } 169 | Popular Tags |