Search in sources :

Example 1 with Type

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);
}
Also used : Const(catdata.fql.decl.TransExp.Const) InstExp(catdata.fql.decl.InstExp) MapExp(catdata.fql.decl.MapExp) Type(catdata.fql.decl.Type) FQLProgram(catdata.fql.decl.FQLProgram)

Aggregations

FQLProgram (catdata.fql.decl.FQLProgram)1 InstExp (catdata.fql.decl.InstExp)1 MapExp (catdata.fql.decl.MapExp)1 Const (catdata.fql.decl.TransExp.Const)1 Type (catdata.fql.decl.Type)1