12#ifndef COMPILER_AST_NODE_HPP
13#define COMPILER_AST_NODE_HPP
31 using Value = std::variant<double, std::string, Keyword>;
60 explicit Node(
long value)
noexcept;
67 explicit Node(
double value)
noexcept;
74 explicit Node(
const std::string& value)
noexcept;
116 const std::string&
string() const noexcept;
123 double number() const noexcept;
172 void setString(const std::
string& value) noexcept;
208 std::
size_t line() const noexcept;
215 std::
size_t col() const noexcept;
222 const std::
string&
filename() const noexcept;
224 friend std::ostream& operator<<(std::ostream& os, const
Node& N) noexcept;
226 friend
bool operator==(const
Node& A, const
Node& B);
227 friend
bool operator<(const
Node& A, const
Node& B);
228 friend
bool operator!(const
Node& A);
239 explicit
Node(const std::
string& value,
NodeType const& type) noexcept;
248 std::ostream& operator<<(std::ostream& os, const std::vector<
Node>& N) noexcept;
250 template <typename T>
253 Node n(std::forward<T>(value));
271 if (node.string() ==
"nil")
273 else if (node.string() ==
"true" || node.string() ==
"false")
277 auto c =
static_cast<std::size_t
>(node.nodeType());
Common code for the compiler.
A node of an Abstract Syntax Tree for ArkScript.
NodeType nodeType() const noexcept
Return the node type.
Node & operator=(Node other) noexcept
Construct a new Node object.
static const Node & getListNode()
Provide a statically initialized / correct and guaranteed to be initialized Node representing "Empty ...
void setNodeType(NodeType type) noexcept
Set the Node Type object.
const std::string & filename() const noexcept
Return the filename in which this node was created.
const std::string & string() const noexcept
Return the string held by the value (if the node type allows it)
void setPos(std::size_t line, std::size_t col) noexcept
Set the Position of the node in the text.
const std::vector< Node > & constList() const noexcept
Return the list of sub-nodes held by the node.
std::variant< double, std::string, Keyword > Value
std::vector< Node > m_list
void setKeyword(Keyword kw) noexcept
Set the Keyword object.
Keyword keyword() const noexcept
Return the keyword held by the value (if the node type allows it)
void setFilename(const std::string &filename) noexcept
Set the original Filename where the node was.
void setNumber(double value) noexcept
Set the Number object.
static const Node & getNilNode()
Provide a statically initialized / correct and guaranteed to be initialized Node representing "Nil".
std::size_t col() const noexcept
Get the column at which this node was created.
void push_back(const Node &node) noexcept
Every node has a list as well as a value so we can push_back on all node no matter their type.
void setString(const std::string &value) noexcept
Set the String object.
static const Node & getTrueNode()
Provide a statically initialized / correct and guaranteed to be initialized Node representing "true".
double number() const noexcept
Return the number held by the value (if the node type allows it)
static const Node & getFalseNode()
Provide a statically initialized / correct and guaranteed to be initialized Node representing "false"...
std::size_t line() const noexcept
Get the line at which this node was created.
friend void swap(Node &lhs, Node &rhs) noexcept
std::vector< Node > & list() noexcept
Return the list of sub-nodes held by the node.
std::string typeToString(const Node &node) noexcept
constexpr std::array< std::string_view, 11 > nodeTypes
Node make_node(T &&value, std::size_t line, std::size_t col, const std::string &file)
NodeType
The different node types available.
Keyword
The different keywords available.
Node make_node_list(std::size_t line, std::size_t col, const std::string &file)