1 package persistence.antlr; 2 3 8 9 import persistence.antlr.collections.impl.BitSet; 10 11 class DefaultToolErrorHandler implements ToolErrorHandler { 12 DefaultToolErrorHandler(persistence.antlr.Tool tool) { 13 antlrTool = tool; 14 } 15 private final persistence.antlr.Tool antlrTool; 16 17 CharFormatter javaCharFormatter = new JavaCharFormatter(); 18 19 29 private void dumpSets(String [] output, 30 int outputStartIndex, 31 Grammar grammar, 32 boolean lexicalAnalysis, 33 int depth, 34 Lookahead[] sets) { 35 StringBuffer line = new StringBuffer (100); 36 for (int i = 1; i <= depth; i++) { 37 line.append("k==").append(i).append(':'); 38 if (lexicalAnalysis) { 39 String bits = sets[i].fset.toStringWithRanges(",", javaCharFormatter); 40 if (sets[i].containsEpsilon()) { 41 line.append("<end-of-token>"); 42 if (bits.length() > 0) { 43 line.append(','); 44 } 45 } 46 line.append(bits); 47 } else { 48 line.append(sets[i].fset.toString(",", grammar.tokenManager.getVocabulary())); 49 } 50 output[outputStartIndex++] = line.toString(); 51 line.setLength(0); 52 } 53 } 54 55 63 public void warnAltAmbiguity(Grammar grammar, 64 AlternativeBlock blk, 65 boolean lexicalAnalysis, 66 int depth, 67 Lookahead[] sets, 68 int altIdx1, 69 int altIdx2) 70 { 71 final StringBuffer line = new StringBuffer (100); 72 if (blk instanceof RuleBlock && ((RuleBlock)blk).isLexerAutoGenRule()) { 73 Alternative ai = blk.getAlternativeAt(altIdx1); 74 Alternative aj = blk.getAlternativeAt(altIdx2); 75 RuleRefElement rri = (RuleRefElement)ai.head; 76 RuleRefElement rrj = (RuleRefElement)aj.head; 77 String ri = CodeGenerator.reverseLexerRuleName(rri.targetRule); 78 String rj = CodeGenerator.reverseLexerRuleName(rrj.targetRule); 79 line.append("lexical nondeterminism between rules "); 80 line.append(ri).append(" and ").append(rj).append(" upon"); 81 } 82 else { 83 if (lexicalAnalysis) { 84 line.append("lexical "); 85 } 86 line.append("nondeterminism between alts "); 87 line.append(altIdx1 + 1).append(" and "); 88 line.append(altIdx2 + 1).append(" of block upon"); 89 } 90 final String [] output = new String [depth + 1];; 91 output[0] = line.toString(); 92 dumpSets(output, 1, grammar, lexicalAnalysis, depth, sets); 93 antlrTool.warning(output, grammar.getFilename(), blk.getLine(), blk.getColumn()); 94 95 } 96 97 104 public void warnAltExitAmbiguity(Grammar grammar, 105 BlockWithImpliedExitPath blk, 106 boolean lexicalAnalysis, 107 int depth, 108 Lookahead[] sets, 109 int altIdx 110 ) 111 { 112 String [] output = new String [depth + 2]; 113 output[0] = (lexicalAnalysis ? "lexical " : "") + "nondeterminism upon"; 114 dumpSets(output, 1, grammar, lexicalAnalysis, depth, sets); 115 output[depth + 1] = "between alt " + (altIdx + 1) + " and exit branch of block"; 116 antlrTool.warning(output, grammar.getFilename(), blk.getLine(), blk.getColumn()); 117 } 118 } 119 | Popular Tags |