Search in sources :

Example 1 with FAFactory

use of org.antlr.works.visualization.fa.FAFactory 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;
}
Also used : GGraph(org.antlr.works.visualization.graphics.graph.GGraph) ArrayList(java.util.ArrayList) FAFactory(org.antlr.works.visualization.fa.FAFactory) NFAState(org.antlr.analysis.NFAState) FAState(org.antlr.works.visualization.fa.FAState) NFAState(org.antlr.analysis.NFAState) List(java.util.List) ArrayList(java.util.ArrayList) GGraphGroup(org.antlr.works.visualization.graphics.graph.GGraphGroup)

Example 2 with FAFactory

use of org.antlr.works.visualization.fa.FAFactory 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;
}
Also used : FAState(org.antlr.works.visualization.fa.FAState) NFAState(org.antlr.analysis.NFAState) GGraph(org.antlr.works.visualization.graphics.graph.GGraph) FAFactory(org.antlr.works.visualization.fa.FAFactory) NFAState(org.antlr.analysis.NFAState)

Aggregations

NFAState (org.antlr.analysis.NFAState)2 FAFactory (org.antlr.works.visualization.fa.FAFactory)2 FAState (org.antlr.works.visualization.fa.FAState)2 GGraph (org.antlr.works.visualization.graphics.graph.GGraph)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GGraphGroup (org.antlr.works.visualization.graphics.graph.GGraphGroup)1