Debian Codegraph @

debian/rust-vendor/ariadne/README.md

raw
1 # Ariadne
2
3 [![crates.io](https://img.shields.io/crates/v/ariadne.svg)](https://crates.io/crates/ariadne)
4 [![crates.io](https://docs.rs/ariadne/badge.svg)](https://docs.rs/ariadne)
5 [![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](https://github.com/zesterer/ariadne)
6 ![actions-badge](https://github.com/zesterer/ariadne/workflows/Rust/badge.svg?branch=main)
7
8 A fancy compiler diagnostics crate.
9
10 ## Example
11
12 <a href = "https://github.com/zesterer/ariadne/blob/main/examples/multiline.rs">
13 <img src="https://raw.githubusercontent.com/zesterer/ariadne/main/misc/example.png" alt="Ariadne supports arbitrary multi-line spans"/>
14 </a>
15
16 ```rust,ignore
17 fn main() {
18 use ariadne::{Color, ColorGenerator, Fmt, Label, Report, ReportKind, Source};
19
20 let mut colors = ColorGenerator::new();
21
22 // Generate & choose some colours for each of our elements
23 let a = colors.next();
24 let b = colors.next();
25 let out = Color::Fixed(81);
26
27 Report::build(ReportKind::Error, ("sample.tao", 12..12))
28 .with_code(3)
29 .with_message(format!("Incompatible types"))
30 .with_label(
31 Label::new(("sample.tao", 32..33))
32 .with_message(format!("This is of type {}", "Nat".fg(a)))
33 .with_color(a),
34 )
35 .with_label(
36 Label::new(("sample.tao", 42..45))
37 .with_message(format!("This is of type {}", "Str".fg(b)))
38 .with_color(b),
39 )
40 .with_label(
41 Label::new(("sample.tao", 11..48))
42 .with_message(format!(
43 "The values are outputs of this {} expression",
44 "match".fg(out),
45 ))
46 .with_color(out),
47 )
48 .with_note(format!(
49 "Outputs of {} expressions must coerce to the same type",
50 "match".fg(out)
51 ))
52 .finish()
53 .print(("sample.tao", Source::from(include_str!("sample.tao"))))
54 .unwrap();
55 }
56 ```
57
58 See [`examples/`](https://github.com/zesterer/ariadne/tree/main/examples) for more examples.
59
60 ## Usage
61
62 For each error you wish to report:
63 * Call `Report::build()` to create a `ReportBuilder`.
64 * Assign whatever details are appropriate to the error using the various
65 methods, and then call the `finish` method to get a `Report`.
66 * For each `Report`, call `print` or `eprint` to write the report
67 directly to `stdout` or `stderr`. Alternately, you can use
68 `write` to send the report to any other `Write` destination (such as a file).
69
70 ## About
71
72 `ariadne` is a sister project of [`chumsky`](https://github.com/zesterer/chumsky/). Neither are dependent on
73 one-another, but I'm working on both simultaneously and like to think that their features complement each other. If
74 you're thinking of using `ariadne` to process your compiler's output, why not try using `chumsky` to process its input?
75
76 ## Features
77
78 - Inline and multi-line labels capable of handling arbitrary configurations of spans
79 - Multi-file errors
80 - Generic across custom spans and file caches
81 - A choice of character sets to ensure compatibility
82 - Coloured labels & highlighting with 8-bit and 24-bit color support (thanks to
83 [`yansi`](https://github.com/SergioBenitez/yansi))
84 - Label priority and ordering
85 - Compact mode for smaller diagnostics
86 - Correct handling of variable-width characters such as tabs
87 - A `ColorGenerator` type that generates distinct colours for visual elements.
88 - A plethora of other options (tab width, label attach points, underlines, etc.)
89 - Built-in ordering/overlap heuristics that come up with the best way to avoid overlapping & label crossover
90
91 ## Cargo Features
92
93 - `"concolor"` enables integration with the [`concolor`](https://crates.io/crates/concolor) crate for global color output
94 control across your application
95 - `"auto-color"` enables `concolor`'s `"auto"` feature for automatic color control
96
97 `concolor`'s features should be defined by the top-level binary crate, but without any features enabled `concolor` does
98 nothing. If `ariadne` is your only dependency using `concolor` then `"auto-color"` provides a convenience to enable
99 `concolor`'s automatic color support detection, i.e. this:
100 ```TOML
101 [dependencies]
102 ariadne = { version = "...", features = ["auto-color"] }
103 ```
104 is equivalent to this:
105 ```TOML
106 [dependencies]
107 ariadne = { version = "...", features = ["concolor"] }
108 concolor = { version = "...", features = ["auto"] }
109 ```
110
111 ## Planned Features
112
113 - Improved layout planning & space usage
114 - Non-ANSI terminal support
115 - More accessibility options (screenreader-friendly mode, textured highlighting as an alternative to color, etc.)
116 - More color options
117 - Better support for layout restrictions (maximum terminal width, for example)
118
119 ## Stability
120
121 The API (should) follow [semver](https://www.semver.org/). However, this does not apply to the layout of final error
122 messages. Minor tweaks to the internal layout heuristics can often result in the exact format of error messages changing
123 with labels moving slightly. If you experience a change in layout that you believe to be a regression (either the change
124 is incorrect, or makes your diagnostics harder to read) then please open an issue.
125
126 ## Credit
127
128 Thanks to:
129
130 - `@brendanzab` for their beautiful [`codespan`](https://github.com/brendanzab/codespan) crate that inspired me to try
131 pushing the envelope of error diagnostics.
132
133 - `@estebank` for showing innumerable people just how good compiler diagnostics can be through their work on Rust.