ArkScript
A small, fast, functional and scripting language for video games
Ark::internal::MacroExecutor Class Referenceabstract

A class that applies macros in a Node. More...

#include <Executor.hpp>

Inheritance diagram for Ark::internal::MacroExecutor:
[legend]
Collaboration diagram for Ark::internal::MacroExecutor:
[legend]

Public Member Functions

 MacroExecutor (MacroProcessor *processor, unsigned debug=0)
 Construct a new Macro Executor object.
 
virtual ~MacroExecutor ()=default
 Need a virtual destructor to correctly destroy object.
 
virtual bool applyMacro (Node &node, unsigned depth)=0
 Executes macros in the Node if the Executor can handle it.
 
virtual bool canHandle (Node &node)=0
 Checks if the executor can apply a macro on the passed Node.
 

Protected Member Functions

const NodefindNearestMacro (const std::string &name) const
 Find the nearest macro matching a giving name.
 
void applyMacroProxy (Node &node, unsigned depth)
 Apply a macro on a given node.
 
void handleMacroNode (Node &node) const
 Registers macros based on their type, expand conditional macros.
 
bool isTruthy (const Node &node) const
 Check if a node can be evaluated to true.
 
Node evaluate (Node &node, unsigned depth, bool is_not_body) const
 Evaluate only the macros.
 

Static Protected Member Functions

static void throwMacroProcessingError (const std::string &message, const Node &node)
 Throw a macro processing error.
 

Protected Attributes

unsigned int m_debug
 
MacroProcessorm_processor
 This is a non-owned pointer.
 

Detailed Description

A class that applies macros in a Node.

Definition at line 28 of file Executor.hpp.

Constructor & Destructor Documentation

◆ MacroExecutor()

Ark::internal::MacroExecutor::MacroExecutor ( MacroProcessor * processor,
unsigned debug = 0 )
explicit

Construct a new Macro Executor object.

Parameters
processor
debug

Definition at line 7 of file Executor.cpp.

◆ ~MacroExecutor()

virtual Ark::internal::MacroExecutor::~MacroExecutor ( )
virtualdefault

Need a virtual destructor to correctly destroy object.

Member Function Documentation

◆ applyMacro()

virtual bool Ark::internal::MacroExecutor::applyMacro ( Node & node,
unsigned depth )
pure virtual

Executes macros in the Node if the Executor can handle it.

Parameters
nodethe node that contains a macro
depth
Returns
true if a macro was successfully applied
false

Implemented in Ark::internal::ConditionalExecutor, Ark::internal::FunctionExecutor, and Ark::internal::SymbolExecutor.

◆ applyMacroProxy()

void Ark::internal::MacroExecutor::applyMacroProxy ( Node & node,
unsigned depth )
protected

◆ canHandle()

virtual bool Ark::internal::MacroExecutor::canHandle ( Node & node)
pure virtual

Checks if the executor can apply a macro on the passed Node.

Parameters
nodethe node that contains a macro

Implemented in Ark::internal::ConditionalExecutor, Ark::internal::FunctionExecutor, and Ark::internal::SymbolExecutor.

◆ evaluate()

Node Ark::internal::MacroExecutor::evaluate ( Node & node,
unsigned depth,
bool is_not_body ) const
protected

Evaluate only the macros.

Proxy function for MacroProcessor::evaluate

Parameters
node
depth
is_not_bodytrue if the method is run on a non-body code (eg a condition of an if-macro)
Returns
Node

Definition at line 32 of file Executor.cpp.

References Ark::internal::MacroProcessor::evaluate(), and m_processor.

Referenced by Ark::internal::ConditionalExecutor::applyMacro(), Ark::internal::FunctionExecutor::applyMacro(), and Ark::internal::SymbolExecutor::applyMacro().

◆ findNearestMacro()

const Node * Ark::internal::MacroExecutor::findNearestMacro ( const std::string & name) const
nodiscardprotected

Find the nearest macro matching a giving name.

Proxy function for MacroProcessor::findNearestMacro

Parameters
name
Returns
const Node* nullptr if no macro was found

Definition at line 12 of file Executor.cpp.

References Ark::internal::MacroProcessor::findNearestMacro(), and m_processor.

Referenced by Ark::internal::FunctionExecutor::applyMacro(), and Ark::internal::SymbolExecutor::applyMacro().

◆ handleMacroNode()

void Ark::internal::MacroExecutor::handleMacroNode ( Node & node) const
protected

Registers macros based on their type, expand conditional macros.

Validate macros and register them by their name Proxy function for MacroProcessor::handleMacroNode

Parameters
nodeA node of type Macro

Definition at line 22 of file Executor.cpp.

References Ark::internal::MacroProcessor::handleMacroNode(), and m_processor.

Referenced by Ark::internal::ConditionalExecutor::applyMacro().

◆ isTruthy()

bool Ark::internal::MacroExecutor::isTruthy ( const Node & node) const
nodiscardprotected

Check if a node can be evaluated to true.

Proxy function for MacroProcessor::isTruthy

Parameters
node
Returns
true
false

Definition at line 27 of file Executor.cpp.

References Ark::internal::MacroProcessor::isTruthy(), and m_processor.

Referenced by Ark::internal::ConditionalExecutor::applyMacro().

◆ throwMacroProcessingError()

void Ark::internal::MacroExecutor::throwMacroProcessingError ( const std::string & message,
const Node & node )
staticprotected

Throw a macro processing error.

Proxy function for MacroProcessor::throwMacroProcessingError

Parameters
messagethe error
nodethe node in which there is an error

Definition at line 37 of file Executor.cpp.

Referenced by Ark::internal::FunctionExecutor::applyMacro(), and Ark::internal::FunctionExecutor::unify().

Member Data Documentation

◆ m_debug

unsigned int Ark::internal::MacroExecutor::m_debug
protected

Definition at line 63 of file Executor.hpp.

◆ m_processor

MacroProcessor* Ark::internal::MacroExecutor::m_processor
protected

This is a non-owned pointer.

Definition at line 64 of file Executor.hpp.

Referenced by applyMacroProxy(), evaluate(), findNearestMacro(), handleMacroNode(), and isTruthy().


The documentation for this class was generated from the following files: