48 const std::optional<CodeErrorContext>& maybe_context,
51 assert(!(maybe_context && loc.
wholeLineIsError()) &&
"Can not create error context when a context is given AND the whole line has to be underlined");
60 const bool ctx_same_file = maybe_context && maybe_context->filename == loc.
filename;
61 const bool ctx_in_window = ctx_same_file && maybe_context && source_printer.
coversLine(maybe_context->at.start.line);
63 if (ctx_same_file && !ctx_in_window)
64 source_printer.
extendWindow(maybe_context->at.start.line);
65 else if (maybe_context && !ctx_same_file && !maybe_context->filename.empty())
68 std::string uniformised_filename;
69 std::ranges::replace_copy(maybe_context->filename, std::back_inserter(uniformised_filename),
'\\',
'/');
70 fmt::print(os,
"Error originated from file {}:{}\n", uniformised_filename, maybe_context->at.start.line + 1);
73 if (maybe_context->at.end)
74 maybe_end_line = maybe_context->at.end->line;
75 Printer printer(maybe_context->filename, maybe_context->at.start.line, maybe_end_line, colorize);
93 const std::size_t i = source_printer.
current();
94 const std::string& line = source_printer.
currentLine();
97 if (ctx_same_file && i == maybe_context->at.start.line && i < loc.
start.
line)
106 const std::size_t line_first_char = (line.find_first_not_of(
" \t\v") == std::string::npos) ? 0 : line.find_first_not_of(
" \t\v");
110 const std::size_t col_end = (i == loc.
end->line) ? loc.
end->column : line.size();
113 if (i == loc.
end->line && loc.
end->line != loc.
start.
line && col_start >= col_end)
119 if (!maybe_context || maybe_context->at.start.line != loc.
start.
line)
125 std::max(1_z, std::min(col_start, col_end)),
127 fmt::styled(
"^", colorize ? fmt::fg(fmt::color::red) : fmt::text_style()),
128 col_start < col_end ? col_end - col_start : 1);
130 else if (maybe_context && maybe_context->at.start.line == loc.
start.
line && i == loc.
start.
line)
132 const auto padding_size = std::max(1_z, maybe_context->at.start.column);
133 const std::string inner_padding =
137 : std::string(std::max(1_z, loc.
start.
column - padding_size - 1),
' ');
146 fmt::styled(
"│", colorize ? fmt::fg(fmt::color::red) : fmt::text_style()),
150 fmt::styled(
"└─ error", colorize ? fmt::fg(fmt::color::red) : fmt::text_style()));
157 fmt::styled(
"│", colorize ? fmt::fg(fmt::color::red) : fmt::text_style()));
167 maybe_context->is_macro_expansion ?
"└─ macro expansion started here" :
"└─ expression started here",
168 colorize ? fmt::fg(fmt::color::red) : fmt::text_style()));
177 const std::size_t col_start = line.find_first_not_of(
" \t\v") + 1;
187 fmt::styled(
"^", colorize ? fmt::fg(fmt::color::red) : fmt::text_style()),
188 line.size() - col_start);
const internal::FileSpan at
const std::string filename