12 m_type(node_type), m_value(value), m_pos()
16 m_type(node_type), m_pos()
27 m_type(
NodeType::
Number), m_value(static_cast<double>(value)), m_pos()
40 return std::get<std::string>(
m_value);
45 return std::get<double>(
m_value);
50 return std::get<Keyword>(
m_value);
55 return std::get<Namespace>(
m_value);
60 return std::get<Namespace>(
m_value);
65 list().push_back(node);
70 return std::get<std::vector<Node>>(
m_value);
75 return std::get<std::vector<Node>>(
m_value);
103 m_type = source.m_type;
104 m_value = source.m_value;
114 m_unqualified_name = name;
124 m_filename = source.m_filename;
125 m_pos = source.m_pos;
197 data +=
"\"" +
string() +
"\"";
201 data += fmt::format(
"{}",
number());
214 assert(
false &&
"Alt syntax nodes can only be begin or list");
217 for (std::size_t i = 1, end =
constList().size(); i < end; ++i)
226 else if (open ==
'[')
232 for (std::size_t i = 0, end =
constList().size(); i < end; ++i)
243 for (std::size_t i = 0, end =
constList().size(); i < end; ++i)
253 for (std::size_t i = 0, end =
constList().size(); i < end; ++i)
284 os <<
"Symbol:" << string();
288 os <<
"Capture:" << string();
308 os <<
"String:" << string();
312 os <<
"Number:" << number();
317 for (
const auto& i : constList())
318 i.debugPrint(os) <<
" ";
324 for (
const auto& i : constList())
325 i.debugPrint(os) <<
" ";
331 for (
const auto& i : constList())
332 i.debugPrint(os) <<
" ";
337 os <<
"Spread:" << string();
342 const auto details = constArkNamespace();
343 os <<
"( Namespace:" << details.name <<
" ";
344 details.ast->debugPrint(os) <<
" )";
391 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.
bool isAnonymousFunction() const noexcept
Check if a node is an anonymous function.
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)
const std::vector< Node > & constList() const noexcept
Return the list of sub-nodes held by the node.
void setAltSyntax(bool toggle)
Set the m_alt_syntax flag of the node.
bool m_alt_syntax
Used to tell if a node uses the alternative syntax (if available), eg (begin) / {}...
Keyword keyword() const noexcept
Return the keyword held by the value (if the node type allows it)
void setFunctionKind(bool anonymous)
Set the m_is_anonymous_function flag on the node.
Namespace & arkNamespace() noexcept
Return the namespace held by the value (if the node type allows it)
const std::optional< std::string > & getUnqualifiedName() const noexcept
Get the unqualified name, if it has been set.
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,...
std::optional< std::string > m_unqualified_name
Used by Capture nodes, to have the FQN in the value, and the captured name here.
void setUnqualifiedName(const std::string &name) noexcept
Set the unqualified name (used by Capture nodes)
void setPositionFrom(const Node &source) noexcept
Position the current node at a given span in a file.
std::ostream & debugPrint(std::ostream &os) const noexcept
Print a node to an output stream with added type annotations.
FileSpan position() const noexcept
Get the span of the node (start and end)
const Namespace & constArkNamespace() const noexcept
Return the namespace held by the value (if the node type allows it)
bool m_is_anonymous_function
Function nodes are marked as anonymous/non-anonymous by the ASTLowerer, to enable some optimisations.
const std::string & commentAfter() const noexcept
Return the comment attached after this node, if any.
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.
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.
bool isFunction() const noexcept
Check if the node is a function.
Node & attachCommentAfter(const std::string &comment)
Set the comment_after field with the nearest comment after this node.
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()
Describes a span for a node/atom in a file, its start position and end position.
std::shared_ptr< Node > ast