[antlr-interest] Can't get += working

Mike Arace mikearace at hotmail.com
Sun Nov 18 23:08:51 PST 2007


Hi guys,

I'm running into a problem with Antlr involving the List += syntax.

Say I have the following example rules:  

//------------------------

buildList : 'PROPERTY' 'LIST' 'IS' prop+=listObject (',' prop+=listObject )*;

listObject returns [String name, String value] : n=ObjectName '=' v=StringLiteral { $name = $n.text; $value = $v.text; }

StringLiteral :  '\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )*;

ObjectName : ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' | '0'..'9' | '_' )*;
  

//-------------------------

Using the Java target, Antlr creates a static class called listObject_return that wraps the two return values of the listObjectRule, as well as a StringTemplate.  For the buildList rule, it creates a List called list_prop to hold the listObject values assigned using the += syntax, and a temporary variable called prop that holds the current value as it parses each of the elements.  

My problem is this:

I assume that each of the elements of list_prop would be of type listObject_return, but that is not the case.  Instead, it creates a new listObject_return and correctly assigns the name and value properties within the listObject rule, and then runs prop.getTemplate() within buildList and adds that value to list_prop.  In my rule, this value is always null.

Given the rules above, how could I access name and value in listObject_return  object from within buildList? 

Best Regards,
Mike

_________________________________________________________________
Share life as it happens with the new Windows Live.Download today it's FREE!
http://www.windowslive.com/share.html?ocid=TXT_TAGLM_Wave2_sharelife_112007
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20071119/48b8d937/attachment.html 


More information about the antlr-interest mailing list