83 lines
1.3 KiB
C++
83 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "types.hh"
|
|
#include <string>
|
|
#include <optional>
|
|
|
|
using std::string;
|
|
using std::optional;
|
|
|
|
namespace nix {
|
|
|
|
enum ErrLevel
|
|
{ elWarning
|
|
, elError
|
|
};
|
|
|
|
class ColumnRange {
|
|
public:
|
|
unsigned int start;
|
|
unsigned int len;
|
|
};
|
|
|
|
class ErrLine {
|
|
public:
|
|
int lineNumber;
|
|
optional<ColumnRange> columnRange;
|
|
optional<string> prevLineOfCode;
|
|
string errLineOfCode;
|
|
optional<string> nextLineOfCode;
|
|
};
|
|
|
|
class NixCode {
|
|
public:
|
|
optional<string> nixFile;
|
|
optional<ErrLine> errLine;
|
|
};
|
|
|
|
|
|
class ErrorInfo {
|
|
public:
|
|
ErrLevel level;
|
|
string name;
|
|
string description;
|
|
string program;
|
|
optional<NixCode> nixCode;
|
|
string hint;
|
|
ErrorInfo& GetEI() { return *this; }
|
|
};
|
|
|
|
template <class T>
|
|
class AddName : private T
|
|
{
|
|
public:
|
|
T& name(const std::string &name){
|
|
GetEI().name = name;
|
|
return *this;
|
|
}
|
|
protected:
|
|
ErrorInfo& GetEI() { return T::GetEI(); }
|
|
};
|
|
|
|
template <class T>
|
|
class AddDescription : private T
|
|
{
|
|
public:
|
|
T& description(const std::string &description){
|
|
GetEI().description = description;
|
|
return *this;
|
|
}
|
|
protected:
|
|
ErrorInfo& GetEI() { return T::GetEI(); }
|
|
};
|
|
|
|
typedef AddName<AddDescription<ErrorInfo>> StandardError;
|
|
|
|
string showErrLine(ErrLine &errLine);
|
|
|
|
void print_code_lines(string &prefix, NixCode &nix_code);
|
|
|
|
void print_error(ErrorInfo &einfo);
|
|
}
|
|
|