[antlr-interest] TestRig: use with package-ized lexer/parser?

Terence Parr parrt at cs.usfca.edu
Mon Nov 12 10:53:13 PST 2012


I assume you have tried TestRig pack.Grammar?   I don't remember if I thought of this so it might not work but I can't see why not. Should be a trivial string concatenation fix. I will look at the other things as well.
T
On Nov 11, 2012, at 9:03 PM, Graham Wideman wrote:

> Hi Terr and all,
> 
> I've been attempting to use the TestRig (part of the ANTLR 4 tools), and have fallen down a hole that I'm hoping someone just knows the answer to.
> 
> The short version is this:
> 
> How does one use TestRig with a grammar that specifies a package for the lexer/parser?
> 
> Longer version:
> 
> In the command line for TestRig we supply the name of the grammar, from which the TestRig class figures out the name of lexer and parser classes to dynamically load (using a ClassLoader).  But TestRig fails to find the lexer/grammar classes if the grammar specifies a package.
> 
> Issue 1: How to load package-ized lexer?
> -----------------------------------------
> TestRig fails if the grammar specifies a package name. Or at least, I've not figured out how to get TestRig to find the lexer and parser classes when a package is specified. Any clues?
> 
> Issue 2: Why does TestRig find lexer class in current dir?
> -----------------------------------------------------------
> I attempted to create my own version of TestRig (with new name TestRig2, and using different package from the original) and though I can get it to compile and run, I can't get it to load even a non-packaged lexer... that is I can't even get my seemingly minimally modified TestRig2 to load a lexer class that the original TestRig is fine with.
> 
> Now it seems that in the original TestRig, the ClassLoader (from Thread.currentThread)getContextClassLoader) is able to find the (unpackaged) lexer class in the "current directory"... but I don't understand why it can do this -- how is it that it treats current dir as on the classpath?
> 
> Any clues on this?
> 
> Issue 3: TestRig exception improvement suggestion
> --------------------------------------------------
> A note for Terr: The exception handling around the class loading is a bit hosed up -- the second attempt at loading (without Lexer suffix) is in the catch block, but this may fail, in which case execution bails with an unhandled exception, instead of proceeding with lexerClass == null to the intended "Can't handle" message.
> 
> Thanks!
> 
> -- Graham 
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list