ArkScript
A small, fast, functional and scripting language for video games
Ark::Diagnostics Namespace Reference

Classes

struct  LineColorContextCounts
 

Functions

ARK_API void makeContext (std::ostream &os, const std::string &code, std::size_t target_line, std::size_t col_start, std::size_t sym_size)
 Helper to create a colorized context to report errors to the user.
 
ARK_API std::string makeContextWithNode (const std::string &message, const internal::Node &node)
 Helper used by the compiler to generate a colorized context from a node.
 
ARK_API void generate (const CodeError &e, std::string code="", std::ostream &os=std::cout)
 Generate a diagnostic from an error and print it to the standard output.
 
bool isPairableChar (const char c)
 
void colorizeLine (const std::string &line, LineColorContextCounts &line_color_context_counts, std::ostream &ss)
 
template<typename T >
void helper (std::ostream &os, const std::string &message, const std::string &filename, const std::string &code, const T &expr, const std::size_t line, std::size_t column, const std::size_t sym_size)
 

Function Documentation

◆ colorizeLine()

void Ark::Diagnostics::colorizeLine ( const std::string &  line,
LineColorContextCounts line_color_context_counts,
std::ostream &  ss 
)

◆ generate()

void Ark::Diagnostics::generate ( const CodeError e,
std::string  code = "",
std::ostream &  os = std::cout 
)

Generate a diagnostic from an error and print it to the standard output.

Parameters
ecode error
codecode of the file in which the error occurred
osoutput stream

Definition at line 157 of file Exceptions.cpp.

References ARK_NO_NAME_FILE, Ark::CodeError::col, Ark::CodeError::expr, Ark::CodeError::filename, helper(), Ark::CodeError::line, Ark::Utils::readFile(), and Ark::CodeError::symbol.

Referenced by Ark::Welder::computeAST(), Ark::Welder::generateBytecode(), and Formatter::run().

◆ helper()

template<typename T >
void Ark::Diagnostics::helper ( std::ostream &  os,
const std::string &  message,
const std::string &  filename,
const std::string &  code,
const T &  expr,
const std::size_t  line,
std::size_t  column,
const std::size_t  sym_size 
)

Definition at line 124 of file Exceptions.cpp.

References ARK_NO_NAME_FILE, and makeContext().

Referenced by generate(), and makeContextWithNode().

◆ isPairableChar()

bool Ark::Diagnostics::isPairableChar ( const char  c)
inline

Definition at line 20 of file Exceptions.cpp.

Referenced by colorizeLine().

◆ makeContext()

void Ark::Diagnostics::makeContext ( std::ostream &  os,
const std::string &  code,
std::size_t  target_line,
std::size_t  col_start,
std::size_t  sym_size 
)

Helper to create a colorized context to report errors to the user.

Parameters
osstream in which the error will be written
codecontent of the source file where the error is
target_lineline where the error is
col_startwhere the error starts on the given line
sym_sizebad expression that triggered the error

Definition at line 79 of file Exceptions.cpp.

References colorizeLine(), and Ark::Utils::splitString().

Referenced by helper().

◆ makeContextWithNode()

std::string Ark::Diagnostics::makeContextWithNode ( const std::string &  message,
const internal::Node node 
)

Helper used by the compiler to generate a colorized context from a node.

Parameters
messageerror message to be included in the context
nodeAST node with the error
Returns
std::string

Definition at line 135 of file Exceptions.cpp.

References ARK_NO_NAME_FILE, Ark::internal::Node::col(), Ark::internal::Node::filename(), helper(), Ark::internal::Node::line(), Ark::internal::Node::nodeType(), Ark::Utils::readFile(), Ark::internal::Node::repr(), Ark::internal::Spread, Ark::internal::Node::string(), Ark::internal::String, and Ark::internal::Symbol.

Referenced by Ark::Compiler::compilerWarning().