[antlr-interest] Names of generated files and classes

Johannes Luber jaluber at gmx.de
Mon Aug 6 06:46:46 PDT 2007


Kay Roepke wrote:
> 
> Here we go again...you do realize that this will go down the "heated
> discussion" path,
> right?

I have been warned, but this is the easiest way to get others' opinions
- and to challenge old assumptions.

> And we couldn't agree what people actually wanted, IIRC. This has been
> the case with
> grammar file suffixes, too. Annoying. We eventually ended up at the
> starting point...

Wait a minute. It should be clear what people want - at least on the
mailing list. After all they tell it. And if they tell it after the
discussion has ended, then either they change their way or the tool
becomes more flexible. And speculating, what non-participating people
could maybe need, should result in "keeping our options open" or have
none influence at all. After all it can be safely assumed that important
requirements would be voiced. (Of course, this excludes the question if
that, what people want, is also that, what people need.)
> 
>> The biggest question is how much the existing code would break. I rename
>> the generated files and classes every time because I can't stand the
>> names aesthetically. In my case no code would break. Other people will
>> have to rename the types in their rigs or add Lexer and Parser to the
>> grammar names. Both are one time operations and done via Search&Replace
>> (if necessary at all) so it isn't a big deal.
> 
> In some cases the names actually propagate further than that, but that's
> target
> specific, I guess (at least for ObjC this is the case - this has to do
> with the
> token name defines and name of rule return values' classes).
> But I agree that "getting it right" should have priority.

Wouldn't a regeneration propagate the right names? Or does client code
access those internals?

> A sensible default (such as it is now, IMHO) plus the ability to specify
> the output filename,
> that's my opinion. I envision a grammar level option that gives ANTLR
> the name of the file(s)
> to generate.
> I think I have made this suggestion earlier, but I don't remember the
> reaction. Probably it
> wasn't received so well, since it never made it into the tool.
> Previously there has been concern with tools not being able to figure
> out the generated file names,
> but since we have the -depend option nowadays, that's covered.
> 
> So my suggestion still stands:
> grammar Name; generates NameLexer, NameParser
> lexer grammar Name; generates Name
> parser grammar Name; generates Name
> treeparser grammar Name; generates Name

So far it is like mine.

> add an option to the grammar:
> 
> grammar Name;
> options {
>     lexer::filename=NameTokenizer;
>     // parser::filename may be omitted and defaults to NameParser
> }
> 
> lexer grammar NameLexer;
> options {
>     filename=NameLexer;    // output filename not NameLexerLexer!
> lexer:: prefix may be omitted
> }
> 
> and so on.

I have nothing against that additional option. May be certainly useful
at times.

Best regards,
Johannes Luber


More information about the antlr-interest mailing list