bithero_agency/LapystOrg/lib-error-reporting-cpp/pipeline/head This commit looks good
Details
|
||
---|---|---|
example | ||
src | ||
.gitignore | ||
Jenkinsfile | ||
LICENSE | ||
Nittofile | ||
readme.md | ||
sample.tao | ||
test._rs |
readme.md
error-reporting-cpp
A header-only error-reporting libary for c++.
License
The code in this repository is licensed under AGPL-3.0-or-later; for more details see the LICENSE
file in the repository.
Usage
using namespace ErrorReporting;
// create colors through an color generator (thanks to ariadne.rs)
auto colors = ColorGenerator();
auto a = colors.next();
// create an explicit color
auto out = Color::fixed(81);
auto r1 = std::make_unique<Report<StdStrSpan>>(ReportKind_Error);
(*r1)
// sets the error-code
.with_code("03")
// sets the primary error message
.with_message(Message("Incompatible types"))
// adds an label (source-annotation) to the report
.with_label(
Label{
// A span is a range inside a sourcefile
StdStrSpan(
"sample.tao", // the source's id
Position(2, 8, 25), // the starting position
Position(2, 9, 25) // the ending position
// Note: positions consist of 3 parts:
// - line number; one-based
// - column number; one-based
// - line-offset: the byteoffset to the begin of the line; zero-based
)
}
// Adds a message to the label with a colored in word "Nat"
.with_message(Message("This is of type ").add_part("Nat", a))
// Sets the arrow color of the label
.with_color(a)
)
.with_label(
Label{ StdStrSpan("sample.tao", Position(3, 8, 35), Position(3, 11, 35)) }
// Using the MessageBuilder, building messages can be written in a much nicer syntax
.with_message(MessageBuilder{} << "This is of type " << b << "Str")
.with_color(b)
);
// Creates a container for sources
auto files = StaticFiles<StdStrSpan::SourceId>{};
// adds a source from a std::istream via StreamSource
files.with_source("main.rs", new StreamSource(new std::ifstream("./test._rs")));
// Creates a renderer for terminals
auto renderer = TerminalRenderer<StdStrSpan::SourceId>(std::cerr, files);
// renders the report
renderer << r1;
For more, see the example directory.
TODOs
- Correctly implement support for rendering 1+ multiline labels
- Fix chain-calling interfaces so that the objects dont get destructed that often
Thanks
Thanks to ariadne.rs for a fantastic crate that inspired me to create this.