I want to generate an antlr lexer at runtime -- that is, generate the grammar and from the grammar generate the lexer class, and its supporting bits at runtime. I am happy to fe
You'll have to use org.antlr.Tool()
class to get it working.
You can check ANTLRWorks source code on github to have an idea how to use it, specifically the generate()
method here:
ErrorListener el = ErrorListener.getThreadInstance();
ErrorManager.setErrorListener(el);
String[] params;
if(debug)
params = new String[] { "-debug", "-o", getOutputPath(), "-lib", window.getFileFolder(), window.getFilePath() };
else
params = new String[] { "-o", getOutputPath(), "-lib", window.getFileFolder(), window.getFilePath() };
new File(getOutputPath()).mkdirs();
Tool antlr = new Tool(Utils.concat(params, AWPrefs.getANTLR3Options()));
antlr.process();
boolean success = !el.hasErrors();
if(success) {
dateOfModificationOnDisk = window.getDocument().getDateOfModificationOnDisk();
}
lastError = el.getFirstErrorMessage();
el.clear();
ErrorManager.removeErrorListener();
return success;