12#ifndef INCLUDE_ARK_EXCEPTIONS_HPP
13#define INCLUDE_ARK_EXCEPTIONS_HPP
32 class Error :
public std::runtime_error
35 explicit Error(
const std::string& message) :
36 std::runtime_error(message)
61 "ZeroDivisionError: In ordinary arithmetic, the expression has no meaning, "
62 "as there is no number which, when multiplied by 0, gives a (assuming a != 0), "
63 "and so division by zero is undefined. Since any number multiplied by 0 is 0, "
64 "the expression 0/0 is also undefined.")
76 Error(
"AssertionFailed: " + message)
88 const std::size_t
col;
90 const std::optional<internal::utf8_char_t>
symbol;
93 const std::string& what,
94 std::string filename_,
95 const std::size_t lineNum,
96 const std::size_t column,
98 const std::optional<internal::utf8_char_t> opt_sym = std::nullopt) :
104 namespace Diagnostics
116 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);
An assertion error, only triggered from ArkScript code through (assert expr error-message)
AssertionFailed(const std::string &message)
Error(const std::string &message)
A type error triggered when types don't match.
TypeError(const std::string &message)
A special zero division error triggered when a number is divided by 0.
A node of an Abstract Syntax Tree for ArkScript.
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 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.
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.
CodeError thrown by the compiler (parser, macro processor, optimizer, and compiler itself)
const std::string filename
const std::optional< internal::utf8_char_t > symbol
CodeError(const std::string &what, std::string filename_, const std::size_t lineNum, const std::size_t column, std::string exp, const std::optional< internal::utf8_char_t > opt_sym=std::nullopt)