columnRange -> column

This commit is contained in:
Ben Burdette 2020-04-07 14:36:32 -06:00
parent 55c96b64e4
commit 00c507cc52
2 changed files with 9 additions and 18 deletions

View file

@ -46,8 +46,8 @@ ErrorInfo ErrorInfo::ProgramEI(ErrLevel level,
string showErrLine(const ErrLine &errLine) string showErrLine(const ErrLine &errLine)
{ {
if (errLine.columnRange.has_value()) { if (errLine.column > 0) {
return (format("(%1%:%2%)") % errLine.lineNumber % errLine.columnRange->start).str(); return (format("(%1%:%2%)") % errLine.lineNumber % errLine.column).str();
} else { } else {
return (format("(%1%)") % errLine.lineNumber).str(); return (format("(%1%)") % errLine.lineNumber).str();
}; };
@ -74,18 +74,14 @@ void printCodeLines(const string &prefix, const NixCode &nixCode)
<< std::endl; << std::endl;
// error arrows for the column range. // error arrows for the column range.
if (nixCode.errLine->columnRange.has_value()) { if (nixCode.errLine->column > 0) {
int start = nixCode.errLine->columnRange->start; int start = nixCode.errLine->column;
std::string spaces; std::string spaces;
for (int i = 0; i < start; ++i) { for (int i = 0; i < start; ++i) {
spaces.append(" "); spaces.append(" ");
} }
int len = nixCode.errLine->columnRange->len; std::string arrows("^");
std::string arrows;
for (int i = 0; i < len; ++i) {
arrows.append("^");
}
std::cout << format("%1% |%2%" ANSI_RED "%3%" ANSI_NORMAL) % prefix % spaces % arrows << std::endl; std::cout << format("%1% |%2%" ANSI_RED "%3%" ANSI_NORMAL) % prefix % spaces % arrows << std::endl;
} }

View file

@ -17,20 +17,13 @@ typedef enum {
elError elError
} ErrLevel; } ErrLevel;
class ColumnRange
{
public:
unsigned int start;
unsigned int len;
};
class ErrorInfo; class ErrorInfo;
class ErrLine class ErrLine
{ {
public: public:
int lineNumber; int lineNumber;
std::optional<ColumnRange> columnRange; int column;
std::optional<string> prevLineOfCode; std::optional<string> prevLineOfCode;
string errLineOfCode; string errLineOfCode;
std::optional<string> nextLineOfCode; std::optional<string> nextLineOfCode;
@ -107,6 +100,8 @@ public:
static std::optional<string> programName; static std::optional<string> programName;
ErrorInfo& set_name(const string &name) { this->name = name; return *this; }
static ErrorInfo ProgramError(const string &name, static ErrorInfo ProgramError(const string &name,
const string &description, const string &description,
const std::optional<hintformat> &hf); const std::optional<hintformat> &hf);
@ -165,7 +160,7 @@ private:
ErrLine errline; ErrLine errline;
errline.lineNumber = pos.line; errline.lineNumber = pos.line;
errline.columnRange = { .start = pos.column, .len = 1 }; errline.column = pos.column;
errline.prevLineOfCode = prevloc; errline.prevLineOfCode = prevloc;
errline.errLineOfCode = loc; errline.errLineOfCode = loc;
errline.nextLineOfCode = nextloc; errline.nextLineOfCode = nextloc;