How do I set up remote debugging anyway?
Remote debugging is enabled for a parser by setting the ANTLR -debug flag (to true) when generating the parser from the grammar.
This has the effect of changing the superclass of the generated parser to subclass DebugParser and inserts various debugging hooks throughout the recursive descent parsing process.
Accordingly the simple driver class to exercise the parser is slightly different.
What is different?
sample.g
grammar sample; example : 'SOME TEXT TO PARSE';
...and a corresponding remote debug driver...
remoteDebugDriver.java
public class RemoteDebugDriver { public static void main(String\[\] args) throws Exception { Â InputStream stream = new ByteArrayInputStream("SOME TEXT TO PARSE".getBytes()); // defaults to ISO-1 ANTLRInputStream inputStream = new ANTLRInputStream(stream); sampleLexer lexer = new sampleLexer( inputStream ); CommonTokenStream tokenStream = new CommonTokenStream(lexer); SampleParser parser = new sampleParser(tokenStream); parser.example(); System.exit(0); } }
This program blocks, waiting for a remote process to connect. From within ANTLRWorks, selecting "Debugger -> Debug Remote", using the default host and port, localhost:49153, allows ANTLRWorks to take control of the remote parsing operation.