[antlr-interest] Status of Ruby binding?

Clifford Heath clifford.heath at gmail.com
Wed Oct 17 17:27:11 PDT 2007


Clifford Heath wrote:
> Clifford Heath wrote:
>> rule : ( rule2 '=' )? rule3
>>     { $rule2 may or may not exist here }

I was wrong - confused myself with my mods to the svg file.
$role2 does exist, but may not have been assigned to (which
is fine, it'll be nil). Thanks to Martin Traverso for setting
be straight.

> This is looking like a bug in ANTLR, not just in the Ruby bindings.

This appears to still be true however. Terence, any ideas?
Do you need more information to be able to answer this?

Clifford Heath.

> Looking inside org/antlr/codegen/templates/Ruby/Ruby.stg, I see this:
> 
> ruleLabelDefs() ::= <<
> <ruleDescriptor.tokenLabels :{_<it.label.text> = nil}; separator="\n">
> <[ruleDescriptor.tokenListLabels, ruleDescriptor.ruleListLabels]
>    :{list_<it.label.text> = nil}; separator="\n"
>>
>>>
> 
> which is the Ruby version of the Java.stg's:
> 
> ruleLabelDefs() ::= <<
> <[ruleDescriptor.tokenLabels,ruleDescriptor.tokenListLabels]
>    :{<labelType> <it.label.text>=null;}; separator="\n"
>>
> <[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]
>    :{List list_<it.label.text>=null;}; separator="\n"
>>
> 
> Now with this grammar, the Java version emits the ruleDescriptor's
> tokenLabels just fine, but for the same grammar in Ruby, this
> collection is empty and nothing is emitted. I've edited various
> things into the Ruby version and they get emitted, so I know that
> ruleLabelDefs is being called, but when I add text into this block
> 
> :{_<it.label.text> = nil}
> 
> nothing gets emitted.
> 
> What's happening here? How can the same parser have the tokenLabels
> defined for Java but not for Ruby?
> 
> -- 
> Clifford Heath. A much simplified version of the grammar follows:
> 
> -------------------- Cut Here --------------------
> grammar Bug;
> 
> options {
>        language = Ruby;
> }
> 
> main returns [ret]
> :       ( term '=' )? head body ';'
>                { $ret = [ $term.ret ] }
> ;
> 
> term returns [ret]:     ID { $ret = $ID.text };
> head: ID;
> body: ID;
> ID:     'a'..'z';
> WS:     (' '|'\t'|'\r'|'\n')+ {$channel = 99;};
> 
> 



More information about the antlr-interest mailing list