FileDocCategorySizeDatePackage
ParseTreeRule.javaAPI DocGlassfish v2 API1798Wed Feb 08 12:30:56 GMT 2006persistence.antlr

ParseTreeRule

public class ParseTreeRule extends ParseTree

Fields Summary
public static final int
INVALID_ALT
protected String
ruleName
protected int
altNumber
Constructors Summary
public ParseTreeRule(String ruleName)

  // unused until I modify antlr to record this

	   
		this(ruleName,INVALID_ALT);
	
public ParseTreeRule(String ruleName, int altNumber)

		this.ruleName = ruleName;
		this.altNumber = altNumber;
	
Methods Summary
protected intgetLeftmostDerivation(java.lang.StringBuffer buf, int step)
Do a step-first walk, building up a buffer of tokens until you've reached a particular step and print out any rule subroots insteads of descending.

		int numReplacements = 0;
		if ( step<=0 ) {
			buf.append(' ");
			buf.append(toString());
			return numReplacements;
		}
		AST child = getFirstChild();
		numReplacements = 1;
		// walk child printing them out, descending into at most one
		while ( child!=null ) {
			if ( numReplacements>=step || child instanceof ParseTreeToken ) {
				buf.append(' ");
				buf.append(child.toString());
			}
			else {
				// descend for at least one more derivation; update count
				int remainingReplacements = step-numReplacements;
				int n = ((ParseTree)child).getLeftmostDerivation(buf,
																 remainingReplacements);
				numReplacements += n;
			}
			child = child.getNextSibling();
		}
		return numReplacements;
	
public java.lang.StringgetRuleName()

		return ruleName;
	
public java.lang.StringtoString()

		if ( altNumber==INVALID_ALT ) {
			return '<"+ruleName+'>";
		}
		else {
			return '<"+ruleName+"["+altNumber+"]>";
		}