Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent naming for combined and separated grammars #37

Open
sharwell opened this issue Mar 8, 2012 · 1 comment
Open

Consistent naming for combined and separated grammars #37

sharwell opened this issue Mar 8, 2012 · 1 comment

Comments

@sharwell
Copy link
Member

sharwell commented Mar 8, 2012

Here is the current naming:

Combined

grammar Foo;
  • FooLexer, FooParser
  • FooListener, FooBaseListener
  • FooParseListener, FooBaseParseListener
  • FooVisitor, FooBaseVisitor

Separated

lexer grammar FooLexer;
parser grammar FooParser;
  • FooLexer, FooParser
  • FooParserListener, FooParserBaseListener
  • FooParserParseListener, FooParserBaseParseListener
  • FooParserVisitor, FooParserBaseVisitor

Request

I find that in ANTLR 4 I'm more likely to use separated grammars than combined grammars. However, I wish the names of listeners/visitors generated by the separated grammars to match those of the combined grammar. In particular, if (and only if) a parser grammar is named *Parser, I'd like to drop the Parser suffix as part of deriving the generated file names.

parrt pushed a commit that referenced this issue Jun 30, 2015
Fix syntax of the generated source code (again)
@analog-cbarber
Copy link

analog-cbarber commented Jan 15, 2017

This is particularly annoying if your project starts out with a combined grammar and you later need to convert it to separate lexer/parser grammars. Obviously you can't fix the default behavior without an incompatible change to the generated names, but you could add an option or options to enable some other behavior.

Note that if you name the parser grammar Foo then you get the mostly the same names as in the combined grammar with the exception of the parser class, which is just called Foo instead of FooParser. You can then create a subclass named FooParser to get pretty close to the combined grammar behavior.

Given that the primary problems are going to come about from going from a combined grammar to a split grammar and not the other way around, I think that providing an option to let you specify the name of the parser class might be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants