ArkScript
A small, fast, functional and scripting language for video games
Symbol.cpp
Go to the documentation of this file.
2
3namespace Ark::internal
4{
6 {
7 return node.nodeType() == NodeType::Symbol;
8 }
9
10 bool SymbolExecutor::applyMacro(Node& node, const unsigned depth)
11 {
12 if (const Node* macro = findNearestMacro(node.string()); macro != nullptr)
13 {
14 // ($ name value)
15 if (macro->constList().size() == 2)
16 {
17 node.updateValueAndType(macro->constList()[1]);
18 node = evaluate(node, depth + 1, false);
19 applyMacroProxy(node, depth + 1);
20 return true;
21 }
22 }
23
24 return false;
25 }
26}
Executor for Symbol Macros.
void applyMacroProxy(Node &node, unsigned depth)
Apply a macro on a given node.
Definition Executor.cpp:17
Node evaluate(Node &node, unsigned depth, bool is_not_body) const
Evaluate only the macros.
Definition Executor.cpp:32
const Node * findNearestMacro(const std::string &name) const
Find the nearest macro matching a giving name.
Definition Executor.cpp:12
A node of an Abstract Syntax Tree for ArkScript.
Definition Node.hpp:31
NodeType nodeType() const noexcept
Return the node type.
Definition Node.cpp:77
const std::string & string() const noexcept
Return the string held by the value (if the node type allows it)
Definition Node.cpp:37
void updateValueAndType(const Node &source) noexcept
Copy a node to the current one, while keeping the filename and position in the file.
Definition Node.cpp:92
bool canHandle(Node &node) override
Definition Symbol.cpp:5
bool applyMacro(Node &node, unsigned depth) override
Definition Symbol.cpp:10