[antlr-interest] Status of Ruby binding?

Clifford Heath clifford.heath at gmail.com
Tue Oct 16 05:42:29 PDT 2007


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

This is looking like a bug in ANTLR, not just in the Ruby bindings.
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