Search in sources :

Example 1 with ASCIIPrettyPrinter3

use of org.matheclipse.core.form.output.ASCIIPrettyPrinter3 in project symja_android_library by axkr.

the class Console method prettyPrinter3Lines.

private String[] prettyPrinter3Lines(final String inputExpression) {
    IExpr result;
    final StringWriter buf = new StringWriter();
    try {
        if (fSeconds <= 0) {
            result = fEvaluator.evaluate(inputExpression);
        } else {
            result = fEvaluator.evaluateWithTimeout(inputExpression, fSeconds, TimeUnit.SECONDS, true);
        }
        if (result != null) {
            if (result.equals(F.Null)) {
                return null;
            }
            ASCIIPrettyPrinter3 strBuffer = new ASCIIPrettyPrinter3();
            strBuffer.convert(result);
            return strBuffer.toStringBuilder();
        }
    } catch (final SyntaxError se) {
        String msg = se.getMessage();
        System.err.println();
        System.err.println(msg);
        return null;
    } catch (final RuntimeException re) {
        Throwable me = re.getCause();
        if (me instanceof MathException) {
            Validate.printException(buf, me);
        } else {
            Validate.printException(buf, re);
        }
        return null;
    } catch (final Exception e) {
        Validate.printException(buf, e);
        return null;
    } catch (final OutOfMemoryError e) {
        Validate.printException(buf, e);
        return null;
    } catch (final StackOverflowError e) {
        Validate.printException(buf, e);
        return null;
    }
    String[] strArray = new String[3];
    strArray[0] = "";
    strArray[1] = buf.toString();
    strArray[3] = "";
    return strArray;
}
Also used : ASCIIPrettyPrinter3(org.matheclipse.core.form.output.ASCIIPrettyPrinter3) StringWriter(java.io.StringWriter) SyntaxError(org.matheclipse.parser.client.SyntaxError) MathException(org.matheclipse.parser.client.math.MathException) IExpr(org.matheclipse.core.interfaces.IExpr) MathException(org.matheclipse.parser.client.math.MathException) IOException(java.io.IOException)

Example 2 with ASCIIPrettyPrinter3

use of org.matheclipse.core.form.output.ASCIIPrettyPrinter3 in project symja_android_library by axkr.

the class ASCIIPrintTest method check.

private void check(IExpr expr, String str1, String str2, String str3) {
    ASCIIPrettyPrinter3 strBuffer = new ASCIIPrettyPrinter3();
    strBuffer.convert(expr);
    String[] result = strBuffer.toStringBuilder();
    assertEquals(result[0].toString(), str1);
    assertEquals(result[1].toString(), str2);
    assertEquals(result[2].toString(), str3);
}
Also used : ASCIIPrettyPrinter3(org.matheclipse.core.form.output.ASCIIPrettyPrinter3)

Aggregations

ASCIIPrettyPrinter3 (org.matheclipse.core.form.output.ASCIIPrettyPrinter3)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 SyntaxError (org.matheclipse.parser.client.SyntaxError)1 MathException (org.matheclipse.parser.client.math.MathException)1