Search in sources :

Example 1 with MarkdownNotebookOutput

use of com.twosigma.beakerx.symjamma.output.MarkdownNotebookOutput in project symja_android_library by axkr.

the class SymjaMMACodeRunner method interpreter.

public Object interpreter(ExprEvaluator fEvaluator, OutputFormFactory fOutputFactory, final String inputExpression) {
    IExpr result;
    final StringWriter buf = new StringWriter();
    try {
        String trimmedInput = inputExpression.trim();
        if (trimmedInput.length() >= 4 && trimmedInput.charAt(0) == '/') {
            Object meta = symjammaEvaluator.metaCommand(this, trimmedInput);
            if (meta != null) {
                return meta;
            }
        }
        if (symjammaEvaluator.fSeconds <= 0) {
            result = fEvaluator.eval(inputExpression);
        } else {
            result = fEvaluator.evaluateWithTimeout(inputExpression, symjammaEvaluator.fSeconds, TimeUnit.SECONDS, true, new EvalControlledCallable(fEvaluator.getEvalEngine()));
        }
        if (result != null) {
            if (result.equals(S.Null)) {
                return "Null";
            } else {
                return result;
            }
        }
    } catch (final Exception e) {
        LOGGER.error("SymjaMMACodeRunner.interpreter() failed", e);
    }
    return new MarkdownNotebookOutput(buf.toString());
}
Also used : MarkdownNotebookOutput(com.twosigma.beakerx.symjamma.output.MarkdownNotebookOutput) StringWriter(java.io.StringWriter) EvalControlledCallable(org.matheclipse.core.eval.EvalControlledCallable) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) IExpr(org.matheclipse.core.interfaces.IExpr) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)1 MarkdownNotebookOutput (com.twosigma.beakerx.symjamma.output.MarkdownNotebookOutput)1 StringWriter (java.io.StringWriter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 EvalControlledCallable (org.matheclipse.core.eval.EvalControlledCallable)1 IExpr (org.matheclipse.core.interfaces.IExpr)1