FileDocCategorySizeDatePackage
DefaultToolErrorHandler.javaAPI DocGlassfish v2 API4340Wed Aug 30 15:34:06 BST 2006persistence.antlr

DefaultToolErrorHandler

public class DefaultToolErrorHandler extends Object implements ToolErrorHandler

Fields Summary
private final Tool
antlrTool
CharFormatter
javaCharFormatter
Constructors Summary
DefaultToolErrorHandler(Tool tool)

		antlrTool = tool;
	
Methods Summary
private voiddumpSets(java.lang.String[] output, int outputStartIndex, persistence.antlr.Grammar grammar, boolean lexicalAnalysis, int depth, persistence.antlr.Lookahead[] sets)
Dump token/character sets to a string array suitable for {@link persistence.antlr.Tool.warning(String[], String, int, int)

param
output The array that will contain the token/character set dump, one element per k (lookahead) value
param
outputStartIndex The index into output that the dump should start at.
param
lexicalAnalysis true for lexical rule
param
depth The depth of the ambiguity
param
sets An array of bitsets containing the ambiguities


	                                                                                                          	 
	   
						   
						   
						   
						   
						    
		StringBuffer line = new StringBuffer(100);
		for (int i = 1; i <= depth; i++) {
			line.append("k==").append(i).append(':");
			if (lexicalAnalysis) {
				String bits = sets[i].fset.toStringWithRanges(",", javaCharFormatter);
				if (sets[i].containsEpsilon()) {
					line.append("<end-of-token>");
					if (bits.length() > 0) {
						line.append(',");
					}
				}
				line.append(bits);
			} else {
				line.append(sets[i].fset.toString(",", grammar.tokenManager.getVocabulary()));
			}
			output[outputStartIndex++] = line.toString();
			line.setLength(0);
		}
	
public voidwarnAltAmbiguity(persistence.antlr.Grammar grammar, persistence.antlr.AlternativeBlock blk, boolean lexicalAnalysis, int depth, persistence.antlr.Lookahead[] sets, int altIdx1, int altIdx2)
Issue a warning about ambiguity between a alternates

param
blk The block being analyzed
param
lexicalAnalysis true for lexical rule
param
depth The depth of the ambiguity
param
sets An array of bitsets containing the ambiguities
param
altIdx1 The zero-based index of the first ambiguous alternative
param
altIdx2 The zero-based index of the second ambiguous alternative

		final StringBuffer line = new StringBuffer(100);
		if (blk instanceof RuleBlock && ((RuleBlock)blk).isLexerAutoGenRule()) {
			Alternative ai = blk.getAlternativeAt(altIdx1);
			Alternative aj = blk.getAlternativeAt(altIdx2);
			RuleRefElement rri = (RuleRefElement)ai.head;
			RuleRefElement rrj = (RuleRefElement)aj.head;
			String ri = CodeGenerator.reverseLexerRuleName(rri.targetRule);
			String rj = CodeGenerator.reverseLexerRuleName(rrj.targetRule);
			line.append("lexical nondeterminism between rules ");
			line.append(ri).append(" and ").append(rj).append(" upon");
		}
		else {
			if (lexicalAnalysis) {
				line.append("lexical ");
			}
			line.append("nondeterminism between alts ");
			line.append(altIdx1 + 1).append(" and ");
			line.append(altIdx2 + 1).append(" of block upon");
		}
		final String [] output = new String [depth + 1];;
		output[0] = line.toString();
		dumpSets(output, 1, grammar, lexicalAnalysis, depth, sets);
		antlrTool.warning(output, grammar.getFilename(), blk.getLine(), blk.getColumn());

	
public voidwarnAltExitAmbiguity(persistence.antlr.Grammar grammar, persistence.antlr.BlockWithImpliedExitPath blk, boolean lexicalAnalysis, int depth, persistence.antlr.Lookahead[] sets, int altIdx)
Issue a warning about ambiguity between an alternate and exit path.

param
blk The block being analyzed
param
lexicalAnalysis true for lexical rule
param
depth The depth of the ambiguity
param
sets An array of bitsets containing the ambiguities
param
altIdx The zero-based index of the ambiguous alternative

		String [] output = new String[depth + 2];
		output[0] = (lexicalAnalysis ? "lexical " : "") + "nondeterminism upon";
		dumpSets(output, 1, grammar, lexicalAnalysis, depth, sets);
		output[depth + 1] = "between alt " + (altIdx + 1) + " and exit branch of block";
		antlrTool.warning(output, grammar.getFilename(), blk.getLine(), blk.getColumn());