Debian Codegraph @

debian/rust-vendor/ariadne/examples/multiline.rs

raw
1 use ariadne::{Color, ColorGenerator, Fmt, Label, Report, ReportKind, Source};
2
3 fn main() {
4 let mut colors = ColorGenerator::new();
5
6 // Generate & choose some colours for each of our elements
7 let a = colors.next();
8 let b = colors.next();
9 let out = Color::Fixed(81);
10 let out2 = colors.next();
11
12 Report::build(ReportKind::Error, ("sample.tao", 32..33))
13 .with_code(3)
14 .with_message("Incompatible types".to_string())
15 .with_label(
16 Label::new(("sample.tao", 32..33))
17 .with_message(format!("This is of type {}", "Nat".fg(a)))
18 .with_color(a),
19 )
20 .with_label(
21 Label::new(("sample.tao", 42..45))
22 .with_message(format!("This is of type {}", "Str".fg(b)))
23 .with_color(b),
24 )
25 .with_label(
26 Label::new(("sample.tao", 11..48))
27 .with_message(format!(
28 "The values are outputs of this {} expression",
29 "match".fg(out),
30 ))
31 .with_color(out),
32 )
33 .with_label(
34 Label::new(("sample.tao", 0..48))
35 .with_message(format!("The {} has a problem", "definition".fg(out2),))
36 .with_color(out2),
37 )
38 .with_label(
39 Label::new(("sample.tao", 50..76))
40 .with_message(format!("Usage of {} here", "definition".fg(out2),))
41 .with_color(out2),
42 )
43 .with_note(format!(
44 "Outputs of {} expressions must coerce to the same type",
45 "match".fg(out)
46 ))
47 .finish()
48 .print(("sample.tao", Source::from(include_str!("sample.tao"))))
49 .unwrap();
50 }