11 m_type(node_type), m_value(value)
39 return std::get<std::string>(
m_value);
44 return std::get<double>(
m_value);
49 return std::get<Keyword>(
m_value);
54 return std::get<Namespace>(
m_value);
59 return std::get<Namespace>(
m_value);
64 list().push_back(node);
69 return std::get<std::vector<Node>>(
m_value);
74 return std::get<std::vector<Node>>(
m_value);
94 m_type = source.m_type;
95 m_value = source.m_value;
108 void Node::setPos(
const std::size_t line,
const std::size_t col)
noexcept
116 m_filename = filename;
178 data +=
"\"" +
string() +
"\"";
182 data += fmt::format(
"{}",
number());
187 for (std::size_t i = 0, end =
constList().size(); i < end; ++i)
197 for (std::size_t i = 0, end =
constList().size(); i < end; ++i)
207 for (std::size_t i = 0, end =
constList().size(); i < end; ++i)
238 os <<
"Symbol:" << string();
242 os <<
"Capture:" << string();
262 os <<
"String:" << string();
266 os <<
"Number:" << number();
271 for (
const auto& i : constList())
272 i.debugPrint(os) <<
" ";
278 for (
const auto& i : constList())
279 i.debugPrint(os) <<
" ";
285 for (
const auto& i : constList())
286 i.debugPrint(os) <<
" ";
291 os <<
"Spread:" << string();
296 const auto details = constArkNamespace();
297 os <<
"( Namespace:" << details.name <<
" ";
298 details.ast->debugPrint(os) <<
" )";
345 return (
static_cast<int>(A.
nodeType()) -
static_cast<int>(B.
nodeType())) < 0;
Common code for the compiler.
ArkScript homemade exceptions.
AST node used by the parser, optimizer and compiler.
A node of an Abstract Syntax Tree for ArkScript.
NodeType nodeType() const noexcept
Return the node type.
std::string m_after_comment
Comment after node.
void setNodeType(NodeType type) noexcept
Set the Node Type object.
bool isListLike() const noexcept
Check if the node is a list like node.
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.
Keyword keyword() const noexcept
Return the keyword held by the value (if the node type allows it)
Namespace & arkNamespace() noexcept
Return the namespace held by the value (if the node type allows it)
const std::string & comment() const noexcept
Return the comment attached to this node, if any.
Node & attachNearestCommentBefore(const std::string &comment)
Set the comment field with the nearest comment before this node.
std::string repr() const noexcept
Compute a representation of the node without any comments or additional sugar, colors,...
void setFilename(const std::string &filename) noexcept
Set the original Filename where the node was.
std::ostream & debugPrint(std::ostream &os) const noexcept
Print a node to an output stream with added type annotations.
const Namespace & constArkNamespace() const noexcept
Return the namespace held by the value (if the node type allows it)
const std::string & commentAfter() const noexcept
Return the comment attached after this node, if any.
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.
bool isStringLike() const noexcept
Check if the node is a string like node.
void setString(const std::string &value) noexcept
Set the String object.
double number() const noexcept
Return the number held by the value (if the node type allows it)
void updateValueAndType(const Node &source) noexcept
Copy a node to the current one, while keeping the filename and position in the file.
Node & attachCommentAfter(const std::string &comment)
Set the comment_after field with the nearest comment after this node.
std::size_t line() const noexcept
Get the line at which this node was created.
std::vector< Node > & list() noexcept
Return the list of sub-nodes held by the node.
bool operator<(const Namespace &, const Namespace &)
bool operator==(const Namespace &A, const Namespace &B)
NodeType
The different node types available.
const Node & getNilNode()
Keyword
The different keywords available.
const Node & getFalseNode()
const Node & getListNode()
constexpr std::array< std::string_view, 9 > keywords
List of available keywords in ArkScript.
const Node & getTrueNode()
std::shared_ptr< Node > ast