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)
 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.
 
void showFileLocation (std::ostream &os, const ErrorLocation &loc)
 
void hintWithContext (std::ostream &os, const std::optional< CodeErrorContext > &maybe_context, const bool colorize)
 
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)
 
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::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 218 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().

◆ 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 )

Definition at line 189 of file Diagnostics.cpp.

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

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

◆ hintWithContext()

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

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 )

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 204 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 )