ArkScript
A small, fast, functional and scripting language for video games
MacroScope.cpp
Go to the documentation of this file.
2
3namespace Ark::internal
4{
6 m_depth(0)
7 {}
8
9 MacroScope::MacroScope(unsigned int depth) :
10 m_depth(depth)
11 {}
12
13 const Node* MacroScope::has(const std::string& name) const
14 {
15 if (auto res = m_macros.find(name); res != m_macros.end())
16 return &res->second;
17 return nullptr;
18 }
19
20 void MacroScope::add(const std::string& name, const Node& node)
21 {
22 m_macros[name] = node;
23 }
24
25 bool MacroScope::remove(const std::string& name)
26 {
27 if (auto res = m_macros.find(name); res != m_macros.end())
28 {
29 m_macros.erase(res);
30 return true;
31 }
32 return false;
33 }
34}
Defines tools to handle macro definitions.
bool remove(const std::string &name)
Remove a macro in the scope, if it exists.
Definition: MacroScope.cpp:25
const Node * has(const std::string &name) const
Check if the current scope holds a value for a given symbol, and returns it as a pointer.
Definition: MacroScope.cpp:13
std::unordered_map< std::string, Node > m_macros
Definition: MacroScope.hpp:76
void add(const std::string &name, const Node &node)
Add a new entry in the scope.
Definition: MacroScope.cpp:20
A node of an Abstract Syntax Tree for ArkScript.
Definition: Node.hpp:29