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, bool colorize)
 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::ostream &os=std::cout, bool colorize=true)
 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 bool colorize, 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::ostream & os = std::cout,
bool colorize = true )

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

Parameters
ecode error
osoutput stream
colorizegenerate colors or not

Definition at line 170 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(), Formatter::run(), and Formatter::runWithString().

◆ helper()

template<typename T >
void Ark::Diagnostics::helper ( std::ostream & os,
const std::string & message,
const bool colorize,
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 )

◆ isPairableChar()

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

Definition at line 24 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,
bool colorize )

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
colorizegenerate colors or not

Definition at line 86 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 148 of file Exceptions.cpp.

References ARK_NO_NAME_FILE, Ark::internal::Node::col(), Ark::internal::Node::filename(), helper(), Ark::internal::Node::isStringLike(), Ark::internal::Node::line(), Ark::Utils::readFile(), Ark::internal::Node::repr(), and Ark::internal::Node::string().

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