[antlr-interest] Avoiding the generation of final methods
"Paul Bouché (NSN)"
paul.bouche at nsn.com
Thu Apr 16 09:12:55 PDT 2009
Sam Barnett-Cormack schrieb:
> Patrick Schönbach wrote:
>
>> On 16.04.2009 17:29, Sam Barnett-Cormack wrote:
>>
>>> Why do you want the parse methods to be non-final? You can subclass
>>> the lexer/parser as long as the *class* isn't final. You just can't
>>> override the final methods, and it's probably not a great idea to be
>>> overriding the actual parse methods themselves.
>>>
>> For example, think of a parser that adds location info.
>>
>
> What do you mean by "location info"?
>
> Sam
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
In the past I would have liked the same, but.... As a workaround you
could add for each parser method an @init and @after which calls some
custom added methods (in the @members section) which are non-final, have
some default behavior and can be overriden in a subclass of a parser. I
think this is the closest you can get to "overriden parser methods"
out-of-the-box. And also some action methods.
I.e. with Java-target
@members {
public void fooInit() { }
public void fooAfter() { }
public void fooBAR() { }
}
foo
@init {
fooInit();
}
@after {
fooAfter();
}
:
BAR { fooBAR(); }
;
--
Paul Bouché
Voice: +49 30 590080-1284
Nokia Siemens Networks GmbH & Co. KG, An den Treptowers 1, 12435 Berlin, Germany
Sitz der Gesellschaft: München / Registered office: Munich
Registergericht: München / Commercial registry: Munich, HRA 88537
WEEE-Reg.-Nr.: DE 52984304
Persönlich haftende Gesellschafterin / General Partner: Nokia Siemens Networks Management GmbH
Geschäftsleitung / Board of Directors: Lydia Sommer, Olaf Horsthemke
Vorsitzender des Aufsichtsrats / Chairman of supervisory board: Lauri Kivinen
Sitz der Gesellschaft: München / Registered office: Munich
Registergericht: München / Commercial registry: Munich, HRB 163416
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090416/d24f506f/attachment.html
More information about the antlr-interest
mailing list