#ifndef error_hh #define error_hh #include "ansicolor.hh" #include #include #include #include #include "types.hh" namespace nix { typedef enum { elWarning, elError } ErrLevel; class ErrPos { public: int lineNumber; int column; string nixFile; template ErrPos& operator=(const P &pos) { lineNumber = pos.line; column = pos.column; nixFile = pos.file; return *this; } template ErrPos(const P &p) { *this = p; } }; class NixCode { public: ErrPos errPos; std::optional prevLineOfCode; string errLineOfCode; std::optional nextLineOfCode; }; // ---------------------------------------------------------------- // format function for hints. same as fmt, except templated values // are always in yellow. template class yellowify { public: yellowify(T &s) : value(s) {} T &value; }; template std::ostream& operator<<(std::ostream &out, const yellowify &y) { return out << ANSI_YELLOW << y.value << ANSI_NORMAL; } class hintformat { public: hintformat(string format) :fmt(format) { fmt.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); } template hintformat& operator%(const T &value) { fmt % yellowify(value); return *this; } std::string str() const { return fmt.str(); } template friend class AddHint; private: format fmt; }; std::ostream& operator<<(std::ostream &os, const hintformat &hf) { return os << hf.str(); } template inline hintformat hintfmt(const std::string & fs, const Args & ... args) { hintformat f(fs); formatHelper(f, args...); return f; } // ------------------------------------------------- // ErrorInfo. class ErrorInfo { public: ErrLevel level; string name; string description; std::optional hint; std::optional nixCode; static std::optional programName; private: }; // -------------------------------------------------------- // error printing // just to cout for now. void printErrorInfo(const ErrorInfo &einfo); } #endif