| 1 |
use ariadne::{sources, ColorGenerator, Fmt, Label, Report, ReportKind}; |
| 2 |
|
| 3 |
fn main() { |
| 4 |
let mut colors = ColorGenerator::new(); |
| 5 |
|
| 6 |
// Generate some colours for each of our elements |
| 7 |
let a = colors.next(); |
| 8 |
let b = colors.next(); |
| 9 |
let c = colors.next(); |
| 10 |
|
| 11 |
Report::build(ReportKind::Error, ("b.tao", 10..14)) |
| 12 |
.with_code(3) |
| 13 |
.with_message("Cannot add types Nat and Str".to_string()) |
| 14 |
.with_label( |
| 15 |
Label::new(("b.tao", 10..14)) |
| 16 |
.with_message(format!("This is of type {}", "Nat".fg(a))) |
| 17 |
.with_color(a), |
| 18 |
) |
| 19 |
.with_label( |
| 20 |
Label::new(("b.tao", 17..20)) |
| 21 |
.with_message(format!("This is of type {}", "Str".fg(b))) |
| 22 |
.with_color(b), |
| 23 |
) |
| 24 |
.with_label( |
| 25 |
Label::new(("b.tao", 15..16)) |
| 26 |
.with_message(format!( |
| 27 |
" {} and {} undergo addition here", |
| 28 |
"Nat".fg(a), |
| 29 |
"Str".fg(b) |
| 30 |
)) |
| 31 |
.with_color(c) |
| 32 |
.with_order(10), |
| 33 |
) |
| 34 |
.with_label( |
| 35 |
Label::new(("a.tao", 4..8)) |
| 36 |
.with_message(format!("Original definition of {} is here", "five".fg(a))) |
| 37 |
.with_color(a), |
| 38 |
) |
| 39 |
.with_note(format!( |
| 40 |
"{} is a number and can only be added to other numbers", |
| 41 |
"Nat".fg(a) |
| 42 |
)) |
| 43 |
.with_note("Multiple notes are possible".to_string()) |
| 44 |
.with_note("Multiline notes\ncan be also used when the note is humongous.") |
| 45 |
.finish() |
| 46 |
.print(sources(vec![ |
| 47 |
("a.tao", include_str!("a.tao")), |
| 48 |
("b.tao", include_str!("b.tao")), |
| 49 |
])) |
| 50 |
.unwrap(); |
| 51 |
} |