Util: Change Lexer line/column to 0-based
This commit is contained in:
+8
-10
@@ -60,17 +60,15 @@ void Job::printErrorLine(Token token, const char* message)
|
|||||||
"%s"
|
"%s"
|
||||||
"\n";
|
"\n";
|
||||||
printf(errorFormat.c_str(),
|
printf(errorFormat.c_str(),
|
||||||
token.line,
|
token.line + 1,
|
||||||
token.column,
|
token.column + 1,
|
||||||
message);
|
message);
|
||||||
|
|
||||||
// Get the JSON line that caused the error
|
// Get the JSON line that caused the error
|
||||||
std::istringstream input(m_input);
|
std::istringstream input(m_input);
|
||||||
std::string line;
|
std::string line;
|
||||||
size_t count = 0;
|
for (size_t i = 0; std::getline(input, line); ++i) {
|
||||||
while (std::getline(input, line)) {
|
if (i == token.line) {
|
||||||
count++;
|
|
||||||
if (count == token.line) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,9 +90,9 @@ void Job::printErrorLine(Token token, const char* message)
|
|||||||
"\033[0m" // Reset
|
"\033[0m" // Reset
|
||||||
"\n";
|
"\n";
|
||||||
printf(lineFormat.c_str(),
|
printf(lineFormat.c_str(),
|
||||||
token.line,
|
token.line + 1,
|
||||||
line.substr(0, token.column - 1).c_str(),
|
line.substr(0, token.column).c_str(),
|
||||||
line.substr(token.column - 1).c_str());
|
line.substr(token.column).c_str());
|
||||||
|
|
||||||
// Arrow pointer
|
// Arrow pointer
|
||||||
std::string arrowFormat = " %s | "
|
std::string arrowFormat = " %s | "
|
||||||
@@ -104,7 +102,7 @@ void Job::printErrorLine(Token token, const char* message)
|
|||||||
"\n";
|
"\n";
|
||||||
printf(arrowFormat.c_str(),
|
printf(arrowFormat.c_str(),
|
||||||
std::string(m_lineNumbersWidth, ' ').c_str(),
|
std::string(m_lineNumbersWidth, ' ').c_str(),
|
||||||
std::string(token.column - 1, ' ').c_str(),
|
std::string(token.column, ' ').c_str(),
|
||||||
std::string(line.length() - token.column, '~').c_str());
|
std::string(line.length() - token.column, '~').c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,11 +103,11 @@ void Lexer::analyze()
|
|||||||
if (peekNext() == '\n') { // CRLF \r\n
|
if (peekNext() == '\n') { // CRLF \r\n
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_column = 0;
|
m_column = -1;
|
||||||
m_line++;
|
m_line++;
|
||||||
break;
|
break;
|
||||||
case '\n':
|
case '\n':
|
||||||
m_column = 0;
|
m_column = -1;
|
||||||
m_line++;
|
m_line++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ private:
|
|||||||
Job* m_job { nullptr };
|
Job* m_job { nullptr };
|
||||||
|
|
||||||
size_t m_index { 0 };
|
size_t m_index { 0 };
|
||||||
size_t m_column { 1 };
|
size_t m_column { 0 };
|
||||||
size_t m_line { 1 };
|
size_t m_line { 0 };
|
||||||
|
|
||||||
std::vector<Token>* m_tokens { nullptr };
|
std::vector<Token>* m_tokens { nullptr };
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user