antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.14k stars 3.28k forks source link

Is it possible to generate parsers that use classes of other shared parsers? #986

Open gvlasov opened 9 years ago

gvlasov commented 9 years ago

I have a grammar SharedParser.g4 with rules a and b. This grammar is imported to grammars Client1Parser.g4 and Client2Parser.g4 which use these rules.

When antlr generates Java sources for Client{1,2}Parser.g4, each of the parsers define their own types for the shared rules. As a result, there are three types for each of rules a and b:

I expected the client parsers to return types SharedParser.A and SharedParser.B from their methods parser.a() and parser.b(). Is this possible?

sharwell commented 9 years ago

It is not currently possible to do this. There is an outstanding effort to allow some sharing within a single parser (#697), but I'm not aware of any proposal or work to support sharing classing between different parsers.