Crates.io | codespan_preprocessed |
lib.rs | codespan_preprocessed |
version | |
source | src |
created_at | 2021-10-14 14:10:48.969255 |
updated_at | 2024-11-07 13:53:08.678083 |
description | Beautiful diagnostic reporting for M4 (or cpp) preprocessed text files |
homepage | |
repository | https://github.com/XopheD/codespan_preprocessed |
max_upload_size | |
id | 464928 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This is an extension for the very useful crate codespan_reporting
to deal with preprocessed file through the well-knownm4
or cpp
.
Using such a preprocessor allows, among a lost of things, the inclusion of many files which are identified in the bytes sequence with preprecessor directive as:
#line 42 "/my/preprocessed/file"
This directive breaks the location of the source and so should be correctly processed to make correct location for error reporting.
This is the purpose of this crate: taking a preprocessor output and managing the different underlying locations inside it.
use codespan_reporting::diagnostic::Diagnostic;
use codespan_reporting::term;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use codespan_preprocessed::PreprocessedFile;
fn main()
{
let file = PreprocessedFile::new(
unindent::unindent(
r#"
#line 1 "top_file"
a first statement;
another one
#line 1 "included_file"
continue...
#line 5
another line
the last one
"#,
),
);
let diagnostic = Diagnostic::note()
.with_message("this is just an example")
.with_labels(vec![
file.primary_label(113..117).with_message("do you see that ?"),
file.secondary_label(21..26).with_message("is it related to this ?")
]);
// We now set up the writer and configuration, and then finally render the
// diagnostic to standard error.
// (see `codespan_reporting` documention for more details)
let writer = StandardStream::stderr(ColorChoice::Always);
let config = codespan_reporting::term::Config::default();
term::emit(&mut writer.lock(), &config, &file, &diagnostic);
}
The previous code will produce:
note: this is just an example
┌─ included_file:6:5
│
6 │ the last one
│ ^^^^ do you see that ?
│
┌─ top_file:1:3
│
1 │ a first statement;
│ ----- is it related to this ?