Search in sources :

Example 1 with ParserException

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) ParserException(org.jparsec.error.ParserException) JTextArea(javax.swing.JTextArea) DateFormat(java.text.DateFormat) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane) FQLProgram(catdata.fql.decl.FQLProgram) Date(java.sql.Date) JDialog(javax.swing.JDialog)

Example 2 with ParserException

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());
}
Also used : ParserException(org.jparsec.error.ParserException) XSchema(catdata.fpql.XExp.XSchema) LineException(catdata.LineException)

Aggregations

ParserException (org.jparsec.error.ParserException)2 LineException (catdata.LineException)1 XSchema (catdata.fpql.XExp.XSchema)1 FQLProgram (catdata.fql.decl.FQLProgram)1 Dimension (java.awt.Dimension)1 Date (java.sql.Date)1 DateFormat (java.text.DateFormat)1 JDialog (javax.swing.JDialog)1 JOptionPane (javax.swing.JOptionPane)1 JScrollPane (javax.swing.JScrollPane)1 JTextArea (javax.swing.JTextArea)1