Package org.scijava.script
Interface ScriptInterpreter
-
- All Known Implementing Classes:
DefaultScriptInterpreter
public interface ScriptInterpreterThe contract for script interpreters.- Author:
- Johannes Schindelin, Curtis Rueden
-
-
Field Summary
Fields Modifier and Type Field Description static ObjectMORE_INPUT_PENDINGA special object returned byinterpret(String)when the interpreter is expecting additional input before finishing the evaluation.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Objecteval(String command)Evaluates a command.BindingsgetBindings()ScriptEnginegetEngine()Returns the associatedScriptEngine.ScriptLanguagegetLanguage()Returns the associatedScriptLanguage.Objectinterpret(String line)Interprets the given line of code, which might be part of a multi-line statement.booleanisExpectingMoreInput()booleanisReady()voidreadHistory()Reads the persisted history of the current script interpreter.voidreset()Clears the buffer of not-yet-evaluated lines of code, accumulated from previous calls tointerpret(java.lang.String).StringwalkHistory(String currentCommand, boolean forward)Obtains the next/previous command in the command history.voidwriteHistory()Persists the history of the current script interpreter.
-
-
-
Field Detail
-
MORE_INPUT_PENDING
static final Object MORE_INPUT_PENDING
A special object returned byinterpret(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
-
eval
Object eval(String command) throws ScriptException
Evaluates a command.- Parameters:
command- the command to evaluate- Returns:
- result of the evaluation
- Throws:
ScriptException
-
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_PENDINGif 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 tointerpret(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)
-
getLanguage
ScriptLanguage getLanguage()
Returns the associatedScriptLanguage.
-
getEngine
ScriptEngine getEngine()
Returns the associatedScriptEngine.- Returns:
- the script engine
-
getBindings
Bindings getBindings()
-
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)
-
-