Interpreter class

Interpreter: an object that contains and runs one MiniScript script.

Constructors

Interpreter({String? source, TextOutputMethod? standardOutput, TextOutputMethod? errorOutput})
Constructor taking some MiniScript source code, and the output delegates.
Interpreter.fromLines({required List<String> sourceLines, TextOutputMethod? standardOutput, TextOutputMethod? errorOutput})
Constructor taking source code in the form of a list of strings.

Properties

done bool
done: returns true when we don't have a virtual machine, or we do have one and it is done (has reached the end of its code).
no setter
errorOutput TextOutputMethod?
errorOutput: receives error messages from the runtime. (This happens via the reportError method, which is virtual; so if you want to catch the actual exceptions rather than get the error messages as strings, you can extend Interpreter and override that method.)
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
hostData Object?
hostData is just a convenient place for you to attach some arbitrary data to the interpreter. It gets passed through to the context object, so you can access it inside your custom intrinsic functions. Use it for whatever you like (or don't, if you don't feel the need).
getter/setter pair
implicitOutput TextOutputMethod?
implicitOutput: receives the value of expressions entered when in REPL mode. If you're not using the REPL() method, you can safely ignore this.
getter/setter pair
parser Parser?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
source String?
getter/setter pair
standardOutput TextOutputMethod
standardOutput: receives the output of the "print" intrinsic.
getter/setter pair
vm Machine?
vm: the virtual machine this interpreter is running. Most applications will not need to use this, but it's provided for advanced users.
getter/setter pair

Methods

checkImplicitResult(int previousImpResultCount) → void
Helper method that checks whether we have a new implicit result, and if so, invokes the implicitOutput callback (if any). This is how you can see the result of an expression in a Read-Eval-Print Loop (REPL).
compile() → void
Compile our source code, if we haven't already done so, so that we are either ready to run, or generate compiler errors (reported via errorOutput).
getGlobalValue(String varName) Value?
Get a value from the global namespace of this interpreter.
needMoreInput() bool
Return whether the parser needs more input, for example because we have run out of source code in the middle of an "if" block. This is typically used with REPL for making an interactive console, so you can change the prompt when more input is expected.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
repl(String? sourceLine, {double timeLimit = 60}) → void
Read Eval Print Loop. Run the given source until it either terminates, or hits the given time limit. When it terminates, if we have new implicit output, print that to the implicitOutput stream.
reportError(MiniscriptException mse) → void
Report a MiniScript error to the user. The default implementation simply invokes errorOutput with the error description. If you want to do something different, then make an Interpreter subclass, and override this method.
reset({String source = ""}) → void
Reset the interpreter with the given source code.
restart() → void
Reset the virtual machine to the beginning of the code. Note that this does not reset global variables; it simply clears the stack and jumps to the beginning. Useful in cases where you have a short script you want to run over and over, without recompiling every time.
running() bool
Report whether the virtual machine is still running, that is, whether it has not yet reached the end of the program code.
runUntilDone({double timeLimit = 60, bool returnEarly = true}) → void
Run the compiled code until we either reach the end, or we reach the specified time limit. In the latter case, you can then call runUntilDone again to continue execution right from where it left off.
setGlobalValue(String varName, Value value) → void
Set a value in the global namespace of this interpreter.
step() → void
Run one step of the virtual machine. This method is not very useful except in special cases; usually you will use runUntilDone (above) instead.
stop() → void
Stop the virtual machine, and jump to the end of the program code. Also reset the parser, in case it's stuck waiting for a block ender.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited