Interpreter

commands. Interpreter

Command interpreter to execute command strings.

Constructor

new Interpreter(commandsopt, intrinsicsopt)

Source:
Parameters:
Name Type Attributes Default Description
commands object.<string, commands.Command> <optional>

Commands this interpreter recognizes.

intrinsics boolean <optional>
true

Whether to add intrinsic commands to the interpreter scope (like 'define' and 'pause').

Members

commandNames :Array.<string>

Source:

Command names this interpreter recognizes.

Type:
  • Array.<string>

commands :object.<string, commands.Command>

Source:

All commands indexed by their names.

Type:

Methods

add(name, command)

Source:

Adds a new command or redefines an existing one.

Parameters:
Name Type Description
name string

The command name.

command commands.Command

The command function.

cancel(ctopt)

Source:

Cancels any executing commands.

Parameters:
Name Type Attributes Description
ct commands.Cancellable <optional>

Cancellation token.

(async) execute(text, ctxopt, ctopt) → {Array.<object>}

Source:

Executes a command asynchronously.

Parameters:
Name Type Attributes Description
text string

Command text to execute.

ctx object <optional>

Context object to be passed as part of the executed commands' context, together with the cancellation token. This context cannot have key 'ct', since it would be overwritten anyway.

ct commands.Cancellable <optional>

Cancellation token.

Throws:

Throws an error for any syntax or semantic errors in the text.

Returns:

Array with the results of the executions of the commands.

Type
Array.<object>

(async) executeFile(filePath, encodingopt, ctxopt, ctopt) → {Array.<object>}

Source:

Executes a command file asynchronously.

Parameters:
Name Type Attributes Default Description
filePath string

Path to the file to execute.

encoding string <optional>
'utf8'

Encoding of the file.

ctx object <optional>

Context object to be passed as part of the executed commands' context, together with the cancellation token. This context cannot have key 'ct', since it would be overwritten anyway.

ct commands.Cancellable <optional>

Cancellation token.

Throws:

Throws an error for any issues accessing the file, or for any syntax or semantic errors in its text.

Returns:

Array with the results of the executions of the commands found in the file.

Type
Array.<object>

lookup(name) → {commands.Command}

Source:

Looks up a command this interpreter recognizes.

Parameters:
Name Type Description
name string

The command name.

Returns:
  • The command function or null if the command is not found.
Type
commands.Command