Generating non-public parser classes with Antlr4

162 views
Skip to first unread message

Jon Chambers

unread,
Aug 20, 2013, 12:00:48 AM8/20/13
to antlr-di...@googlegroups.com
Hi there!

I'm just getting started with Antlr, and I was wondering if there's a way to generate parsers/lexers from an Antlr grammar that aren't public classes by default. My ultimate goal is to write a front-end for the parser as part of a public-facing API, and it would be nice to have the lexer and parser be non-public to avoid any confusion about which "parser" class is actually part of the API.

More concretely, in the grammar-derived source files, I want to change this line:

public class MyParser extends Parser { ... }

to this line:

class MyParser extends Parser { ... }

If there isn't a good way to do that, are the other best practices for managing visibility with respect to generated parsers/lexers?

Thanks kindly!

-Jon

Jon Chambers

unread,
Aug 20, 2013, 11:31:47 PM8/20/13
to antlr-di...@googlegroups.com
I've done some research, and it seems like the only way to do this right now is to modify the template for generated classes. I opened a pull request to add support for generating package-private classes from the command-line tool and from the Maven plugin. Hope somebody out there finds it useful!

-Jon

Terence Parr

unread,
Aug 21, 2013, 4:38:34 PM8/21/13
to antlr-di...@googlegroups.com
Hi. I think we used to have something in v3 that was an option or perhaps a named action like @members. Hmm... Also it seems like we should allow an arbitrary modifier not just public are not public. I.e., protected or private. I see that we have a -D=value option. Maybe we should add an option called visibility or something instead.
Ter


--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Dictation in use. Please excuse homophones, malapropisms, and nonsense. 
Reply all
Reply to author
Forward
0 new messages