[antlr-interest] ANTLR 3.1, headers in imported grammars

Dimitrios Kolovos dskolovos at gmail.com
Wed Jun 18 12:43:23 PDT 2008


Thanks. What I would expect would be that if a sub-grammar doesn't 
specify a header, the header of the top-level grammar is inserted. 
Otherwise, its own header is inserted.

On a remotely related note, I've customized the org.antlr.Tool class for 
my needs so that it supports multiple lib directories (separated by ;) 
so that a grammar can extend a number of sub-grammars located in 
different directories (which is essential for what I'm doing). I'm happy 
to share the modified version if this sounds useful in general.

Cheers,
Dimitrios

Terence Parr wrote:
> added bug to fix for 3.1
>
> http://www.antlr.org:8888/browse/ANTLR-301
>
> Actually, wait.  So we are saying that the header in root grammar 
> should override any in subgrammars?  In this case, there are none so 
> it inserts it?  That will be special case.  @members are not 
> overridden for example.
> Ter
> On Jun 18, 2008, at 5:12 PM, Dimitrios Kolovos wrote:
>
>> In the composite-java example that demonstrates the new "import" 
>> feature of 3.1 none of the parsers/lexers define @header or 
>> @lexer::header and as a result all generated classes do not contain a 
>> package declaration. Now, if I add
>>
>> @header{package demo;}
>>
>> and
>>
>> @lexer::header{package demo;}
>>
>> in Java.g, the JavaLexer and JavaParser contain the "package demo;" 
>> declaration but all the other files that are generated from 
>> sub-grammars (e.g. Java_JavaAnnotations, Java_JavaDecl) do not 
>> contain a package declaration. To add a package declaration to them I 
>> need to go in each sub-grammar and add a @header{package demo;}.
>>
>> Is there a way to get package declarations in files generated by 
>> sub-grammars only by setting @header{}/@lexer::header{} in the 
>> top-level grammar?
>>
>> Cheers,
>> Dimitrios
>
>


More information about the antlr-interest mailing list