I don't want antlr's generated classes and methods exposed to the public API.
There's a 6-year old answer Antlr generated classes access modifier to internal. But I hope there's a more modern and true way to do it.
I don't want antlr's generated classes and methods exposed to the public API.
There's a 6-year old answer Antlr generated classes access modifier to internal. But I hope there's a more modern and true way to do it.
AFAIK, you can't. You could use the superClass
option in the grammar so that you extend a custom parser class where you define only those methods you want to be public:
grammar T;
options {
superClass=MyParser;
}
parse
: id+ EOF
;
id
: ID
;
ID
: [a-zA-Z] [a-zA-Z0-9_]*
;
and your MyParser
class could look like this:
public abstract class MyParser extends Parser {
public MyParser(TokenStream input) {
super(input);
}
abstract TParser.ParseContext parse() throws RecognitionException;
}
and then instantiate your parser like this:
TLexer lexer = new TLexer(CharStreams.fromString("foo"));
MyParser parser = new TParser(new CommonTokenStream(lexer));
parser.parse(); // OK
parser.id(); // No can do
but I need to actually hide the whole class. This class should be internal, it's being called in inner methods in the lib
That is not something you can do AFAIK. You'll have to add that yourself with some post-build script (simple search/replace), I think.