muzgen/lib/Node.hpp

48 lines
1.1 KiB
C++

#ifndef muz_NODE_HPP
#define muz_NODE_HPP
#include "commons.hpp"
#define NODE_TYPE(G) \
G(NODE_UNDEFINED), \
G(NODE_NUM), G(NODE_IDENT), G(NODE_DIR_IDENT), \
G(NODE_OSQUARE), G(NODE_CSQUARE), \
G(NODE_PROG), G(NODE_DIR), G(NODE_CMD)
namespace muz
{
MUZ_ENUM(NodeType, NODE_TYPE);
MUZ_ERROR(node_error);
/**
* Represents a node of the abstract syntax tree.
**/
class Node
{
public:
explicit Node(NodeType type,
std::string const& value="");
virtual ~Node();
// properties
// ----------
inline NodeType type() const { return m_type; }
inline std::string value() const { return m_value; }
// children
// --------
void add_child(std::shared_ptr<Node> child);
std::shared_ptr<Node> child(size_t index) const;
inline size_t size() const { return m_children.size(); }
std::string string() const;
private:
NodeType m_type;
std::string m_value;
std::vector<std::shared_ptr<Node>> m_children;
};
}
#endif