[antlr-interest] setTreeAdaptor and delegates

Dimitrios Kolovos dskolovos at gmail.com
Fri Jun 20 13:53:13 PDT 2008


Since you asked :) there is another thing related to reuse that may (or 
may) not need be improved.

I need to collect all parse errors generated during parsing (instead of 
just printing them which is the default behaviour). To do that I've 
added a @rulecatch in my top-level grammar and an ArrayList in the 
@members. Again, I'd expect that the @rulecatch would propagate to the 
imported grammars (which is not the case).

Also I hoped that the delegate would have a standard-name field e.g. 
parentParser which I could use to add the errors caught in sub-grammars 
to the ArrayList of the parent parser. I can still do this (again via 
reflection) but it would help if the parent parser had a fixed name in 
the delegate.

Cheers,
Dimitrios

Terence Parr wrote:
> INteresting....i wonder if you'd ever want the delegates to have 
> different tree ctors.
>
> I guess the setTreeAdaptor should announce.  Hmm...i wonder what else 
> falls into same category.  Added:
>
> http://www.antlr.org:8888/browse/ANTLR-302
>
> Ter
> On Jun 20, 2008, at 1:20 PM, Dimitrios Kolovos wrote:
>
>> In the composite grammar (3.1.b) that I'm working on, I need to set 
>> the TreeAdaptor of the generated parser to a custom one. I expected 
>> that setting the TreeAdaptor to the top-level parser would also 
>> propagate it in the delegates but this doesn't seem to be the case.
>>
>> If implementing such a TreeAdaptor-propagating behaviour would be too 
>> much of a problem, it would be nice to at least have a field (e.g. 
>> "delegates") that contains a collection of all the delegates in the 
>> generated parser (in addition to the individual fields) so that one 
>> can implement this propagating behaviour in a recursive manner using 
>> a generic algorithm that doesn't need to know the names of each 
>> delegate. (Such a generic algorithm would also require the 
>> getTreeAdaptor() and setTreeAdaptor() methods to be moved to a core 
>> base-class such as Parser or Base Recognizer)
>
>


More information about the antlr-interest mailing list