Skip to content

A Reporting library for for Ara Programming Language πŸ“ƒ

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

ara-lang/reporting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Ara Reporting

Actions Status Crates.io Docs

A Reporting library for Ara Programming Language πŸ“ƒ

Internally, Ara reporting uses the codespan-reporting library to build a report of the issues found in the code.

Note If you are planning on adding more features to Ara reporting, please consider adding them to codespan instead if possible.

Usage

Add ara_reporting to your Cargo.toml, and you're good to go!

[dependencies]
ara_reporting = "0.6.1"

Example

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::new(origin, 26, 27).with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::new(origin, 38, 39).with_message("this is found to be of type `{int}`"),
                )
                .with_annotation(
                    Annotation::new(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)
}

see examples directory for more examples.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Credits