ArkScript
A small, fast, functional and scripting language for video games
Executor.cpp
Go to the documentation of this file.
2
4
5namespace Ark::internal
6{
7 MacroExecutor::MacroExecutor(MacroProcessor* processor, unsigned debug) :
8 m_debug(debug),
9 m_processor(processor)
10 {}
11
12 const Node* MacroExecutor::findNearestMacro(const std::string& name) const
13 {
14 return m_processor->findNearestMacro(name);
15 }
16
18 {
20 }
21
22 bool MacroExecutor::isTruthy(const Node& node) const
23 {
24 return m_processor->isTruthy(node);
25 }
26
27 Node MacroExecutor::evaluate(Node& node, const bool is_not_body) const
28 {
29 return m_processor->evaluate(node, is_not_body);
30 }
31
32 void MacroExecutor::unify(const std::unordered_map<std::string, Node>& map, Node& target, Node* parent) const
33 {
34 m_processor->unify(map, target, parent);
35 }
37 void MacroExecutor::throwMacroProcessingError(const std::string& message, const Node& node) const
38 {
40 }
41
43 {
44 return m_processor->applyMacro(node);
45 }
46
47 bool MacroExecutor::isPredefined(const std::string& symbol) const
48 {
49 return m_processor->isPredefined(symbol);
50 }
51}
The base class for all MacroExecutors.
Handles the macros and their expansion in ArkScript source code.
bool applyMacroProxy(Node &node) const
Execute a node, trying to emplace macros calls.
Definition: Executor.cpp:42
void throwMacroProcessingError(const std::string &message, const Node &node) const
Throw a macro processing error.
Definition: Executor.cpp:37
MacroExecutor(MacroProcessor *processor, unsigned debug=0)
Construct a new Macro Executor object.
Definition: Executor.cpp:7
MacroProcessor * m_processor
This is a non-owned pointer.
Definition: Executor.hpp:62
void unify(const std::unordered_map< std::string, Node > &, Node &, Node *) const
Applies the spread operator.
Definition: Executor.cpp:32
Node evaluate(Node &node, bool is_not_body) const
Evaluate only the macros.
Definition: Executor.cpp:27
void registerMacro(Node &node) const
Registers macros based on their type.
Definition: Executor.cpp:17
bool isTruthy(const Node &node) const
Check if a node can be evaluated to true.
Definition: Executor.cpp:22
bool isPredefined(const std::string &symbol) const
Check if a given symbol is a predefined macro.
Definition: Executor.cpp:47
const Node * findNearestMacro(const std::string &name) const
Find the nearest macro matching a giving name.
Definition: Executor.cpp:12
The class handling the macros definitions and calls, given an AST.
Definition: Processor.hpp:29
void unify(const std::unordered_map< std::string, Node > &map, Node &target, Node *parent, std::size_t index=0)
Unify a target node with a given map symbol => replacement node, recursively.
Definition: Processor.cpp:188
void registerMacro(Node &node)
Registers macros based on their type.
Definition: Processor.cpp:53
Node evaluate(Node &node, bool is_not_body=false)
Evaluate only the macros.
Definition: Processor.cpp:215
const Node * findNearestMacro(const std::string &name) const
Find the nearest macro matching a given name.
Definition: Processor.cpp:475
static bool isTruthy(const Node &node)
Check if a node can be evaluated to true.
Definition: Processor.cpp:459
static void throwMacroProcessingError(const std::string &message, const Node &node)
Throw a macro processing error.
Definition: Processor.cpp:584
bool isPredefined(const std::string &symbol)
Check if a given symbol is a predefined macro or not.
Definition: Processor.cpp:503
bool applyMacro(Node &node) const
Apply a macro on a given node.
Definition: Processor.cpp:183
A node of an Abstract Syntax Tree for ArkScript.
Definition: Node.hpp:30