ArkScript
A small, fast, functional and scripting language for video games
Ark::internal::Node Class Reference

A node of an Abstract Syntax Tree for ArkScript. More...

#include <Node.hpp>

+ Collaboration diagram for Ark::internal::Node:

Public Types

using Value = std::variant< double, std::string, Keyword >
 

Public Member Functions

 Node ()=default
 
 Node (long value) noexcept
 Construct a new Node object.
 
 Node (double value) noexcept
 Construct a new Node object.
 
 Node (const std::string &value) noexcept
 Construct a new Node object.
 
 Node (Keyword value) noexcept
 Construct a new Node object.
 
 Node (NodeType type) noexcept
 Construct a new Node object, does not set the value.
 
 Node (const Node &other) noexcept
 Construct a new Node object.
 
Nodeoperator= (Node other) noexcept
 Construct a new Node object.
 
void swap (Node &other) noexcept
 Construct a new Node object.
 
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)
 
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.
 
void setNodeType (NodeType type) noexcept
 Set the Node Type object.
 
void setString (const std::string &value) noexcept
 Set the String object.
 
void setNumber (double value) noexcept
 Set the Number object.
 
void setKeyword (Keyword kw) noexcept
 Set the Keyword 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.
 
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.
 

Static Public Member Functions

static const NodegetTrueNode ()
 Provide a statically initialized / correct and guaranteed to be initialized Node representing "true".
 
static const NodegetFalseNode ()
 Provide a statically initialized / correct and guaranteed to be initialized Node representing "false".
 
static const NodegetNilNode ()
 Provide a statically initialized / correct and guaranteed to be initialized Node representing "Nil".
 
static const NodegetListNode ()
 Provide a statically initialized / correct and guaranteed to be initialized Node representing "Empty List".
 

Private Member Functions

 Node (const std::string &value, NodeType const &type) noexcept
 Construct a new Node object. This is private because it is only used by the static member of this class to generate specialized versions of the node.
 

Private Attributes

NodeType m_type
 
Value m_value
 
std::vector< Nodem_list
 
std::size_t m_line = 0
 
std::size_t m_col = 0
 
std::string m_filename = ""
 

Friends

std::ostream & operator<< (std::ostream &os, const Node &N) noexcept
 
void swap (Node &lhs, Node &rhs) noexcept
 
bool operator== (const Node &A, const Node &B)
 
bool operator< (const Node &A, const Node &B)
 
bool operator! (const Node &A)
 

Detailed Description

A node of an Abstract Syntax Tree for ArkScript.

Definition at line 28 of file Node.hpp.

Member Typedef Documentation

◆ Value

using Ark::internal::Node::Value = std::variant<double, std::string, Keyword>

Definition at line 31 of file Node.hpp.

Constructor & Destructor Documentation

◆ Node() [1/8]

Ark::internal::Node::Node ( )
default

◆ Node() [2/8]

Ark::internal::Node::Node ( long  value)
explicitnoexcept

Construct a new Node object.

Parameters
value

Definition at line 35 of file Node.cpp.

◆ Node() [3/8]

Ark::internal::Node::Node ( double  value)
explicitnoexcept

Construct a new Node object.

Parameters
value

Definition at line 40 of file Node.cpp.

◆ Node() [4/8]

Ark::internal::Node::Node ( const std::string &  value)
explicitnoexcept

Construct a new Node object.

Parameters
value

Definition at line 50 of file Node.cpp.

◆ Node() [5/8]

Ark::internal::Node::Node ( Keyword  value)
explicitnoexcept

Construct a new Node object.

Parameters
value

Definition at line 54 of file Node.cpp.

◆ Node() [6/8]

Ark::internal::Node::Node ( NodeType  type)
explicitnoexcept

Construct a new Node object, does not set the value.

Parameters
type

Definition at line 59 of file Node.cpp.

◆ Node() [7/8]

Ark::internal::Node::Node ( const Node other)
noexcept

Construct a new Node object.

Parameters
other

Definition at line 63 of file Node.cpp.

◆ Node() [8/8]

Ark::internal::Node::Node ( const std::string &  value,
NodeType const &  type 
)
explicitprivatenoexcept

Construct a new Node object. This is private because it is only used by the static member of this class to generate specialized versions of the node.

Parameters
value
type

Definition at line 45 of file Node.cpp.

Member Function Documentation

◆ col()

std::size_t Ark::internal::Node::col ( ) const
noexcept

Get the column at which this node was created.

Returns
std::size_t

Definition at line 169 of file Node.cpp.

References m_col.

Referenced by Ark::JsonCompiler::_compile(), Ark::internal::make_node(), Ark::internal::make_node_list(), and Ark::internal::makeNodeBasedErrorCtx().

◆ constList()

◆ filename()

const std::string & Ark::internal::Node::filename ( ) const
noexcept

Return the filename in which this node was created.

Returns
const std::string&

Definition at line 174 of file Node.cpp.

References m_filename.

Referenced by Ark::JsonCompiler::_compile(), and Ark::internal::makeNodeBasedErrorCtx().

◆ getFalseNode()

const Node & Ark::internal::Node::getFalseNode ( )
static

Provide a statically initialized / correct and guaranteed to be initialized Node representing "false".

Definition at line 16 of file Node.cpp.

References Ark::internal::Symbol.

Referenced by Ark::internal::MacroProcessor::evaluate().

◆ getListNode()

const Node & Ark::internal::Node::getListNode ( )
static

Provide a statically initialized / correct and guaranteed to be initialized Node representing "Empty List".

Definition at line 28 of file Node.cpp.

References Ark::internal::Symbol.

Referenced by Ark::internal::FunctionExecutor::applyMacro(), and Ark::internal::MacroProcessor::evaluate().

◆ getNilNode()

const Node & Ark::internal::Node::getNilNode ( )
static

Provide a statically initialized / correct and guaranteed to be initialized Node representing "Nil".

Definition at line 22 of file Node.cpp.

References Ark::internal::Symbol.

Referenced by Ark::internal::ConditionalExecutor::applyMacro(), and Ark::internal::MacroProcessor::evaluate().

◆ getTrueNode()

const Node & Ark::internal::Node::getTrueNode ( )
static

Provide a statically initialized / correct and guaranteed to be initialized Node representing "true".

Definition at line 10 of file Node.cpp.

References Ark::internal::Symbol.

Referenced by Ark::internal::MacroProcessor::evaluate().

◆ keyword()

Keyword Ark::internal::Node::keyword ( ) const
noexcept

Return the keyword held by the value (if the node type allows it)

Returns
Keyword

Definition at line 102 of file Node.cpp.

References m_value.

Referenced by Ark::JsonCompiler::_compile(), Ark::internal::ConditionalExecutor::applyMacro(), Ark::internal::Parser::checkForInclude(), Ark::internal::MacroProcessor::registerMacro(), and Ark::internal::MacroProcessor::removeBegin().

◆ line()

std::size_t Ark::internal::Node::line ( ) const
noexcept

Get the line at which this node was created.

Returns
std::size_t

Definition at line 164 of file Node.cpp.

References m_line.

Referenced by Ark::JsonCompiler::_compile(), Ark::internal::make_node(), Ark::internal::make_node_list(), and Ark::internal::makeNodeBasedErrorCtx().

◆ list()

◆ nodeType()

◆ number()

double Ark::internal::Node::number ( ) const
noexcept

Return the number held by the value (if the node type allows it)

Returns
double

Definition at line 97 of file Node.cpp.

References m_value.

Referenced by Ark::JsonCompiler::_compile(), Ark::internal::MacroProcessor::evaluate(), and Ark::internal::MacroProcessor::isTruthy().

◆ operator=()

Node & Ark::internal::Node::operator= ( Node  other)
noexcept

Construct a new Node object.

Parameters
other

Definition at line 72 of file Node.cpp.

References Ark::internal::swap().

◆ push_back()

void Ark::internal::Node::push_back ( const Node node)
noexcept

◆ setFilename()

void Ark::internal::Node::setFilename ( const std::string &  filename)
noexcept

Set the original Filename where the node was.

Parameters
filename

Definition at line 159 of file Node.cpp.

Referenced by Ark::internal::Parser::feed(), Ark::internal::make_node(), and Ark::internal::make_node_list().

◆ setKeyword()

void Ark::internal::Node::setKeyword ( Keyword  kw)
noexcept

Set the Keyword object.

Parameters
kw

Definition at line 146 of file Node.cpp.

◆ setNodeType()

void Ark::internal::Node::setNodeType ( NodeType  type)
noexcept

◆ setNumber()

void Ark::internal::Node::setNumber ( double  value)
noexcept

Set the Number object.

Parameters
value

Definition at line 141 of file Node.cpp.

◆ setPos()

void Ark::internal::Node::setPos ( std::size_t  line,
std::size_t  col 
)
noexcept

Set the Position of the node in the text.

Parameters
line
col

Definition at line 153 of file Node.cpp.

Referenced by Ark::internal::make_node(), and Ark::internal::make_node_list().

◆ setString()

void Ark::internal::Node::setString ( const std::string &  value)
noexcept

Set the String object.

Parameters
value

Definition at line 136 of file Node.cpp.

Referenced by Ark::internal::Parser::atom(), and Ark::internal::MacroProcessor::evaluate().

◆ string()

◆ swap()

void Ark::internal::Node::swap ( Node other)
noexcept

Construct a new Node object.

Parameters
other

Definition at line 78 of file Node.cpp.

References Ark::internal::swap().

Friends And Related Function Documentation

◆ operator!

bool operator! ( const Node A)
friend

Definition at line 321 of file Node.cpp.

◆ operator<

bool operator< ( const Node A,
const Node B 
)
friend

Definition at line 301 of file Node.cpp.

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Node N 
)
friend

Definition at line 192 of file Node.cpp.

◆ operator==

bool operator== ( const Node A,
const Node B 
)
friend

Definition at line 285 of file Node.cpp.

◆ swap

void swap ( Node lhs,
Node rhs 
)
friend

Definition at line 188 of file Node.cpp.

Member Data Documentation

◆ m_col

std::size_t Ark::internal::Node::m_col = 0
private

Definition at line 244 of file Node.hpp.

Referenced by col().

◆ m_filename

std::string Ark::internal::Node::m_filename = ""
private

Definition at line 245 of file Node.hpp.

Referenced by filename().

◆ m_line

std::size_t Ark::internal::Node::m_line = 0
private

Definition at line 244 of file Node.hpp.

Referenced by line().

◆ m_list

std::vector<Node> Ark::internal::Node::m_list
private

Definition at line 242 of file Node.hpp.

Referenced by constList(), and list().

◆ m_type

NodeType Ark::internal::Node::m_type
private

Definition at line 240 of file Node.hpp.

Referenced by nodeType().

◆ m_value

Value Ark::internal::Node::m_value
private

Definition at line 241 of file Node.hpp.

Referenced by keyword(), number(), and string().


The documentation for this class was generated from the following files: