Support printing multiline error context in interpreter
This commit is contained in:
parent
902d272deb
commit
11656fb296
1 changed files with 11 additions and 2 deletions
|
|
@ -45,10 +45,10 @@ std::size_t replace_tabs_with_spaces(std::string & str, std::size_t count)
|
|||
|
||||
void print_error_context(std::filesystem::path const & file, pslang::ast::location const & location)
|
||||
{
|
||||
std::size_t max_line_number_digits = std::floor(std::log10(location.end.line)) + 1;
|
||||
|
||||
if (location.begin.line == location.end.line)
|
||||
{
|
||||
std::size_t max_line_number_digits = std::floor(std::log10(location.begin.line)) + 1;
|
||||
|
||||
auto line = extract_nth_line(file, location.begin.line);
|
||||
auto extra = replace_tabs_with_spaces(line, 2);
|
||||
|
||||
|
|
@ -57,6 +57,15 @@ void print_error_context(std::filesystem::path const & file, pslang::ast::locati
|
|||
std::cerr << line << std::endl;
|
||||
std::cerr << std::string(std::max<std::size_t>(location.begin.column, 1) - 1 + max_line_number_digits + 7 + extra, ' ') << std::string(location.end.column - location.begin.column, '^') << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << std::endl;
|
||||
for (std::size_t line = location.begin.line; line <= location.end.line; ++line)
|
||||
{
|
||||
std::cerr << "line " << std::setw(max_line_number_digits) << std::right << line << ": ";
|
||||
std::cerr << extract_nth_line(file, line) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue