![]() |
ArkScript
A small, lisp-inspired, functional scripting language
|
Source printer for diagnostics. More...
#include <PrettyPrinting.hpp>
Public Member Functions | |
Printer (const std::string &filename, std::size_t target_line, std::optional< std::size_t > end_target_line, bool colorize) | |
Create a new Printer object. | |
std::string | sliceCode (internal::FilePos start, const std::optional< internal::FilePos > &end) const |
Slice the source code to get code between two cursors. | |
void | extendWindow (std::size_t line_to_include) |
Extend the window of lines to show, to include a given line. Useful to display the origin of an error. | |
void | printLine (std::ostream &os) |
Print the current line and advance by one. | |
bool | isTargetLine () const |
Check if we printed the target line. | |
bool | hasContent () const |
Check if there are lines to print. | |
bool | coversLine (std::size_t line_number) const |
const Window & | window () const |
std::size_t | current () const |
const std::string & | currentLine () const |
Static Public Attributes | |
static const std::string | GhostLinePrefix = " |" |
Private Attributes | |
bool | m_should_colorize |
std::vector< std::string > | m_source |
Window | m_window |
std::size_t | m_current_line |
LineColorContextCounts | m_color_ctx |
Source printer for diagnostics.
Definition at line 61 of file PrettyPrinting.hpp.
Ark::Diagnostics::Printer::Printer | ( | const std::string & | filename, |
std::size_t | target_line, | ||
std::optional< std::size_t > | end_target_line, | ||
bool | colorize ) |
Create a new Printer object.
filename | path to the file that has an error |
target_line | line of the error (0-indexed) |
end_target_line | optional end line for the error (0-indexed) |
colorize | if we should colorize the output or not |
Definition at line 78 of file PrettyPrinting.cpp.
References ARK_NO_NAME_FILE, m_current_line, m_source, m_window, Ark::Utils::readFile(), Ark::Utils::splitString(), and Ark::Diagnostics::Window::start.
|
nodiscard |
Definition at line 176 of file PrettyPrinting.cpp.
References Ark::Diagnostics::Window::end, m_window, and Ark::Diagnostics::Window::start.
Referenced by Ark::Diagnostics::makeContext().
|
inlinenodiscard |
Definition at line 122 of file PrettyPrinting.hpp.
Referenced by Ark::Diagnostics::makeContext().
|
inlinenodiscard |
Definition at line 127 of file PrettyPrinting.hpp.
Referenced by Ark::Diagnostics::makeContext().
void Ark::Diagnostics::Printer::extendWindow | ( | std::size_t | line_to_include | ) |
Extend the window of lines to show, to include a given line. Useful to display the origin of an error.
line_to_include | line to include (0-indexed) |
Definition at line 121 of file PrettyPrinting.cpp.
References m_current_line, m_window, Ark::Diagnostics::Window::resume_at, Ark::Diagnostics::Window::skip_start_at, and Ark::Diagnostics::Window::start.
Referenced by Ark::Diagnostics::makeContext().
|
nodiscard |
Check if there are lines to print.
Definition at line 171 of file PrettyPrinting.cpp.
References Ark::Diagnostics::Window::end, m_current_line, m_source, m_window, and Ark::Diagnostics::Window::target.
Referenced by Ark::Diagnostics::makeContext(), and printLine().
|
nodiscard |
Check if we printed the target line.
Definition at line 166 of file PrettyPrinting.cpp.
References m_current_line, m_window, Ark::Diagnostics::Window::target, and Ark::Diagnostics::Window::target_end.
Referenced by Ark::Diagnostics::makeContext().
void Ark::Diagnostics::Printer::printLine | ( | std::ostream & | os | ) |
Print the current line and advance by one.
os | output stream |
Definition at line 135 of file PrettyPrinting.cpp.
References Ark::Diagnostics::colorizeLine(), hasContent(), Ark::Diagnostics::Window::hasSkip(), m_color_ctx, m_current_line, m_should_colorize, m_source, m_window, Ark::Diagnostics::Window::resume_at, and Ark::Diagnostics::Window::skip_start_at.
Referenced by Ark::Diagnostics::makeContext().
|
nodiscard |
Slice the source code to get code between two cursors.
start | |
end |
Definition at line 90 of file PrettyPrinting.cpp.
References Ark::internal::FilePos::column, Ark::internal::FilePos::line, Ark::Utils::ltrim(), m_source, and Ark::Utils::rtrim().
|
inlinenodiscard |
Definition at line 116 of file PrettyPrinting.hpp.
|
inlinestatic |
Definition at line 132 of file PrettyPrinting.hpp.
Referenced by Ark::Diagnostics::hintWithContext(), and Ark::Diagnostics::makeContext().
|
private |
Definition at line 139 of file PrettyPrinting.hpp.
Referenced by printLine().
|
private |
Definition at line 138 of file PrettyPrinting.hpp.
Referenced by extendWindow(), hasContent(), isTargetLine(), Printer(), and printLine().
|
private |
Definition at line 135 of file PrettyPrinting.hpp.
Referenced by printLine().
|
private |
Definition at line 136 of file PrettyPrinting.hpp.
Referenced by hasContent(), Printer(), printLine(), and sliceCode().
|
private |
Definition at line 137 of file PrettyPrinting.hpp.
Referenced by coversLine(), extendWindow(), hasContent(), isTargetLine(), Printer(), and printLine().