Interpreter Module

Interpreter

class bTagScript.interpreter.Interpreter(blocks: Union[List[Block], Tuple[Block]])[source]

Bases: object

The TagScript interpreter.

blocks

A list or tuple of blocks to be used for TagScript processing.

Type

UnionList[Block]

process(message: str, seed_variables: Optional[Dict[str, Adapter]] = None, *, charlimit: Optional[int] = None, **kwargs) Response[source]

Processes a given TagScript string.

Parameters
  • message (str) – A TagScript string to be processed.

  • seed_variables (Dict[str, Adapter]) – A dictionary containing strings to adapters to provide context variables for processing.

  • charlimit (int) – The maximum characters to process.

  • kwargs (Dict[str, Any]) – Additional keyword arguments that may be used by blocks during processing.

Returns

A response object containing the processed body, actions and variables.

Return type

Response

Raises
  • TagScriptError – A block intentionally raised an exception, most likely due to invalid user input.

  • WorkloadExceededError – Signifies the interpreter reached the character limit, if one was provided.

  • ProcessError – An unexpected error occurred while processing blocks.

AsyncInterpreter

class bTagScript.interpreter.AsyncInterpreter(blocks: Union[List[Block], Tuple[Block]])[source]

Bases: Interpreter

An asynchronous subclass of Interpreter that allows blocks to implement asynchronous methods. Synchronous blocks are still supported. This subclass has no additional attributes from the Interpreter class. See Interpreter for full documentation.

async process(message: str, seed_variables: Optional[Dict[str, Adapter]] = None, *, charlimit: Optional[int] = None, **kwargs) Response[source]

Asynchronously process a given TagScript string. This method has no additional attributes from the Interpreter class. See Interpreter.process for full documentation.

Context

class bTagScript.interpreter.Context(verb: Verb, res: Response, interpreter: Interpreter, og: str)[source]

Bases: object

An object containing data on the TagScript block processed by the interpreter. This class is passed to adapters and blocks during processing.

verb

The Verb object representing a TagScript block.

Type

Verb

original_message

The original message passed to the interpreter.

Type

str

interpreter

The interpreter processing the TagScript.

Type

Interpreter

Response

class bTagScript.interpreter.Response(*, variables: Optional[Dict[str, Adapter]] = None, extras: Optional[Dict[str, Any]] = None)[source]

Bases: object

An object containing information on a completed TagScript process.

body

The cleaned message with all verbs interpreted.

Type

str

actions

A dictionary that blocks can access and modify to define post-processing actions.

Type

Dict[str, Any]

variables

A dictionary of variables that blocks such as the LooseVariableGetterBlock can access.

Type

Dict[str, Adapter]

extras

A dictionary of extra keyword arguments that blocks can use to define their own behavior.

Type

Dict[str, Any]

Node

class bTagScript.interpreter.Node(coordinates: Tuple[int, int], verb: Optional[Verb] = None)[source]

Bases: object

A low-level object representing a bracketed block.

coordinates

The start and end position of the bracketed text block.

Type

Tuple[int, int]

verb

The determined Verb for this node.

Type

Optional[Verb]

output

The Block processed output for this node.

build_node_tree

bTagScript.interpreter.build_node_tree(message: str) List[Node][source]

Function that finds all possible nodes in a string.

Parameters

message (str) – The string to find nodes in.

Returns

A list of all possible text bracket blocks.

Return type

List[Node]