use of org.antlr.works.visualization.graphics.graph.GGraph in project antlrworks by antlr.
the class GFactory method buildGraphGroup.
private GGraphGroup buildGraphGroup(Grammar grammar, GrammarError error) {
// Create one GGraph for each error rules
List<GGraph> graphs = new ArrayList<GGraph>();
FAFactory factory = new FAFactory(grammar);
for (String rule : error.rules) {
NFAState startState = grammar.getRuleStartState(rule);
FAState state = factory.buildNFA(startState, optimize);
GGraph graph = renderer.render(state);
graph.setName(rule);
graphs.add(graph);
}
// Add only graphs that are referenced by at least one error path.
// For example, the statement rule of the java.g grammar produces
// states that do not exist in the graph (they are after the accepted state
// and are ignored by the FAFactory)
GGraphGroup gg = new GGraphGroup();
for (GGraph graph : graphs) {
if (graph.containsAtLeastOneState(error.states))
gg.add(graph);
}
// Attach all error paths to the GGraphGroup
for (int i = 0; i < error.paths.size(); i++) {
List states = error.paths.get(i);
Boolean disabled = error.pathsDisabled.get(i);
try {
gg.addPath(states, disabled, factory.getSkippedStatesMap());
} catch (Exception e) {
if (console == null)
e.printStackTrace();
else
console.println(e);
}
}
// Attach all unreacheable alts to the GGraphGroup
for (Object[] unreachableAlt : error.unreachableAlts) {
gg.addUnreachableAlt((NFAState) unreachableAlt[0], (Integer) unreachableAlt[1]);
}
if (error.paths.size() > 0)
gg.getPathGroup().setPathVisible(0, true);
return gg;
}
use of org.antlr.works.visualization.graphics.graph.GGraph in project antlrworks by antlr.
the class GFactory method buildGraphsForRule.
public GGraph buildGraphsForRule(ANTLRGrammarEngine antlrEngineGrammar, String rule) throws Exception {
NFAState startState = antlrEngineGrammar.getRuleStartState(rule);
if (startState == null)
return null;
FAState state = new FAFactory(antlrEngineGrammar.getGrammarForRule(rule)).buildNFA(startState, optimize);
GGraph graph = renderer.render(state);
graph.setName(rule);
return graph;
}
use of org.antlr.works.visualization.graphics.graph.GGraph in project antlrworks by antlr.
the class SDGenerator method renderRuleToEPSFile.
public void renderRuleToEPSFile(String ruleName, String file) throws Exception {
GGraph graph = createGraph(ruleName);
GEnginePS engine = new GEnginePS();
context.setEngine(engine);
graph.draw();
XJUtils.writeStringToFile(engine.getPSText(), file);
}
use of org.antlr.works.visualization.graphics.graph.GGraph in project antlrworks by antlr.
the class SDGenerator method createGraph.
private GGraph createGraph(String ruleName) throws Exception {
GGraph graph = new GFactory().buildGraphsForRule(engine.getANTLRGrammarEngine(), ruleName);
graph.setContext(context);
graph.render(0, 0);
return graph;
}
use of org.antlr.works.visualization.graphics.graph.GGraph in project antlrworks by antlr.
the class SDGenerator method serializeRule.
public void serializeRule(String name, SEncoder encoder) throws Exception {
GGraph graph = createGraph(name);
encoder.write(graph);
}
Aggregations