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 &filename, const std::optional< std::string > &expr, std::size_t sym_size, std::size_t target_line, std::size_t col_start, const std::optional< CodeErrorContext > &maybe_context, bool whole_line, 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)
 
void helper (std::ostream &os, const std::string &message, const bool colorize, const std::string &filename, const std::optional< std::string > &expr, const std::size_t sym_size, const std::size_t line, const std::size_t column, const std::optional< CodeErrorContext > &maybe_context=std::nullopt)
 

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 326 of file Exceptions.cpp.

References Ark::CodeError::additional_context, Ark::CodeErrorContext::col, Ark::CodeError::context, Ark::CodeErrorContext::expr, Ark::CodeErrorContext::filename, helper(), Ark::CodeErrorContext::line, and Ark::CodeErrorContext::symbol.

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

◆ helper()

void Ark::Diagnostics::helper ( std::ostream & os,
const std::string & message,
const bool colorize,
const std::string & filename,
const std::optional< std::string > & expr,
const std::size_t sym_size,
const std::size_t line,
const std::size_t column,
const std::optional< CodeErrorContext > & maybe_context = std::nullopt )

Definition at line 292 of file Exceptions.cpp.

References helper(), makeContext(), and Ark::Utils::splitString().

Referenced by generate(), helper(), and makeContextWithNode().

◆ isPairableChar()

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

Definition at line 25 of file Exceptions.cpp.

Referenced by colorizeLine().

◆ makeContext()

void Ark::Diagnostics::makeContext ( std::ostream & os,
const std::string & filename,
const std::optional< std::string > & expr,
std::size_t sym_size,
std::size_t target_line,
std::size_t col_start,
const std::optional< CodeErrorContext > & maybe_context,
bool whole_line,
bool colorize )

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

Parameters
osstream in which the error will be written
filenamepath to the file in which the error is
exproptional expression causing the error
sym_sizelength of expression to underline (can be 0)
target_lineline where the error is
col_startwhere the error starts on the given line
maybe_contextoptional context, parent of the error
whole_linewhen true, underline the whole line, disregarding col_start and sym_size
colorizegenerate colors or not

Definition at line 87 of file Exceptions.cpp.

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

Referenced by Ark::VM::backtrace(), and 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 305 of file Exceptions.cpp.

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

Referenced by Ark::internal::ASTLowerer::warning().