Interface ScriptInterpreter

  • All Known Implementing Classes:
    DefaultScriptInterpreter

    public interface ScriptInterpreter
    The contract for script interpreters.
    Author:
    Johannes Schindelin, Curtis Rueden
    • Field Detail

      • MORE_INPUT_PENDING

        static final Object MORE_INPUT_PENDING
        A special object returned by interpret(String) when the interpreter is expecting additional input before finishing the evaluation.
    • Method Detail

      • readHistory

        void readHistory()
        Reads the persisted history of the current script interpreter.
      • writeHistory

        void writeHistory()
        Persists the history of the current script interpreter.
      • walkHistory

        String walkHistory​(String currentCommand,
                           boolean forward)
        Obtains the next/previous command in the command history.
        Parameters:
        currentCommand - the current command (will be stored in the history)
        forward - if true, the next history entry is returned (more recent), if false, the previous one
        Returns:
        the next/previous command
      • interpret

        Object interpret​(String line)
                  throws ScriptException
        Interprets the given line of code, which might be part of a multi-line statement.
        Parameters:
        line - line of code to interpret
        Returns:
        value of the line, or MORE_INPUT_PENDING if there is still pending input
        Throws:
        ScriptException - in case of an exception
      • reset

        void reset()
        Clears the buffer of not-yet-evaluated lines of code, accumulated from previous calls to interpret(java.lang.String). In other words: start over with a new (potentially multi-line) statement, discarding the current partial one.
        See Also:
        interpret(java.lang.String)
      • isReady

        boolean isReady()
        Returns:
        whether the interpreter is ready for a brand new statement.
        See Also:
        interpret(String)
      • isExpectingMoreInput

        boolean isExpectingMoreInput()
        Returns:
        whether the interpreter expects more input. A true value means there is definitely more input needed. A false value means no more input is needed, but it may not yet be appropriate to evaluate all the pending lines. (there's some ambiguity depending on the language)
        See Also:
        interpret(String)