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;
}
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);
}
}
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;
}
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;
}
}
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());
}
}
Aggregations