1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use ara_reporting::annotation::Annotation;
use ara_reporting::builder::CharSet;
use ara_reporting::builder::ColorChoice;
use ara_reporting::builder::ReportBuilder;
use ara_reporting::error::Error;
use ara_reporting::issue::Issue;
use ara_reporting::Report;
use ara_reporting::ReportFooter;
use ara_source::source::Source;
use ara_source::source::SourceKind;
use ara_source::SourceMap;

fn main() -> Result<(), Error> {
    let origin = "example.ara";
    let code = r#"
$b = match $a {
    1 => 2,
    2 => 3,
    default => "string",
};
"#;

    let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);

    let report = Report::new()
        .with_issue(
            Issue::error("E0417", "`match` arms have incompatible types")
                .with_source(origin, 6, 67)
                .with_annotation(
                    Annotation::secondary(origin, 26, 27)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 38, 39)
                        .with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::secondary(origin, 56, 64)
                        .with_message("expected `{int}`, found `{string}`"),
                )
                .with_note("for more information about this error, try `ara --explain E0417`"),
        )
        .with_footer(
            ReportFooter::new("this is a report footer message")
                .with_note("this is a note message"),
        );

    let builder = ReportBuilder::new(&map)
        .with_colors(ColorChoice::Always)
        .with_charset(CharSet::Unicode);

    builder.print(&report)
}