use of org.antlr.works.grammar.antlr.ANTLRGrammarEngine in project antlrworks by antlr.
the class TokensDFA method getDOTString.
@Override
public String getDOTString() throws Exception {
ANTLRGrammarEngine eg = window.getGrammarEngine().getANTLRGrammarEngine();
eg.analyze();
Grammar g = eg.getLexerGrammar();
if (g == null) {
throw new Exception("Cannot show tokens DFA because there is no lexer grammar");
}
Rule r = g.getRule(Grammar.ARTIFICIAL_TOKENS_RULENAME);
NFAState s = (NFAState) r.startState.transition(0).target;
DFA dfa = g.getLookaheadDFA(s.getDecisionNumber());
DOTGenerator dg = new DOTGenerator(g);
dg.setArrowheadType("none");
// Left-to-right
dg.setRankdir("LR");
return dg.getDOT(dfa.startState);
}
use of org.antlr.works.grammar.antlr.ANTLRGrammarEngine in project antlrworks by antlr.
the class DecisionDFAEngine method discover.
private void discover(int start, int end) throws Exception {
Set<Integer> lineIndexes = new HashSet<Integer>();
for (int index = start; index < end; index++) {
lineIndexes.add(window.getTextEditor().getLineIndexAtTextPosition(index));
}
ANTLRGrammarEngine antlrEngineGrammar = window.getGrammarEngine().getANTLRGrammarEngine();
antlrEngineGrammar.analyze();
discoveredLexerGrammar = antlrEngineGrammar.getLexerGrammar();
discoveredParserGrammar = antlrEngineGrammar.getParserGrammar();
decisionDFA.clear();
usesSynPreds.clear();
usesSemPreds.clear();
discover(discoveredLexerGrammar, lineIndexes, usesSemPreds, usesSynPreds);
discover(discoveredParserGrammar, lineIndexes, usesSemPreds, usesSynPreds);
}
use of org.antlr.works.grammar.antlr.ANTLRGrammarEngine 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