Search in sources :

Example 31 with FQLException

use of catdata.fql.FQLException in project fql by CategoricalData.

the class Mapping method constraint.

public JPanel constraint() {
    JPanel ret = new JPanel(new GridLayout(1, 1));
    try {
        Triple<Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>, Pair<Signature, List<Pair<Attribute<Node>, Pair<Edge, Attribute<Node>>>>>> x = toEDs();
        JTabbedPane t = new JTabbedPane();
        t.addTab("Sigma", quickView(x.second));
        t.addTab("Pi", quickView(x.third));
        t.addTab("Delta", quickView(x.first));
        ret.add(t);
    } catch (FQLException e) {
        // e.printStackTrace();
        ret.add(new JScrollPane(new JTextArea(e.getMessage())));
    }
    return ret;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) JTextArea(javax.swing.JTextArea) JTabbedPane(javax.swing.JTabbedPane) Pair(catdata.Pair)

Example 32 with FQLException

use of catdata.fql.FQLException in project fql by CategoricalData.

the class Path method parsePath.

// private static List<String> convert(
// List<Pair<Pair<String, String>, String>> l) {
// List<String> ret = new LinkedList<>();
// for (Pair<Pair<String, String>, String> x : l) {
// ret.add(x.second);
// }
// return ret;
// }
public static Path parsePath(Signature a, String s) throws FQLException {
    try {
        Tokens t = new FqlTokenizer(s);
        PathParser pp = new PathParser();
        Partial<List<String>> r = pp.parse(t);
        if (!r.tokens.toString().trim().isEmpty()) {
            throw new FQLException("Invalid path: " + s);
        }
        return new Path(a, r.value);
    } catch (Exception e) {
        throw new FQLException("Invalid path: " + s);
    }
}
Also used : FQLException(catdata.fql.FQLException) PathParser(catdata.fql.parse.PathParser) FqlTokenizer(catdata.fql.parse.FqlTokenizer) List(java.util.List) LinkedList(java.util.LinkedList) FQLException(catdata.fql.FQLException) Tokens(catdata.fql.parse.Tokens)

Example 33 with FQLException

use of catdata.fql.FQLException in project fql by CategoricalData.

the class Signature method makeNormalizer.

private JPanel makeNormalizer() {
    JPanel ret = new JPanel(new BorderLayout());
    JPanel p = new JPanel(new GridLayout(2, 1));
    CodeTextPanel p1 = new CodeTextPanel("Input path", "");
    CodeTextPanel p2 = new CodeTextPanel("Normalized path", "");
    p.add(p1);
    p.add(p2);
    JButton b = new JButton("Normalize");
    b.addActionListener((ActionEvent e) -> {
        String s = p1.getText();
        try {
            Path path = Path.parsePath(this, s);
            Path ap = cached.second.of(path).arr;
            p2.setText(ap.toString());
        } catch (FQLException ex) {
            p2.setText(ex.toString());
        }
    });
    ret.add(p, BorderLayout.CENTER);
    ret.add(b, BorderLayout.PAGE_END);
    return ret;
}
Also used : JPanel(javax.swing.JPanel) FQLException(catdata.fql.FQLException) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) CodeTextPanel(catdata.ide.CodeTextPanel) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 34 with FQLException

use of catdata.fql.FQLException in project fql by CategoricalData.

the class Signature method denotation.

public JPanel denotation() {
    try {
        if (den == null) {
            toCategory2();
            den = makePanel();
        }
        return den;
    } catch (FQLException fe) {
        den = new JPanel(new GridLayout(1, 1));
        JTextArea a = new JTextArea(fe.getMessage());
        JScrollPane jsp = new JScrollPane(a);
        den.add(jsp);
        return den;
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) FQLException(catdata.fql.FQLException) JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JTextArea(javax.swing.JTextArea)

Example 35 with FQLException

use of catdata.fql.FQLException in project fql by CategoricalData.

the class FqlCodeEditor method vedit.

public void vedit() {
    FQLProgram init = tryParse(topArea.getText());
    if (init == null) {
        respArea.setText(toDisplay);
        return;
    }
    if (init.lines.isEmpty()) {
        return;
    }
    String which = null;
    int start = -1;
    int offs = topArea.getCaretPosition();
    int end = -1;
    int i = 0;
    int pos = 0;
    for (String k : init.lines.keySet()) {
        Integer v = init.lines.get(k);
        if (v < offs && v > start) {
            start = v;
            which = k;
            pos = i;
        }
        i++;
    }
    if (which == null) {
        throw new RuntimeException();
    }
    int j = 0;
    for (String k : init.lines.keySet()) {
        if (j == pos + 1) {
            end = init.lines.get(k);
            break;
        }
        j++;
    }
    if (end == -1) {
        end = topArea.getText().length();
    }
    InstExp ie = init.insts.get(which);
    TransExp te = init.transforms.get(which);
    if ((ie == null && te == null) || (ie != null && !(ie instanceof InstExp.Const)) || (te != null && !(te instanceof Const))) {
        respArea.setText("Cannot visually edit " + which + ": only constant instances or transforms are visually editable.");
        return;
    }
    try {
        if (ie != null) {
            InstExp.Const iec = (InstExp.Const) ie;
            InstExp.Const n = new InstanceEditor(which, iec.sig.toSig(init), iec).show(Color.black);
            if (n == null) {
                return;
            }
            String newText = "instance " + which + " = " + n + " : " + n.sig + "\n\n";
            topArea.replaceRange(newText, start, end);
        } else {
            Const iec = (Const) te;
            if (iec == null) {
                throw new RuntimeException("Anomaly: please report");
            }
            InstExp.Const s = (InstExp.Const) init.insts.get(iec.src);
            InstExp.Const t = (InstExp.Const) init.insts.get(iec.dst);
            Const n = new TransformEditor(which, init.insts.get(iec.src).type(init).toSig(init), iec, s, t).show(Color.black);
            if (n == null) {
                return;
            }
            String newText = "transform " + which + " = " + n + " : " + n.src + " -> " + n.dst + "\n\n";
            topArea.replaceRange(newText, start, end);
        }
    } catch (FQLException fe) {
        fe.printStackTrace();
        respArea.setText(fe.getLocalizedMessage());
    }
}
Also used : InstExp(catdata.fql.decl.InstExp) FQLException(catdata.fql.FQLException) TransExp(catdata.fql.decl.TransExp) Const(catdata.fql.decl.TransExp.Const) InstanceEditor(catdata.fql.decl.InstanceEditor) FQLProgram(catdata.fql.decl.FQLProgram) TransformEditor(catdata.fql.decl.TransformEditor)

Aggregations

FQLException (catdata.fql.FQLException)37 Pair (catdata.Pair)28 LinkedList (java.util.LinkedList)23 HashMap (java.util.HashMap)21 Node (catdata.fql.decl.Node)20 LinkedHashMap (java.util.LinkedHashMap)20 Arr (catdata.fql.cat.Arr)15 Map (java.util.Map)15 Instance (catdata.fql.decl.Instance)14 Path (catdata.fql.decl.Path)14 Transform (catdata.fql.decl.Transform)12 Attribute (catdata.fql.decl.Attribute)11 Edge (catdata.fql.decl.Edge)11 Signature (catdata.fql.decl.Signature)11 List (java.util.List)11 Triple (catdata.Triple)9 HashSet (java.util.HashSet)6 Fn (catdata.fql.Fn)5 CopyFlower (catdata.fql.sql.CopyFlower)5 ExpPSM (catdata.fql.sql.ExpPSM)5