1 package antlr; 2 3 9 10 import antlr.collections.impl.BitSet; 11 12 class DefaultToolErrorHandler implements ToolErrorHandler { 13 CharFormatter javaCharFormatter = new JavaCharFormatter(); 14 15 20 private void dumpSets(Grammar grammar, 21 boolean lexicalAnalysis, 22 int depth, 23 Lookahead[] sets, 24 String linePrefix) { 25 for (int i = 1; i <= depth; i++) { 26 System.out.print(linePrefix + "\tk==" + i + ":"); 27 if (lexicalAnalysis) { 28 String bits = sets[i].fset.toStringWithRanges(",", javaCharFormatter); 29 if (sets[i].containsEpsilon()) { 30 System.out.print("<end-of-token>"); 31 if (bits.length() > 0) { 32 System.out.print(","); 33 } 34 } 35 System.out.println(bits); 36 } 37 else { 38 System.out.println(sets[i].fset.toString(",", grammar.tokenManager.getVocabulary())); 39 } 40 } 41 } 42 43 51 public void warnAltAmbiguity(Grammar grammar, 52 AlternativeBlock blk, 53 boolean lexicalAnalysis, 54 int depth, 55 Lookahead[] sets, 56 int altIdx1, 57 int altIdx2) { 58 String fileline = FileLineFormatter.getFormatter().getFormatString(grammar.getFilename(), blk.getLine(), blk.getColumn()); 59 if (blk instanceof RuleBlock && ((RuleBlock)blk).isLexerAutoGenRule()) { 60 System.out.print("warning: lexical nondeterminism between rules "); 61 Alternative ai = blk.getAlternativeAt(altIdx1); 62 Alternative aj = blk.getAlternativeAt(altIdx2); 63 RuleRefElement rri = (RuleRefElement)ai.head; 64 RuleRefElement rrj = (RuleRefElement)aj.head; 65 String ri = CodeGenerator.reverseLexerRuleName(rri.targetRule); 66 String rj = CodeGenerator.reverseLexerRuleName(rrj.targetRule); 67 System.out.println(ri + " and " + rj + " upon"); 68 dumpSets(grammar, lexicalAnalysis, depth, sets, fileline); 69 return; 70 } 71 System.out.println( 72 fileline + "warning: " + 74 (lexicalAnalysis ? "lexical " : "") + "nondeterminism upon" 75 ); 76 dumpSets(grammar, lexicalAnalysis, depth, sets, fileline); 77 System.out.println(fileline + "\tbetween alts " + (altIdx1 + 1) + " and " + (altIdx2 + 1) + " of block"); 78 } 79 80 87 public void warnAltExitAmbiguity(Grammar grammar, 88 BlockWithImpliedExitPath blk, 89 boolean lexicalAnalysis, 90 int depth, 91 Lookahead[] sets, 92 int altIdx 93 ) { 94 String fileline = FileLineFormatter.getFormatter().getFormatString(grammar.getFilename(), blk.getLine(), blk.getColumn()); 95 System.out.println( 96 fileline + "warning: " + 98 (lexicalAnalysis ? "lexical " : "") + "nondeterminism upon" 99 ); 100 dumpSets(grammar, lexicalAnalysis, depth, sets, fileline); 101 System.out.println(fileline + "\tbetween alt " + (altIdx + 1) + " and exit branch of block"); 102 } 103 } 104
| Popular Tags
|