![]() |
ArkScript
A small, fast, functional and scripting language for video games
|
A node of an Abstract Syntax Tree for ArkScript. More...
#include <Node.hpp>
Public Types | |
using | Value = std::variant<double, std::string, Keyword, std::vector<Node>, Namespace> |
Public Member Functions | |
Node ()=default | |
Node (NodeType node_type, const std::string &value) | |
Node (NodeType node_type) | |
Node (double value) | |
Node (long value) | |
Node (Keyword value) | |
Node (Namespace namespace_) | |
const std::string & | string () const noexcept |
Return the string held by the value (if the node type allows it) | |
double | number () const noexcept |
Return the number held by the value (if the node type allows it) | |
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 Namespace & | constArkNamespace () const noexcept |
Return the namespace held by the value (if the node type allows it) | |
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. | |
std::vector< Node > & | list () noexcept |
Return the list of sub-nodes held by the node. | |
const std::vector< Node > & | constList () const noexcept |
Return the list of sub-nodes held by the node. | |
NodeType | nodeType () const noexcept |
Return the node type. | |
bool | isListLike () const noexcept |
Check if the node is a list like node. | |
bool | isStringLike () const noexcept |
Check if the node is a string like node. | |
void | updateValueAndType (const Node &source) noexcept |
Copy a node to the current one, while keeping the filename and position in the file. | |
void | setNodeType (NodeType type) noexcept |
Set the Node Type object. | |
void | setString (const std::string &value) noexcept |
Set the String object. | |
void | setPos (std::size_t line, std::size_t col) noexcept |
Set the Position of the node in the text. | |
void | setFilename (const std::string &filename) noexcept |
Set the original Filename where the node was. | |
Node & | attachNearestCommentBefore (const std::string &comment) |
Set the comment field with the nearest comment before this node. | |
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::size_t | col () const noexcept |
Get the column at which this node was created. | |
const std::string & | filename () const noexcept |
Return the filename in which this node was created. | |
const std::string & | comment () const noexcept |
Return the comment attached to this node, if any. | |
const std::string & | commentAfter () const noexcept |
Return the comment attached after this node, if any. | |
std::string | repr () const noexcept |
Compute a representation of the node without any comments or additional sugar, colors, types. | |
std::ostream & | debugPrint (std::ostream &os) const noexcept |
Print a node to an output stream with added type annotations. | |
Private Attributes | |
NodeType | m_type |
Value | m_value |
std::size_t | m_line = 0 |
std::size_t | m_col = 0 |
std::string | m_filename |
std::string | m_comment |
std::string | m_after_comment |
Comment after node. | |
Friends | |
bool | operator== (const Node &A, const Node &B) |
bool | operator< (const Node &A, const Node &B) |
using Ark::internal::Node::Value = std::variant<double, std::string, Keyword, std::vector<Node>, Namespace> |
|
default |
Ark::internal::Node::Node | ( | NodeType | node_type, |
const std::string & | value ) |
|
explicit |
Definition at line 14 of file Node.cpp.
References Ark::internal::Field, Ark::internal::List, m_type, m_value, and Ark::internal::Macro.
|
nodiscardnoexcept |
Return the namespace held by the value (if the node type allows it)
Definition at line 52 of file Node.cpp.
References m_value.
Referenced by Ark::internal::Optimizer::countAndPruneDeadCode(), Ark::internal::ImportSolver::findAndReplaceImports(), Ark::internal::MacroProcessor::processNode(), and Ark::internal::NameResolutionPass::visit().
Node & Ark::internal::Node::attachCommentAfter | ( | const std::string & | comment | ) |
Set the comment_after field with the nearest comment after this node.
comment |
Definition at line 125 of file Node.cpp.
References comment(), and m_after_comment.
Node & Ark::internal::Node::attachNearestCommentBefore | ( | const std::string & | comment | ) |
Set the comment field with the nearest comment before this node.
comment |
Definition at line 119 of file Node.cpp.
References comment(), and m_comment.
Referenced by Ark::internal::Parser::functionArgs(), Ark::internal::Parser::import_(), and Ark::internal::Parser::nil().
|
nodiscardnoexcept |
Get the column at which this node was created.
Definition at line 140 of file Node.cpp.
References m_col.
Referenced by JsonCompiler::_compile(), Ark::internal::NameResolutionPass::addSymbolNode(), Ark::internal::MacroProcessor::evaluate(), Ark::internal::ImportSolver::findAndReplaceImports(), Ark::Diagnostics::makeContextWithNode(), Ark::internal::Compiler::throwCompilerError(), Ark::internal::MacroProcessor::throwMacroProcessingError(), and Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName().
|
nodiscardnoexcept |
Return the comment attached to this node, if any.
Definition at line 150 of file Node.cpp.
References m_comment.
Referenced by attachCommentAfter(), attachNearestCommentBefore(), Formatter::format(), Formatter::formatFunction(), Formatter::formatImport(), and Formatter::shouldSplitOnNewline().
|
nodiscardnoexcept |
Return the comment attached after this node, if any.
Definition at line 155 of file Node.cpp.
References m_after_comment.
Referenced by Formatter::format().
|
nodiscardnoexcept |
|
nodiscardnoexcept |
Return the list of sub-nodes held by the node.
Definition at line 72 of file Node.cpp.
References m_value.
Referenced by JsonCompiler::_compile(), Ark::internal::ConditionalExecutor::applyMacro(), Ark::internal::FunctionExecutor::applyMacro(), Ark::internal::FunctionExecutor::canHandle(), Ark::internal::MacroProcessor::checkMacroArgCountEq(), Ark::internal::MacroProcessor::checkMacroArgCountGe(), Ark::internal::Compiler::compileExpression(), Ark::internal::Compiler::compileFunction(), Ark::internal::Compiler::compileIf(), Ark::internal::Compiler::compileLetMutSet(), Ark::internal::Compiler::compileListInstruction(), Ark::internal::Compiler::compilePluginImport(), Ark::internal::Compiler::compileWhile(), Ark::internal::Optimizer::countAndPruneDeadCode(), Ark::internal::MacroProcessor::evaluate(), Ark::internal::ImportSolver::findAndReplaceImports(), Formatter::format(), Formatter::formatBegin(), Formatter::formatBlock(), Formatter::formatCall(), Formatter::formatCondition(), Formatter::formatDel(), Formatter::formatFunction(), Formatter::formatImport(), Formatter::formatLoop(), Formatter::formatMacro(), Formatter::formatVariable(), Ark::internal::Compiler::handleCalls(), Ark::internal::MacroProcessor::handleMacroNode(), Ark::internal::MacroProcessor::isBeginNode(), Ark::internal::MacroProcessor::isConstEval(), Formatter::isFuncCall(), Formatter::isListStartingWithKeyword(), Formatter::lineOfLastNodeIn(), Ark::internal::Compiler::nodeProducesOutput(), Formatter::processAst(), Ark::internal::MacroProcessor::processNode(), Ark::internal::MacroProcessor::registerFuncDef(), Ark::internal::MacroProcessor::removeBegin(), repr(), Formatter::shouldAddNewLineBetweenNodes(), Formatter::shouldSplitOnNewline(), JsonCompiler::toJsonList(), Ark::internal::NameResolutionPass::visit(), and Ark::internal::NameResolutionPass::visitKeyword().
|
nodiscardnoexcept |
Print a node to an output stream with added type annotations.
os |
Definition at line 233 of file Node.cpp.
References Ark::internal::Begin, Ark::internal::Capture, Ark::internal::Del, Ark::internal::Field, Ark::internal::Fun, Ark::internal::If, Ark::internal::Import, Ark::internal::Keyword, Ark::internal::Let, Ark::internal::List, Ark::internal::Macro, Ark::internal::Mut, Ark::internal::Namespace, Ark::internal::Number, Ark::internal::Set, Ark::internal::Spread, Ark::internal::String, Ark::internal::Symbol, Ark::internal::Unused, and Ark::internal::While.
Referenced by Ark::internal::MacroProcessor::process(), Ark::internal::NameResolutionPass::process(), and Ark::internal::Optimizer::process().
|
nodiscardnoexcept |
Return the filename in which this node was created.
Definition at line 145 of file Node.cpp.
References m_filename.
Referenced by JsonCompiler::_compile(), Ark::internal::NameResolutionPass::addSymbolNode(), Ark::internal::MacroProcessor::evaluate(), Ark::internal::ImportSolver::findAndReplaceImports(), Ark::Diagnostics::makeContextWithNode(), Ark::internal::Compiler::throwCompilerError(), Ark::internal::MacroProcessor::throwMacroProcessingError(), Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName(), Ark::internal::NameResolutionPass::visit(), and Ark::internal::NameResolutionPass::visitKeyword().
|
nodiscardnoexcept |
Check if the node is a list like node.
Definition at line 82 of file Node.cpp.
References Ark::internal::List, m_type, and Ark::internal::Macro.
Referenced by Ark::internal::Optimizer::countAndPruneDeadCode(), Formatter::formatFunction(), Formatter::isFuncCall(), Formatter::isListStartingWithKeyword(), Formatter::lineOfLastNodeIn(), Ark::internal::MacroProcessor::removeBegin(), Formatter::shouldSplitOnNewline(), and Ark::internal::FunctionExecutor::unify().
|
nodiscardnoexcept |
Check if the node is a string like node.
Definition at line 87 of file Node.cpp.
References m_type, Ark::internal::Spread, Ark::internal::String, and Ark::internal::Symbol.
Referenced by Ark::Diagnostics::makeContextWithNode().
|
nodiscardnoexcept |
Return the keyword held by the value (if the node type allows it)
Definition at line 47 of file Node.cpp.
References m_value.
Referenced by JsonCompiler::_compile(), Formatter::format(), Formatter::formatBlock(), Ark::internal::MacroProcessor::removeBegin(), and repr().
|
nodiscardnoexcept |
Get the line at which this node was created.
Definition at line 135 of file Node.cpp.
References m_line.
Referenced by JsonCompiler::_compile(), Ark::internal::NameResolutionPass::addSymbolNode(), Ark::internal::MacroProcessor::evaluate(), Ark::internal::ImportSolver::findAndReplaceImports(), Formatter::lineOfLastNodeIn(), Ark::Diagnostics::makeContextWithNode(), Ark::internal::Compiler::throwCompilerError(), Ark::internal::MacroProcessor::throwMacroProcessingError(), and Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName().
|
noexcept |
Return the list of sub-nodes held by the node.
Definition at line 67 of file Node.cpp.
References m_value.
Referenced by Ark::internal::ConditionalExecutor::applyMacro(), Ark::internal::FunctionExecutor::applyMacro(), Ark::internal::ConditionalExecutor::canHandle(), Ark::internal::Optimizer::countAndPruneDeadCode(), Ark::internal::MacroProcessor::evaluate(), Ark::internal::ImportSolver::findAndReplaceImports(), Ark::internal::MacroProcessor::handleMacroNode(), Ark::internal::Parser::import_(), Ark::internal::Parser::process(), Ark::internal::MacroProcessor::processNode(), Ark::internal::Optimizer::pruneUnusedGlobalVariables(), Ark::internal::MacroProcessor::removeBegin(), Ark::internal::FunctionExecutor::unify(), Ark::internal::NameResolutionPass::visit(), and Ark::internal::NameResolutionPass::visitKeyword().
|
nodiscardnoexcept |
Return the node type.
Definition at line 77 of file Node.cpp.
References m_type.
Referenced by JsonCompiler::_compile(), Ark::internal::ConditionalExecutor::applyMacro(), Ark::internal::ConditionalExecutor::canHandle(), Ark::internal::FunctionExecutor::canHandle(), Ark::internal::SymbolExecutor::canHandle(), Ark::internal::Compiler::compileExpression(), Ark::internal::Optimizer::countAndPruneDeadCode(), Ark::internal::MacroProcessor::evaluate(), Ark::internal::ImportSolver::findAndReplaceImports(), Formatter::format(), Formatter::formatBlock(), Ark::internal::Parser::function(), Ark::internal::MacroProcessor::handleMacroNode(), Ark::internal::MacroProcessor::isBeginNode(), Ark::internal::MacroProcessor::isConstEval(), Ark::internal::MacroProcessor::isTruthy(), Ark::internal::Compiler::nodeProducesOutput(), Ark::internal::Optimizer::process(), Ark::internal::MacroProcessor::processNode(), Ark::internal::MacroProcessor::registerFuncDef(), Ark::internal::MacroProcessor::removeBegin(), Ark::internal::FunctionExecutor::unify(), and Ark::internal::NameResolutionPass::visit().
|
nodiscardnoexcept |
Return the number held by the value (if the node type allows it)
Definition at line 42 of file Node.cpp.
References m_value.
Referenced by JsonCompiler::_compile(), Ark::internal::MacroProcessor::evaluate(), Formatter::format(), Ark::internal::MacroProcessor::isTruthy(), and repr().
|
noexcept |
Every node has a list as well as a value so we can push_back on all node no matter their type.
node | a sub-node to push on the list held by the current node |
Definition at line 62 of file Node.cpp.
Referenced by Ark::internal::MacroProcessor::evaluate(), Ark::internal::ImportSolver::findAndReplaceImports(), Ark::internal::Parser::import_(), and Ark::internal::Parser::process().
|
nodiscardnoexcept |
Compute a representation of the node without any comments or additional sugar, colors, types.
Definition at line 160 of file Node.cpp.
References Ark::internal::Namespace::ast, Ark::internal::Capture, constArkNamespace(), constList(), Ark::internal::Field, Ark::internal::Keyword, keyword(), Ark::internal::keywords, Ark::internal::List, m_type, Ark::internal::Macro, Ark::internal::Namespace, Ark::internal::Number, number(), Ark::internal::Spread, Ark::internal::String, string(), Ark::internal::Symbol, and Ark::internal::Unused.
Referenced by Ark::internal::MacroProcessor::evaluate(), Ark::Diagnostics::makeContextWithNode(), Ark::internal::Compiler::throwCompilerError(), Ark::internal::MacroProcessor::throwMacroProcessingError(), and Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName().
|
noexcept |
Set the original Filename where the node was.
filename |
Definition at line 114 of file Node.cpp.
Referenced by Ark::internal::MacroProcessor::evaluate().
|
noexcept |
Set the Node Type object.
type |
Definition at line 98 of file Node.cpp.
Referenced by Ark::internal::ConditionalExecutor::applyMacro(), Ark::internal::MacroProcessor::evaluate(), and Ark::internal::FunctionExecutor::unify().
|
noexcept |
Set the Position of the node in the text.
line | |
col |
Definition at line 108 of file Node.cpp.
Referenced by Ark::internal::MacroProcessor::evaluate(), and Ark::internal::Parser::setNodePosAndFilename().
|
noexcept |
Set the String object.
value |
Definition at line 103 of file Node.cpp.
Referenced by Ark::internal::MacroProcessor::evaluate(), and Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName().
|
nodiscardnoexcept |
Return the string held by the value (if the node type allows it)
Definition at line 37 of file Node.cpp.
References m_value.
Referenced by JsonCompiler::_compile(), Ark::internal::Compiler::addSymbol(), Ark::internal::NameResolutionPass::addSymbolNode(), Ark::internal::FunctionExecutor::applyMacro(), Ark::internal::SymbolExecutor::applyMacro(), Ark::internal::Compiler::compileListInstruction(), Ark::internal::Compiler::compileSymbol(), Ark::internal::Optimizer::countAndPruneDeadCode(), Ark::internal::MacroProcessor::evaluate(), Formatter::format(), Ark::internal::Parser::function(), Ark::internal::MacroProcessor::handleMacroNode(), Ark::internal::MacroProcessor::isConstEval(), Ark::internal::MacroProcessor::isTruthy(), Ark::Diagnostics::makeContextWithNode(), Ark::internal::MacroProcessor::registerFuncDef(), repr(), Ark::internal::FunctionExecutor::unify(), Ark::internal::NameResolutionPass::updateSymbolWithFullyQualifiedName(), and Ark::internal::NameResolutionPass::visit().
|
noexcept |
Copy a node to the current one, while keeping the filename and position in the file.
source | node to copy type and value from |
Definition at line 92 of file Node.cpp.
Referenced by Ark::internal::ConditionalExecutor::applyMacro(), Ark::internal::FunctionExecutor::applyMacro(), Ark::internal::SymbolExecutor::applyMacro(), and Ark::internal::MacroProcessor::evaluate().
|
private |
Comment after node.
Definition at line 228 of file Node.hpp.
Referenced by attachCommentAfter(), and commentAfter().
|
private |
|
private |
Definition at line 227 of file Node.hpp.
Referenced by attachNearestCommentBefore(), and comment().
|
private |
Definition at line 226 of file Node.hpp.
Referenced by filename().
|
private |
|
private |
Definition at line 222 of file Node.hpp.
Referenced by isListLike(), isStringLike(), Node(), nodeType(), and repr().
|
private |
Definition at line 223 of file Node.hpp.
Referenced by arkNamespace(), constArkNamespace(), constList(), keyword(), list(), Node(), number(), and string().