use of org.jparsec.error.ParserException in project fql by CategoricalData.
the class FqlCodeEditor method check.
public void check() {
String program = topArea.getText();
FQLProgram init;
try {
init = FQLParser.program(program);
} catch (ParserException e) {
int col = e.getLocation().column;
int line = e.getLocation().line;
topArea.requestFocusInWindow();
topArea.setCaretPosition(topArea.getDocument().getDefaultRootElement().getElement(line - 1).getStartOffset() + (col - 1));
// String s = e.getMessage();
// String t = s.substring(s.indexOf(" "));
// t.split("\\s+");
respArea.setText("Syntax error: " + e.getLocalizedMessage());
e.printStackTrace();
return;
} catch (RuntimeException e) {
respArea.setText("Error: " + e.getLocalizedMessage());
e.printStackTrace();
return;
}
String xxx = Driver.checkReport(init);
DateFormat format = DateFormat.getTimeInstance();
String time = format.format(new Date(System.currentTimeMillis()));
String foo = title;
JTextArea jta = new JTextArea(xxx);
jta.setWrapStyleWord(true);
jta.setLineWrap(true);
JScrollPane p = new JScrollPane(jta, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
p.setPreferredSize(new Dimension(650, 300));
JOptionPane pane = new JOptionPane(p);
JDialog dialog = pane.createDialog(null, "Type Check " + foo + " - " + time);
dialog.setModal(false);
dialog.setResizable(true);
dialog.setVisible(true);
}
use of org.jparsec.error.ParserException in project fql by CategoricalData.
the class EnrichViewer method translate.
private String translate(String program) {
XProgram init;
try {
init = XParser.program(program);
} catch (ParserException e) {
int col = e.getLocation().column;
int line = e.getLocation().line;
topArea.requestFocusInWindow();
topArea.area.setCaretPosition(topArea.area.getDocument().getDefaultRootElement().getElement(line - 1).getStartOffset() + (col - 1));
// String s = e.getMessage();
// String t = s.substring(s.indexOf(" "));
// t.split("\\s+");
e.printStackTrace();
return "Syntax error: " + e.getLocalizedMessage();
} catch (Throwable e) {
e.printStackTrace();
return "Error: " + e.getLocalizedMessage();
}
if (init == null) {
return "";
}
String isaX = null, matX = null;
XSchema isa = null, mat = null;
for (String line : init.order) {
XExp exp = init.exps.get(line);
if (exp instanceof XSchema) {
if (isaX == null) {
isaX = line;
isa = (XSchema) exp;
continue;
}
if (matX == null) {
matX = line;
mat = (XSchema) exp;
continue;
}
throw new RuntimeException("More than two schemas");
}
}
if (isaX == null || matX == null) {
throw new RuntimeException("Fewer than two schemas");
}
/* if (isa.arrows.size() != 2) {
String temp = isaX;
XExp.XSchema temp2 = isa;
isaX = matX;
isa = mat;
matX = temp;
mat = temp2;
} */
XEnvironment env;
try {
env = XDriver.makeEnv(program, init);
} catch (LineException e) {
String toDisplay = "Error in " + e.kind + " " + e.decl + ": " + e.getLocalizedMessage();
e.printStackTrace();
topArea.requestFocusInWindow();
Integer theLine = init.getLine(e.decl);
topArea.area.setCaretPosition(theLine);
return toDisplay;
} catch (Throwable re) {
return "Error: " + re.getLocalizedMessage();
}
@SuppressWarnings("unchecked") XCtx<String> isa0 = (XCtx<String>) env.objs.get(isaX);
@SuppressWarnings("unchecked") XCtx<String> mat0 = (XCtx<String>) env.objs.get(matX);
return go(isa, mat, isaX, matX, isa0, mat0, name.getText(), kid.getText(), instField.getText(), isaField.getText());
}
Aggregations