[antlr-interest] problem with Terence's preserving token sequence implementation?

Donal Murtagh donalmurtagh at yahoo.co.uk
Wed Dec 7 07:21:22 PST 2005


Hi,

I've been using the approach advocated by TP in:
http://www.antlr.org/article/preserving.token.order/preserving.token.order.tml

in order to preserve the original token sequence in my file. Using the code provided with the
article, I tried to build an AST that tracks the min/max index position of it's children, but I
noticed that on a few occassions the following method in ASTMinMax is throwing a
NullPointerException

public String getText() {   
  return token.getText();
}

I temporarily changed this method to:

public String getText() {   
  if (token == null)
    return "FOO";
  return token.getText();
}

It turns out that each node "FOO" is a node that I am returning "manually" from a rule, e.g. 

parentRule
:	"A_PARENT"!
	LBRACE!
		( processChildren )*
	RBRACE!
	{
		// add this node as the parent of this rule
  		parentRule = #(#[PARENT_TOKEN, "ParentNodeText"], parentRule);
	}
;

I can sort of see why this is causing a problem - because the nodes are not being added in the
"usual" sequence, i.e. the children are processed before the parent node is added.

If anyone knows how to modify this example in order to support nodes added in this fashion, I'd be
grateful if they'd let me know.

Cheers,
Don


		
___________________________________________________________ 
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com


More information about the antlr-interest mailing list