use of org.antlr.tool.Rule 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.tool.Rule in project antlrworks by antlr.
the class DecisionDFAEngine method getDecisionDFAItems.
public List<DecisionDFAItem> getDecisionDFAItems() {
List<DecisionDFAItem> items = new ArrayList<DecisionDFAItem>();
for (int lineIndex : decisionDFA.keySet()) {
for (int columnIndex : decisionDFA.get(lineIndex)) {
DFA dfa = getDFAAtPosition(lineIndex, columnIndex);
if (dfa == null) {
System.err.println("DFA is null for line " + lineIndex + " and column " + columnIndex);
continue;
}
Grammar g = discoveredLexerGrammar;
if (g != null) {
Rule r = g.getRule(Grammar.ARTIFICIAL_TOKENS_RULENAME);
NFAState s = (NFAState) r.startState.transition(0).target;
if (s == null) {
System.err.println("NFAState s is null for rule " + r.name);
continue;
}
// Ignore tokens DFA
if (dfa.getDecisionNumber() == s.getDecisionNumber())
continue;
}
Color c = new Color(0, 128, 64);
String title = "DFA decision " + dfa.getDecisionNumber();
String info = "";
if (usesSemPreds.contains(dfa.getDecisionNumber())) {
info += "uses semantic predicate";
c = new Color(255, 220, 0);
} else if (usesSynPreds.contains(dfa.getDecisionNumber())) {
info += "uses syntactic predicate";
c = new Color(255, 220, 0);
}
if (dfa.isCyclic()) {
if (info.length() > 0)
info += ", ";
info += "cyclic";
}
if (info.length() > 0)
info += ", ";
if (dfa.getNumberOfStates() != 0) {
info += dfa.getNumberOfStates() + " states";
} else {
info += "<=" + dfa.getMaxStateNumber() + " states";
}
Point p = window.textEditor.getLineTextPositionsAtLineIndex(lineIndex - 1);
if (p != null) {
DecisionDFAItem item = new DecisionDFAItem(window);
item.setAttributes(null, p.x + columnIndex - 1, p.x + columnIndex, lineIndex - 1, c, title + " (" + info + ")");
item.shape = ATEOverlayManager.SHAPE_RECT;
items.add(item);
}
}
}
return items;
}
Aggregations