[antlr-interest] ENHANCEMENT - Add option to output tokens as symbolic constants (enum)
Terence Parr
parrt at cs.usfca.edu
Mon Oct 15 19:21:24 PDT 2007
On Oct 15, 2007, at 6:38 PM, Austin Hastings wrote:
> In looking over the gunit source code, I find several lines that
> look like the following:
>
> if ( ts.testSuites.get(input).getType()==27 ) {
> // ...
> }
> else if ( ts.testSuites.get(input).getType()==28 ) {
> // ...
> }
>
> Guess what that does?
>
> One answer, of course, is that it encodes the transient results of
> the token generation process in a way that is disconnected from the
> process, so that if tokens are regenerated (such as by me, trying
> to add some features) the old numbers become meaningless.
>
> Another answer is that it sprinkles magic numbers through the code.
>
> Both answers are considered less than "good" programming practice.
> I understand why it was done, and how to fix it. But I suspect this
> kind of greasy-elbows access of the innards is pretty common,
> especially since Antlr v3 is pretty lax about data hiding.
It's generated code; everything is fair game ;) That said, making it
pretty is a good idea.
Ter
More information about the antlr-interest
mailing list