use of catdata.fql.decl.Type in project fql by CategoricalData.
the class FqlCodeEditor method format.
public void format() {
String input = topArea.getText();
FQLProgram p = tryParse(input);
if (p == null) {
respArea.setText(toDisplay);
return;
}
if (input.contains("//") || input.contains("/*")) {
int x = JOptionPane.showConfirmDialog(null, "Formatting will erase all comments - continue?", "Continue?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (x != JOptionPane.YES_OPTION) {
return;
}
}
// order does not contain enums or drops
StringBuilder sb = new StringBuilder();
for (String k : p.enums.keySet()) {
Type t = p.enums.get(k);
if (!(t instanceof Type.Enum)) {
continue;
}
Type.Enum e = (Type.Enum) t;
sb.append("enum ").append(k).append(" = ").append(e.printFull());
sb.append("\n\n");
}
for (String k : p.order) {
Pair<String, Object> o = get(p, k);
sb.append(o.first).append(" ").append(k).append(" = ").append(o.second);
if (o.second instanceof InstExp.Const) {
InstExp.Const c = (InstExp.Const) o.second;
sb.append(" : ").append(c.sig);
} else if (o.second instanceof MapExp.Const) {
MapExp.Const c = (MapExp.Const) o.second;
sb.append(" : ").append(c.src).append(" -> ").append(c.dst);
} else if (o.second instanceof Const) {
Const c = (Const) o.second;
sb.append(" : ").append(c.src).append(" -> ").append(c.dst);
}
sb.append("\n\n");
}
if (!p.drop.isEmpty()) {
sb.append("drop ").append(PrettyPrinter.sep0(" ", p.drop)).append("\n\n");
}
topArea.setText(sb.toString().trim());
topArea.setCaretPosition(0);
}
Aggregations