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.
 
virtual ~MacroExecutor ()
 Need a virtual destructor to correctly destory object.
 
virtual bool applyMacro (Node &node)=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 registerMacro (Node &node)
 Registers macros based on their type.
 
bool isTruthy (const Node &node)
 Check if a node can be evaluated to true.
 
Node evaluate (Node &node, bool is_not_body)
 Evaluate only the macros.
 
void unify (const std::unordered_map< std::string, Node > &, Node &, Node *)
 Applies the spread operator.
 
void throwMacroProcessingError (const std::string &message, const Node &node)
 Throw a macro processing error.
 
bool applyMacroProxy (Node &node)
 Execute a node, trying to emplace macros calls.
 
bool isPredefined (const std::string &symbol)
 Check if a given symbol is a predefined macro.
 

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

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

◆ 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::FunctionExecutor::applyMacro().

◆ findNearestMacro()

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

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 15 of file Executor.cpp.

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

Referenced by Ark::internal::FunctionExecutor::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::FunctionExecutor::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::FunctionExecutor::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::FunctionExecutor::applyMacro().

Member Data Documentation

◆ m_debug

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

Definition at line 61 of file Executor.hpp.

◆ m_macroprocessor


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