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:
+ Collaboration diagram for Ark::internal::MacroExecutor:

Public Member Functions

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

Protected Member Functions

NodefindNearestMacro (const std::string &name)
 Find the nearest macro matching a giving name. More...
 
void registerMacro (Node &node)
 Registers macros based on their type. More...
 
bool isTruthy (const Node &node)
 Check if a node can be evaluated to true. More...
 
Node evaluate (Node &node, bool is_not_body)
 Evaluate only the macros. More...
 
void unify (const std::unordered_map< std::string, Node > &, Node &, Node *)
 Applies the spread operator. More...
 
void throwMacroProcessingError (const std::string &message, const Node &node)
 Throw a macro processing error. More...
 
bool applyMacroProxy (Node &node)
 Execute a node, trying to emplace macros calls. More...
 
bool isPredefined (const std::string &symbol)
 Check if a given symbol is a predefined macro. More...
 

Protected Attributes

unsigned int m_debug
 
MacroProcessorm_macroprocessor
 

Detailed Description

A class that applies macros in a Node.

Definition at line 27 of file Executor.hpp.

Constructor & Destructor Documentation

◆ MacroExecutor()

Ark::internal::MacroExecutor::MacroExecutor ( MacroProcessor macroprocessor,
unsigned  debug = 0 
)

Construct a new Macro Executor object.

Parameters
macroprocessor
debug

Definition at line 7 of file Executor.cpp.

◆ ~MacroExecutor()

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

Need a virtual destructor to correctly destory object.

Definition at line 12 of file Executor.cpp.

Member Function Documentation

◆ applyMacro()

virtual bool Ark::internal::MacroExecutor::applyMacro ( Node node)
pure virtual

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

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

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

◆ applyMacroProxy()

bool Ark::internal::MacroExecutor::applyMacroProxy ( Node node)
protected

Execute a node, trying to emplace macros calls.

Proxy function for MacroProcessor::applyMacro

Parameters
node
Returns
true
false

Definition at line 45 of file Executor.cpp.

References Ark::internal::MacroProcessor::applyMacro(), and m_macroprocessor.

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

◆ 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::SymbolExecutor, Ark::internal::ListExecutor, and Ark::internal::ConditionalExecutor.

◆ evaluate()

Node Ark::internal::MacroExecutor::evaluate ( Node node,
bool  is_not_body 
)
protected

Evaluate only the macros.

Proxy function for MacroProcessor::evaluate

Parameters
node
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 30 of file Executor.cpp.

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

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

◆ findNearestMacro()

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

Find the nearest macro matching a giving name.

Proxy function for MacroProcessor::findNearestMacro

Parameters
name
Returns
Node* nullptr if no macro was found

Definition at line 15 of file Executor.cpp.

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

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

◆ isPredefined()

bool Ark::internal::MacroExecutor::isPredefined ( const std::string &  symbol)
protected

Check if a given symbol is a predefined macro.

Proxy function for MacroProcessor::isPredefined

Parameters
symbol
Returns
true
false

Definition at line 50 of file Executor.cpp.

References Ark::internal::MacroProcessor::isPredefined(), and m_macroprocessor.

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

◆ isTruthy()

bool Ark::internal::MacroExecutor::isTruthy ( const Node node)
protected

Check if a node can be evaluated to true.

Proxy function for MacroProcessor::isTruthy

Parameters
node
Returns
true
false

Definition at line 25 of file Executor.cpp.

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

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

◆ registerMacro()

void Ark::internal::MacroExecutor::registerMacro ( Node node)
protected

Registers macros based on their type.

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

Parameters
nodeA node of type Macro

Definition at line 20 of file Executor.cpp.

References m_macroprocessor, and Ark::internal::MacroProcessor::registerMacro().

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

◆ throwMacroProcessingError()

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

Throw a macro processing error.

Proxy function for MacroProcessor::throwMacroProcessingError

Parameters
messagethe error
nodethe node in which there is an error

Definition at line 40 of file Executor.cpp.

References m_macroprocessor, and Ark::internal::MacroProcessor::throwMacroProcessingError().

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

◆ unify()

void Ark::internal::MacroExecutor::unify ( const std::unordered_map< std::string, Node > &  map,
Node target,
Node parent 
)
protected

Applies the spread operator.

Proxy function for MacroProcessor::unify

Definition at line 35 of file Executor.cpp.

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

Member Data Documentation

◆ m_debug

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

Definition at line 62 of file Executor.hpp.

◆ m_macroprocessor


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