[antlr-interest] Names of generated files and classes

Kay Roepke kroepke at classdump.org
Mon Aug 6 04:15:25 PDT 2007


On Aug 6, 2007, at 12:59 PM, Johannes Luber wrote:

> I've noticed that for separate lexer and parser grammars the generated
> files still attach Lexer and Parser to the class names. As I already
> named mu grammars CSharp3Lexer.g and CSharp3Parser.g, I end up with
> CSharp3LexerLexer and CSharp3ParserParser. My suggestion is to  
> leave the
> grammar names as they are, because the generated files won't have a
> naming conflict.

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

> I've talked with Ter about this and he said that the behaviour wasn't
> changed before because the book was written for the old behaviour
> (actually, I remember an example which showed my suggested  
> behaviour so
> nobody should be surprised. Maybe a editor thought that the source  
> code
> was wrong there.). But as for 3.1 the bets are off.

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...

> 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.

> What are your opionions?

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

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.

bring on the flame war, I'm off to lunch.

cheers,
-k
-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list