Search in sources :

Example 1 with SDGenerator

use of org.antlr.works.visualization.SDGenerator in project antlrworks by antlr.

the class ExportMenu method exportAllRules.

public void exportAllRules(boolean asImage) {
    List<String> extensions = null;
    if (asImage) {
        extensions = lookupAvailableImageFormat();
    }
    if (!XJFileChooser.shared().displayChooseDirectory(window.getJavaContainer(), extensions, extensions, !asImage)) {
        return;
    }
    String directory = XJFileChooser.shared().getSelectedFilePath();
    String extension = XJFileChooser.shared().getSelectedFileExtension();
    SDGenerator sd = new SDGenerator(window.getGrammarEngine());
    for (ElementRule rule : window.getRules()) {
        try {
            if (asImage) {
                sd.renderRuleToBitmapFile(rule.name, extension, XJUtils.concatPath(directory, rule.name + "." + extension));
            } else {
                sd.renderRuleToEPSFile(rule.name, XJUtils.concatPath(directory, rule.name + ".eps"));
            }
        } catch (Exception e) {
            XJAlert.display(window.getJavaContainer(), "Error", "Images cannot be saved because:\n" + e);
        }
    }
}
Also used : SDGenerator(org.antlr.works.visualization.SDGenerator) ElementRule(org.antlr.works.grammar.element.ElementRule) IOException(java.io.IOException)

Example 2 with SDGenerator

use of org.antlr.works.visualization.SDGenerator in project antlrworks by antlr.

the class Console method processSyntaxDiagram.

private void processSyntaxDiagram(ProcessSyntaxDiagramDelegate delegate) throws Exception {
    GrammarEngine engine = new GrammarEngineImpl(new EngineDelegate());
    GrammarSyntaxEngine syntaxEngine = engine.getSyntaxEngine();
    syntaxEngine.setDelegate(new SyntaxDelegate());
    syntaxEngine.processSyntax();
    engine.parserCompleted();
    SDGenerator gen = new SDGenerator(engine);
    delegate.beginProcess();
    for (String name : engine.getRuleNames()) {
        delegate.processRule(name, gen);
    }
    delegate.endProcess();
}
Also used : SDGenerator(org.antlr.works.visualization.SDGenerator) GrammarSyntaxEngine(org.antlr.works.grammar.syntax.GrammarSyntaxEngine) GrammarEngine(org.antlr.works.grammar.engine.GrammarEngine) ATESyntaxEngineDelegate(org.antlr.works.ate.syntax.generic.ATESyntaxEngineDelegate) GrammarEngineDelegate(org.antlr.works.grammar.engine.GrammarEngineDelegate) GrammarEngineImpl(org.antlr.works.grammar.engine.GrammarEngineImpl)

Aggregations

SDGenerator (org.antlr.works.visualization.SDGenerator)2 IOException (java.io.IOException)1 ATESyntaxEngineDelegate (org.antlr.works.ate.syntax.generic.ATESyntaxEngineDelegate)1 ElementRule (org.antlr.works.grammar.element.ElementRule)1 GrammarEngine (org.antlr.works.grammar.engine.GrammarEngine)1 GrammarEngineDelegate (org.antlr.works.grammar.engine.GrammarEngineDelegate)1 GrammarEngineImpl (org.antlr.works.grammar.engine.GrammarEngineImpl)1 GrammarSyntaxEngine (org.antlr.works.grammar.syntax.GrammarSyntaxEngine)1