4 个版本 (2 个破坏性更新)
0.7.11 | 2023 年 11 月 27 日 |
---|---|
0.7.5 |
|
0.7.3 |
|
0.7.0 |
|
0.2.1 |
|
#4 在 #reporting
每月下载 135 次
32KB
728 行
codespan_preprocessed
这是一个针对非常有用的crate codespan_reporting
的扩展,用于通过众所周知的m4
或 cpp
处理预处理的文件。
使用此类预处理器可以使许多文件被包含,这些文件通过预处理指令在字节序列中标识为
#行42 "/my/preprocessed/file"
此指令破坏了源位置,因此应该正确处理以生成错误报告的正确位置。
这正是此crate的目的:接收预处理器输出并管理其内部的不同基本位置。
示例
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);
}
前面的代码将生成
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 ?
依赖关系
~0.5–7MB
~41K SLoC