ArkScript
A small, lisp-inspired, functional scripting language
Ark::Diagnostics Namespace Reference

Classes

struct  ErrorLocation
 
struct  LineColorContextCounts
 
class  Printer
 Source printer for diagnostics. More...
 
struct  Window
 

Functions

ARK_API void makeContext (const ErrorLocation &loc, std::ostream &os, const std::optional< CodeErrorContext > &maybe_context, bool colorize)
 Helper to create a colorized context to report errors to the user.
 
std::string makeContextWithNode (const std::string &message, const internal::Node &node, bool colorize=true)
 Helper used by the compiler to generate a colorized context from a node.
 
ARK_API void generateWithCode (const CodeError &e, const std::string &code, std::ostream &os=std::cerr, bool colorize=true)
 
ARK_API void generate (const CodeError &e, std::ostream &os=std::cerr, bool colorize=true)
 Generate a diagnostic from an error and print it to the standard error output.
 
void showFileLocation (std::ostream &os, const ErrorLocation &loc)
 
void hintWithContext (std::ostream &os, const std::optional< CodeErrorContext > &maybe_context, const bool colorize, const bool start)
 
void helper (std::ostream &os, const std::string &message, const bool colorize, const std::string &filename, const internal::FileSpan &at, const std::optional< CodeErrorContext > &maybe_context=std::nullopt, const std::optional< std::string > &maybe_file_content=std::nullopt)
 
bool isPairableChar (const char c)
 
void colorizeLine (const std::string &line, LineColorContextCounts &ctx, std::ostream &os)
 

Function Documentation

◆ colorizeLine()

◆ generate()

void Ark::Diagnostics::generate ( const CodeError & e,
std::ostream & os = std::cerr,
bool colorize = true )

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

Parameters
ecode error
osoutput stream
colorizegenerate colors or not

Definition at line 244 of file Diagnostics.cpp.

References Ark::CodeError::additional_context, Ark::CodeErrorContext::at, Ark::CodeError::context, Ark::CodeErrorContext::filename, and helper().

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

◆ generateWithCode()

void Ark::Diagnostics::generateWithCode ( const CodeError & e,
const std::string & code,
std::ostream & os = std::cerr,
bool colorize = true )

◆ helper()

void Ark::Diagnostics::helper ( std::ostream & os,
const std::string & message,
const bool colorize,
const std::string & filename,
const internal::FileSpan & at,
const std::optional< CodeErrorContext > & maybe_context = std::nullopt,
const std::optional< std::string > & maybe_file_content = std::nullopt )

◆ hintWithContext()

void Ark::Diagnostics::hintWithContext ( std::ostream & os,
const std::optional< CodeErrorContext > & maybe_context,
const bool colorize,
const bool start )

Definition at line 25 of file Diagnostics.cpp.

References Ark::Diagnostics::Printer::GhostLinePrefix.

Referenced by makeContext().

◆ isPairableChar()

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

Definition at line 15 of file PrettyPrinting.cpp.

Referenced by colorizeLine().

◆ makeContext()

◆ makeContextWithNode()

std::string Ark::Diagnostics::makeContextWithNode ( const std::string & message,
const internal::Node & node,
bool colorize = true )

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
colorizetoggle context colors (default: true)
Returns
std::string

Definition at line 213 of file Diagnostics.cpp.

References Ark::internal::Node::filename(), helper(), and Ark::internal::Node::position().

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

◆ showFileLocation()

void Ark::Diagnostics::showFileLocation ( std::ostream & os,
const ErrorLocation & loc )