Search in sources :

Example 1 with GGraph

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

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

Example 3 with GGraph

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);
}
Also used : GGraph(org.antlr.works.visualization.graphics.graph.GGraph)

Example 4 with GGraph

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;
}
Also used : GGraph(org.antlr.works.visualization.graphics.graph.GGraph)

Example 5 with GGraph

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);
}
Also used : GGraph(org.antlr.works.visualization.graphics.graph.GGraph)

Aggregations

GGraph (org.antlr.works.visualization.graphics.graph.GGraph)7 ArrayList (java.util.ArrayList)2 NFAState (org.antlr.analysis.NFAState)2 FAFactory (org.antlr.works.visualization.fa.FAFactory)2 FAState (org.antlr.works.visualization.fa.FAState)2 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 List (java.util.List)1 GGraphGroup (org.antlr.works.visualization.graphics.graph.GGraphGroup)1 GNode (org.antlr.works.visualization.graphics.shape.GNode)1