}
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);