use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.
the class OurSyntaxWidget method doNav.
private void doNav() {
try {
String text = pane.getText();
int[] sel = getCurrentWordSelection(text);
Pos pos = Pos.toPos(text, sel[0], sel[1]);
if (pos == null)
return;
String currentWord = getCurrentWord();
if (currentWord == null)
return;
CompModule module = getModule();
if (module == null)
return;
Expr expr = module.find(pos);
if (expr != null) {
Clause clause = expr.referenced();
if (clause != null) {
Pos where = clause.pos();
if (where.sameFile(module.pos()))
select(where);
else {
OurSyntaxWidget ow = parent.open(where);
if (ow != null) {
ow.select(where);
}
}
}
}
} catch (Exception e) {
// Ignore, this is a best effort thingy
}
}
use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.
the class OurSyntaxWidget method getTooltip.
public String getTooltip(MouseEvent event) {
try {
int offset = pane.viewToModel(event.getPoint());
CompModule module = getModule();
if (module == null)
return null;
String text = pane.getText();
Pos pos = Pos.toPos(text, offset, offset + 1);
Expr expr = module.find(pos);
if (expr instanceof ExprBad) {
return expr.toString();
}
if (expr != null) {
Clause referenced = expr.referenced();
if (referenced != null) {
String s = referenced.explain();
String table = "<html><pre>" + s + "</pre></html>";
s = table.replaceAll("\n", "<br/>");
return s;
} else if (expr instanceof ExprConstant) {
String token = pos.substring(text);
if (token != null) {
String match = expr.toString();
if (!Objects.equals(token, match))
return match;
}
}
}
} catch (Exception e) {
// e.printStackTrace();
// ignore compile errors etc.
}
return null;
}
use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.
the class OurSyntaxWidget method getModule.
CompModule getModule() {
try {
A4Reporter reporter = new A4Reporter();
CompModule module = this.module;
if (module == null)
module = CompUtil.parseEverything_fromString(reporter, pane.getText());
this.module = module;
return module;
} catch (Err e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.
the class AlloyModelsTest method minimalAlloyDoc.
@Test
public void minimalAlloyDoc() throws Exception {
CompModule world = CompUtil.parseEverything_fromString(A4Reporter.NOP, "sig Foo {} \n" + "run { 1 < #Int } for 10 int\n");
A4Options options = new A4Options();
options.unrolls = 10;
for (Command command : world.getAllCommands()) {
A4Solution ans = TranslateAlloyToKodkod.execute_command(A4Reporter.NOP, world.getAllReachableSigs(), command, options);
while (ans.satisfiable()) {
String hc = "Answer: " + ans.toString().hashCode();
System.out.println(hc);
ans = ans.next();
}
return;
}
}
use of edu.mit.csail.sdg.parser.CompModule in project org.alloytools.alloy by AlloyTools.
the class ExampleCompilingFromSource method compileModuleAndRun.
public static void compileModuleAndRun(String model) throws Err {
A4Reporter rep = new A4Reporter();
// parse model from string
CompModule world = CompUtil.parseEverything_fromString(rep, model);
ConstList<Command> commands = world.getAllCommands();
if (commands.size() != 1)
throw new ErrorAPI("Must specify exactly one command; number of commands found: " + commands.size());
Command cmd = commands.get(0);
A4Options opt = new A4Options();
opt.solver = A4Options.SatSolver.SAT4J;
// solve
A4Solution sol = TranslateAlloyToKodkod.execute_command(rep, world.getAllSigs(), cmd, opt);
// print solution
System.out.println(sol);
for (Sig sig : world.getAllReachableSigs()) {
System.out.println("traversing sig: " + sig);
SafeList<Field> fields = sig.getFields();
for (Field field : fields) {
System.out.println(" traversing field: " + field);
A4TupleSet ts = (sol.eval(field));
for (A4Tuple t : ts) {
System.out.print(" [");
for (int i = 0; i < t.arity(); i++) System.out.print(t.atom(i) + " ");
System.out.println("]");
}
}
}
}
Aggregations