[antlr-interest] The problem of return struct
Gavin Lambert
antlr at mirality.co.nz
Mon Dec 1 03:03:57 PST 2008
At 20:47 1/12/2008, chain one wrote:
>entity_id returns [String eid]
>@init{ eid=null; }
> : { isFirst }? id=IDENT { eid=id.getText();
> /*addId(eid,ENTITY_IDENT);*/ }-> ^(ENTITY_ID[] $id)
> | id2=ENTITY_IDENT {
> eid=id2.getText();$id2.setType(IDENT);} -> ^(ENTITY_IDENT[] $id2)
> ;
>
>variable eid would be undefined when compiling the generated Java
>code.
[...]
>I am looking for a method that could avoid this kind of problem
>(not modify the Java code directly : ) )
Whenever you refer to a label, parameter, rule, or return value
(something defined in ANTLR space) in a code fragment, you need to
use $.
So using $eid will solve your problem.
(And instead of using id.getText() etc, you should be using
$id.text.)
More information about the antlr-interest
mailing list