51 lines
1.2 KiB
C++
51 lines
1.2 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,
|
|
int line,
|
|
std::string const& value="");
|
|
virtual ~Node();
|
|
|
|
// properties
|
|
// ----------
|
|
inline NodeType type() const { return m_type; }
|
|
inline int line() const { return m_line; }
|
|
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;
|
|
int m_line;
|
|
std::string m_value;
|
|
std::vector<std::shared_ptr<Node>> m_children;
|
|
};
|
|
}
|
|
|
|
#endif
|