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{
5 MacroScope::MacroScope(const unsigned int depth) :
6 m_depth(depth)
7 {}
8
9 const Node* MacroScope::has(const std::string& name) const
10 {
11 if (const auto res = m_macros.find(name); res != m_macros.end())
12 return &res->second;
13 return nullptr;
14 }
15
16 void MacroScope::add(const std::string& name, const Node& node)
17 {
18 m_macros[name] = node;
19 }
20
21 bool MacroScope::remove(const std::string& name)
22 {
23 if (const auto res = m_macros.find(name); res != m_macros.end())
24 {
25 m_macros.erase(res);
26 return true;
27 }
28 return false;
29 }
30}
Defines tools to handle macro definitions.
bool remove(const std::string &name)
Remove a macro in the scope, if it exists.
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:9
std::unordered_map< std::string, Node > m_macros
MacroScope(unsigned int depth)
Construct a new MacroScope object given a depth in the scope hierarchy.
Definition MacroScope.cpp:5
void add(const std::string &name, const Node &node)
Add a new entry in the scope.
A node of an Abstract Syntax Tree for ArkScript.
Definition Node.hpp:31