concepts.dsl.executors.executor_base.DSLExecutorBase#

class DSLExecutorBase[source]#

Bases: ABC

The baseclass for all executors of domain-specific languages.

Methods

execute(expression)

Execute an expression.

get_function_implementation(name)

Get the implementation of a function.

has_function_implementation(name)

Check whether the executor has an implementation for a function.

register_function(name, func)

Register an implementation for a function to the executor.

register_function_implementation(name, func)

Register an implementation for a function.

Attributes

domain

The domain of the executor.

function_implementations

The implementations of functions, which is a mapping from function names to implementations.

__init__(domain)[source]#

Initialize the executor.

Parameters:

domain (DSLDomainBase) – the domain of the executor.

__new__(**kwargs)#
abstract execute(expression)[source]#

Execute an expression.

Parameters:

expression (Expression) – the expression to execute.

Returns:

the result of the execution.

Return type:

Any

get_function_implementation(name)[source]#

Get the implementation of a function. When the executor does not have an implementation for the function, the implementation of the function in the domain will be returned. If that is also None, a KeyError will be raised.

Parameters:

name (str) – the name of the function.

Returns:

the implementation of the function.

Return type:

Callable

has_function_implementation(name)[source]#

Check whether the executor has an implementation for a function.

Parameters:

name (str) – the name of the function.

Returns:

whether the executor has an implementation for the function.

Return type:

bool

register_function(name, func)[source]#

Register an implementation for a function to the executor. Alias for register_function_implementation().

Parameters:
  • name (str) – the name of the function.

  • func (Callable) – the implementation of the function.

register_function_implementation(name, func)[source]#

Register an implementation for a function.

Parameters:
  • name (str) – the name of the function.

  • func (Callable) – the implementation of the function.

property domain: DSLDomainBase#

The domain of the executor.

property function_implementations: Dict[str, Callable]#

The implementations of functions, which is a mapping from function names to implementations.