use of org.antlr.tool.Interpreter in project antlrworks by antlr.
the class InterpreterTab method process.
protected void process() {
progress.setInfo("Interpreting...");
window.consoleTab.println("Interpreting...");
CharStream input = new ANTLRStringStream(Utils.convertRawTextWithEOL(textPane.getText(), eolCombo));
ANTLRGrammarEngine eg = window.getGrammarEngine().getANTLRGrammarEngine();
try {
eg.createGrammars();
} catch (Exception e) {
window.consoleTab.println(e);
return;
}
Grammar parser = eg.getParserGrammar();
Grammar lexer = eg.getLexerGrammar();
if (lexer == null) {
throw new RuntimeException("Lexer is null. Check the grammar before running the interpreterTab.");
}
Interpreter lexEngine = new CustomInterpreter(lexer, input);
FilteringTokenStream tokens = new FilteringTokenStream(lexEngine);
StringTokenizer tk = new StringTokenizer(tokensToIgnoreLabel.getText(), " ");
while (tk.hasMoreTokens()) {
String tokenName = tk.nextToken();
tokens.setTokenTypeChannel(lexer.getTokenType(tokenName), Token.HIDDEN_CHANNEL);
}
Interpreter parseEngine = new CustomInterpreter(parser, tokens);
ParseTree t = null;
try {
if (ATEToken.isLexerName(startSymbol)) {
t = lexEngine.parse(startSymbol);
} else {
t = parseEngine.parse(startSymbol);
}
} catch (Exception e) {
window.consoleTab.println(e);
}
if (parser != null && t != null) {
SwingUtilities.invokeLater(new Refresh(parser, t));
}
}
Aggregations