[antlr-interest] public final void mFOO() in lexers?
Gavin Lambert
antlr at mirality.co.nz
Thu Mar 20 14:59:26 PDT 2008
At 03:58 21/03/2008, Kenneth Domino wrote:
>I was looking at the code generated for lexers and I noticed
that
>token type rules are translated into public routines, not
private.
>I understand why rules are public in parsers, and why mTokens()
>is public. But, I don't understand why this is the case for the
>rest of the token rules in the lexer. Is there a reason why,
>maybe to influence the lexing by selecting some subset of rules?
I don't know if this is the real reason, but having them public is
useful for unit tests. You can then do testing both at the
individual rule level ("assuming we already know this is the right
token, can it match all the right input we want?") as well as the
complete input level ("given this entire input stream, does it
generate the right sequence of tokens?").
The ANTLR grammar does let you specify "private", "protected", or
"public" on a rule. I'm not sure if it actually uses that in the
code generation or not, but if you really wanted private rules you
could give it a try.
More information about the antlr-interest
mailing list