use of org.alloytools.util.table.Table in project org.alloytools.alloy by AlloyTools.
the class Sig method explain.
@Override
public String explain() {
Table t = new Table(2, 1 + realFields.size(), 1);
StringBuilder sb = new StringBuilder();
if (builtin)
sb.append("builtin ");
if (isEnum != null)
sb.append("enum ");
if (isAbstract != null)
sb.append("abstract ");
if (isLone != null)
sb.append("lone ");
if (isOne != null)
sb.append("one ");
if (isMeta != null)
sb.append("meta ");
if (isSome != null)
sb.append("some ");
if (isSubsig != null)
sb.append("sig ");
if (isSubset != null)
sb.append("subset ");
t.set(0, 0, sb);
t.set(1, 0, clean(label));
int n = 1;
for (Field f : realFields) {
t.set(0, n++, clean(f.label));
}
n = 1;
for (Field f : realFields) {
String relation = clean(type.join(f.type).toString());
Table table = TableView.toTable(relation, false);
t.set(1, n++, table);
}
return t.toString();
}
use of org.alloytools.util.table.Table in project org.alloytools.alloy by AlloyTools.
the class TableView method toTable.
// public static Table toTable(SimTupleset tupleset) {
// Table table = new Table(tupleset.size(), tupleset.arity(), 0);
// int row = 0;
// for ( SimTuple tuple : tupleset) {
// int column = 0;
// for ( SimAtom atom : tuple) {
// table.set(row, column++, atom);
// }
// row++;
// }
//
// return table;
// }
public static Table toTable(SimTupleset tupleset) {
if (tupleset.arity() == 0) {
return new Table(0, 0, 0);
}
if (tupleset.arity() == 1) {
Table t = new Table(tupleset.size(), 1, 0);
int row = 0;
for (SimTuple tuple : tupleset) {
t.set(row, 0, tuple.get(0));
row++;
}
return t;
}
SimTupleset head = tupleset.head(1);
Table table = new Table(head.size(), 2, 0);
int row = 0;
for (SimTuple tuple : head) {
SimAtom atom = tuple.head();
SimTuple target = SimTuple.make(atom);
SimTupleset singleton = SimTupleset.make(target);
SimTupleset joined = singleton.join(tupleset);
table.set(row, 0, atom.toString());
Table sub = toTable(joined);
table.set(row, 1, sub);
row++;
}
return table;
}
use of org.alloytools.util.table.Table in project org.alloytools.alloy by AlloyTools.
the class TableView method toTable.
/**
* Format a solution to a string
*
* @param solution
* @param instance
* @param sigs
* @return
*/
public static Map<String, Table> toTable(A4Solution solution, Instance instance, SafeList<Sig> sigs) {
Map<String, Table> map = new HashMap<String, Table>();
for (Sig s : sigs) {
if (!s.label.startsWith("this/"))
continue;
TupleSet instanceTuples = instance.tuples(s.label);
if (instanceTuples != null) {
SimTupleset sigInstances = toSimTupleset(instanceTuples);
Table table = new Table(sigInstances.size() + 1, s.getFields().size() + 1, 1);
table.set(0, 0, s.label);
if (s.getFields().size() == 0 && sigInstances.size() <= 1)
continue;
int c = 1;
for (Field f : s.getFields()) {
table.set(0, c++, f.label);
}
map.put(s.label, table);
int r = 1;
for (SimTuple sigInstance : sigInstances) {
assert sigInstance.arity() == 1;
SimTupleset leftJoin = SimTupleset.make(sigInstance);
table.set(r, 0, sigInstance.get(0));
c = 1;
for (Field f : s.getFields()) {
SimTupleset relations = toSimTupleset(solution.eval(f));
SimTupleset joined = leftJoin.join(relations);
Table relationTable = toTable(joined);
table.set(r, c++, relationTable);
}
r++;
}
}
}
return map;
}
use of org.alloytools.util.table.Table in project org.alloytools.alloy by AlloyTools.
the class OurConsole method do_add.
/**
* Insert the given text into the given location and with the given style if
* where>=0; append the text if where<0.
*/
private void do_add(int where, String text, AttributeSet style) {
try {
StyledDocument doc = main.getStyledDocument();
if (TableView.isTable(text)) {
Table table = TableView.toTable(text, false);
doc.insertString(where >= 0 ? where : doc.getLength(), table.toString(), mono);
main.getCaret().setSelectionVisible(false);
} else
doc.insertString(where >= 0 ? where : doc.getLength(), text, style);
} catch (BadLocationException ex) {
}
}
use of org.alloytools.util.table.Table in project org.alloytools.alloy by AlloyTools.
the class Func method explain.
@Override
public String explain() {
StringBuilder sb = new StringBuilder();
if (isPred)
sb.append("pred ");
else
sb.append("fun ");
sb.append(clean(label)).append(":\n");
if (decls.size() > 0 || !isPred) {
sb.append("\n");
int n = 0;
int count = (int) decls.stream().flatMap(decl -> decl.names.stream()).count();
Table t = new Table(2, count + (isPred ? 0 : 1), 1);
for (Decl decl : decls) {
for (Expr e : decl.names) {
t.set(0, n, e);
t.set(1, n, TableView.toTable(decl.expr.type));
n++;
}
}
if (!isPred) {
t.set(0, n, "⟶");
t.set(1, n, TableView.toTable(returnDecl.type));
n++;
}
sb.append(t);
}
return sb.toString();
}
Aggregations