Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/org/clafer/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ public static void main(String[] args) throws Exception {
accepts( "n", "Specify the maximum number of instances." ).withRequiredArg().ofType( Integer.class );
accepts( "noprint", "Don't print the instances to the console or a file");
accepts( "output", "Output instances to the given file." ).withRequiredArg().ofType( File.class ).describedAs( "text file" );
accepts( "plantuml", "Print the clafer model as PlantUML" );
accepts( "prettify", "Use simple and pretty output format (not formal)." );
accepts( "sysml", "Print the instances as SysMLv2" );
accepts( "repl", "Run in REPL (interactive) mode." );
accepts( "scope", "Override the default global scope value." ).withRequiredArg().ofType( Integer.class );
accepts( "search", "PreferSmallerInstances/PreferLargerInstances/Random" ).withRequiredArg().ofType( ClaferSearchStrategy.class );
accepts( "sysml", "Print the instances as SysMLv2" );
accepts( "time", "Time how long it takes to find all instances (and print if it is turned on");
accepts( "v", "Run in validation mode; checks all assertions." );
accepts( "version", "Display the tool version" );
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/org/clafer/cli/Normal.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.clafer.objective.Objective;
import org.clafer.scope.Scope;
import org.clafer.ast.AstModel;
import org.plantuml.ast.PlantumlProgram;
import org.plantuml.compiler.AstPlantumlCompiler;
import org.plantuml.pprinter.PlantumlPrinter;
import org.sysml.ast.SysmlProperty;
import org.sysml.ast.SysmlPropertyDef;
import org.sysml.compiler.AstSysmlCompiler;
Expand Down Expand Up @@ -45,16 +48,33 @@ public static void runNormal(JavascriptFile javascriptFile, OptionSet options,
int index = 0; // instance id
boolean prettify = options.has("prettify");
boolean sysml = options.has("sysml");
boolean plantuml = options.has("plantuml");
boolean printOff = options.has("noprint");
boolean dataTackingOn = options.has("dataFile");
boolean timeOn = options.has("time");

// check for conflicting options
if (plantuml && sysml) {
System.err.println("Bad CLI config: both plantuml and sysml are selected");
return;
}

File dataFile;
PrintStream dataStream = null;
if (dataTackingOn) {
dataFile = (File) options.valueOf("dataFile");
dataStream = new PrintStream(dataFile);
}

if (plantuml) {
AstModel top = javascriptFile.getModel();
AstPlantumlCompiler compiler = new AstPlantumlCompiler();
PlantumlProgram prog = compiler.compile(top);
PlantumlPrinter pprinter = new PlantumlPrinter(outStream);
pprinter.visit(prog, "");
return;
}

double elapsedTime;

long startTime = System.nanoTime();
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/plantuml/ast/PlantumlConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.plantuml.ast;

public class PlantumlConnection {
}
16 changes: 16 additions & 0 deletions src/main/java/org/plantuml/ast/PlantumlExpr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.plantuml.ast;

import java.io.IOException;

public interface PlantumlExpr {
/**
* Dynamic dispatch on the visitor.
*
* @param <A> the parameter type
* @param <B> the return type
* @param visitor the visitor
* @param a the parameter
* @return the return value
*/
<A, B> B accept(PlantumlExprVisitor<A, B> visitor, A a) throws IOException;
}
13 changes: 13 additions & 0 deletions src/main/java/org/plantuml/ast/PlantumlExprVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.plantuml.ast;

import java.io.IOException;

/**
* AST Visitor
*
* We make AST visitors capable of throwing IOExecptions as it's convenient for pretty printers
* However, we could likely get rid of this throw some type of interface conversion.
*/
public interface PlantumlExprVisitor<A, B> {
B visit(PlantumlProgram plantumlProgram, A a) throws IOException;
}
10 changes: 10 additions & 0 deletions src/main/java/org/plantuml/ast/PlantumlId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.plantuml.ast;

public interface PlantumlId {
/**
* PlantUML <language-identifier>
*
* @return the name of the identifier
*/
String getName();
}
4 changes: 4 additions & 0 deletions src/main/java/org/plantuml/ast/PlantumlObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.plantuml.ast;

public class PlantumlObject {
}
25 changes: 25 additions & 0 deletions src/main/java/org/plantuml/ast/PlantumlProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.plantuml.ast;

import org.sysml.ast.SysmlExpr;
import org.sysml.ast.SysmlExprVisitor;

import java.io.IOException;

/**
* Main PlantUML Program Element
*
* This is likely quite wrong. For our use case, we consider a PlantUML program as a collection
* of objects and connections.
*/
public class PlantumlProgram implements PlantumlExpr {
private PlantumlObject[] objects;
private PlantumlConnection[] connections;

public PlantumlProgram() {
}

@Override
public <A, B> B accept(PlantumlExprVisitor<A, B> visitor, A a) throws IOException {
return visitor.visit(this, a);
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/plantuml/ast/PlantumlProperty.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.plantuml.ast;

public class PlantumlProperty {
}
16 changes: 16 additions & 0 deletions src/main/java/org/plantuml/compiler/AstPlantumlCompiler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.plantuml.compiler;

import org.clafer.ast.AstModel;
import org.plantuml.ast.PlantumlProgram;

/**
* Clafer AST to PlantUML
*
* Note that this compilation doesn't require instances, so we don't need to run the solver
* to compile.
*/
public class AstPlantumlCompiler {
public PlantumlProgram compile(AstModel model) {
return new PlantumlProgram();
}
}
29 changes: 29 additions & 0 deletions src/main/java/org/plantuml/pprinter/PlantumlPrinter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.plantuml.pprinter;

import org.plantuml.ast.PlantumlExprVisitor;
import org.plantuml.ast.PlantumlProgram;

import java.io.IOException;

/**
* PlantUML -> Text
*
* Visits the PlantUML AST and generates text output to an Appendable stream
*/
public class PlantumlPrinter implements PlantumlExprVisitor<String, Void> {
private final String indentBase;
private final Appendable out;

public PlantumlPrinter(Appendable out) {
this.out = out;
this.indentBase = " ";
}

// implement the visitor
@Override
public Void visit(PlantumlProgram ast, String indent) throws IOException {
this.out.append(indent).append("@startuml").append("\n");
this.out.append(indent).append("@enduml").append("\n");
return null;
}
}