• Stars
    star
    1,309
  • Rank 35,952 (Top 0.8 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fancy diagnostics & error reporting crate

Ariadne

crates.io crates.io License actions-badge

A fancy compiler diagnostics crate.

Example

Ariadne supports arbitrary multi-line spans
fn main() {
    use ariadne::{Color, ColorGenerator, Fmt, Label, Report, ReportKind, Source};

    let mut colors = ColorGenerator::new();

    // Generate & choose some colours for each of our elements
    let a = colors.next();
    let b = colors.next();
    let out = Color::Fixed(81);

    Report::build(ReportKind::Error, "sample.tao", 12)
        .with_code(3)
        .with_message(format!("Incompatible types"))
        .with_label(
            Label::new(("sample.tao", 32..33))
                .with_message(format!("This is of type {}", "Nat".fg(a)))
                .with_color(a),
        )
        .with_label(
            Label::new(("sample.tao", 42..45))
                .with_message(format!("This is of type {}", "Str".fg(b)))
                .with_color(b),
        )
        .with_label(
            Label::new(("sample.tao", 11..48))
                .with_message(format!(
                    "The values are outputs of this {} expression",
                    "match".fg(out),
                ))
                .with_color(out),
        )
        .with_note(format!(
            "Outputs of {} expressions must coerce to the same type",
            "match".fg(out)
        ))
        .finish()
        .print(("sample.tao", Source::from(include_str!("sample.tao"))))
        .unwrap();
}

See examples/ for more examples.

Usage

For each error you wish to report:

  • Call Report::build() to create a ReportBuilder.
  • Assign whatever details are appropriate to the error using the various methods, and then call the finish method to get a Report.
  • For each Report, call print or eprint to write the report directly to stdout or stderr. Alternately, you can use write to send the report to any other Write destination (such as a file).

About

ariadne is a sister project of chumsky. Neither are dependent on one-another, but I'm working on both simultaneously and like to think that their features complement each other. If you're thinking of using ariadne to process your compiler's output, why not try using chumsky to process its input?

Features

  • Inline and multi-line labels capable of handling arbitrary configurations of spans
  • Multi-file errors
  • Generic across custom spans and file caches
  • A choice of character sets to ensure compatibility
  • Coloured labels & highlighting with 8-bit and 24-bit color support (thanks to yansi)
  • Label priority and ordering
  • Compact mode for smaller diagnostics
  • Correct handling of variable-width characters such as tabs
  • A ColorGenerator type that generates distinct colours for visual elements.
  • A plethora of other options (tab width, label attach points, underlines, etc.)
  • Built-in ordering/overlap heuristics that come up with the best way to avoid overlapping & label crossover

Cargo Features

  • "concolor" enables integration with the concolor crate for global color output control across your application
  • "auto-color" enables concolor's "auto" feature for automatic color control

concolor's features should be defined by the top-level binary crate, but without any features enabled concolor does nothing. If ariadne is your only dependency using concolor then "auto-color" provides a convenience to enable concolor's automatic color support detection, i.e. this:

[dependencies]
ariadne = { version = "...", features = ["auto-color"] }

is equivalent to this:

[dependencies]
ariadne = { version = "...", features = ["concolor"] }
concolor = { version = "...", features = ["auto"] }

Planned Features

  • Improved layout planning & space usage
  • Non-ANSI terminal support
  • More accessibility options (screenreader-friendly mode, textured highlighting as an alternative to color, etc.)
  • More color options
  • Better support for layout restrictions (maximum terminal width, for example)

Stability

The API (should) follow semver. However, this does not apply to the layout of final error messages. Minor tweaks to the internal layout heuristics can often result in the exact format of error messages changing with labels moving slightly. If you experience a change in layout that you believe to be a regression (either the change is incorrect, or makes your diagnostics harder to read) then please open an issue.

Credit

Thanks to:

  • @brendanzab for their beautiful codespan crate that inspired me to try pushing the envelope of error diagnostics.

  • @estebank for showing innumerable people just how good compiler diagnostics can be through their work on Rust.

More Repositories

1

chumsky

Write expressive, high-performance parsers with ease.
Rust
3,334
star
2

flume

A safe and fast multi-producer, multi-consumer channel.
Rust
1,820
star
3

tao

A statically-typed functional language with generics, typeclasses, sum types, pattern-matching, first-class functions, currying, algebraic effects, associated types, good diagnostics, etc.
Rust
923
star
4

pollster

A minimal async executor that lets you block on a future
Rust
288
star
5

broom

An ergonomic tracing garbage collector that supports mark 'n sweep garbage collection
Rust
243
star
6

euc

A software rendering crate that lets you write shaders with Rust
Rust
241
star
7

forge

A lightweight, elegant scripting language with built-in Rust-FFI.
Rust
161
star
8

atto

An insanely simple self-hosted functional programming language
Rust
141
star
9

parze

A clean, efficient parser combinator
Rust
123
star
10

teloren

A command-line frontend for Veloren
Rust
90
star
11

funkicrab

Optimising Brainfuck compiler: Run your beloved Brainfuck code, but faster.
Rust
64
star
12

openmw-volumetric-clouds

A volumetric clouds mod for OpenMW
64
star
13

openmw-shaders

Photorealistic shaders for Morrowind
GLSL
59
star
14

vulcan

A minimalistic text editor designed for both ordinary use and software development
Vala
45
star
15

lagoon

A thread pool crate with an array of features
Rust
36
star
16

mutation

Unleash the power of nightly Rust to write code that's generic over mutation!
Rust
23
star
17

coord-rs

[deprecated] A simple, ergonomic vector mathematics crate for Rust
Rust
22
star
18

errant

A (mostly) drop-in replacement for Rust's Result that provides backtrace support.
Rust
22
star
19

leon

A lightweight scripting language for Rust
Rust
19
star
20

zte

Zesterer's Text Editor
Rust
18
star
21

tupai

A modular POSIX-like operating system created for educational purposes
C++
16
star
22

gui

An experimental stateful, structured, declarative GUI crate
Rust
12
star
23

the-bitwise-challenge

Challenge: Can you develop a game with only 8 bytes of state?
9
star
24

vast-outdated

As The Name Suggests: A Pretty Large Space Sim
C++
8
star
25

vm-perf

Performance comparisons between various virtual interpreter implementation strategies
Rust
8
star
26

gba-test

Software rasterisation on the GBA in Rust. Some experiments from a while ago.
Rust
7
star
27

thoth

A modular, x86_64 micro-kernel operating system
C
6
star
28

alonzo

A pure Rust functional compiler backend
Rust
6
star
29

que

An experimental lock-free queue
Rust
6
star
30

cargo-veloren

Name-squatting, for the moment
Rust
5
star
31

fula

A functional programming language with Hindley-Milner type inference
Rust
5
star
32

babble

A (horrendously hackish) clean room reimplementation of the Library of Babel, originally at https://libraryofbabel.info (seriously, check it out)
Python
5
star
33

synco

An experimental ECS crate that makes use of GATs
Rust
5
star
34

fuckvm

A highly experimental Brainfuck-targetting LLVM-like compiler backend
Rust
4
star
35

smash

Yet another blazingly fast hashmap written in Rust
Rust
4
star
36

emul8

Yet another CHIP-8 emulator written in Rust
Rust
4
star
37

bitwise-examples

Example games that persist just 8 bytes of state between frames
Rust
4
star
38

browser

Vala
4
star
39

nilts-old

A game about many things. I don't know what, since most content is randomly generated.
C
3
star
40

oms

[WIP] Orbital mechanics simulation tool/library
Rust
3
star
41

hire-me

Hire me! Here's why...
3
star
42

turk

A generic minmax algorithm that may be used as an AI player for 2-player games
Rust
3
star
43

libvolume

A voxel engine library used primarily in my other projects
C++
3
star
44

wavefront

A Wavefront OBJ parser and utility crate
Rust
3
star
45

voxeltest

A test voxel engine program
C++
3
star
46

emul8or

A CHIP-8 emulator written using Vala and SDL
Vala
3
star
47

sdf-test

An experiment in Signed Distance Field (SDF) raytracing and raymarching
C++
3
star
48

ir

An experimental language intermediate representation
Rust
2
star
49

yurt

A highly experiment portable runtime
Rust
2
star
50

parze-new

Rust
2
star
51

nilts

Work in progress which will hopefully one day be good
C++
2
star
52

picos

Raspberry Pi Card Operating System
C
2
star
53

async-priority-queue

An async-aware priority queue
Rust
2
star
54

spurv

A free, open-source CPU and instruction set specification with a minimalist design
2
star
55

jsbarretto

A personal website
HTML
2
star
56

opplyse

A clean, efficient GTK3 text editor for programmers. The big brother of Vulcan.
Vala
2
star
57

nilts-oldish

The procedurally generated game
C++
2
star
58

super-block

A platforming game written for the CHIP-8
1
star
59

forge-demo

Run Forge code online!
JavaScript
1
star
60

cragmoor

A text-based ASCII RPG procedurally generated game inspired by Dwarf Fortress
C++
1
star
61

snakes-on-a-continuous-plane

A 2D Continuous Snakes Game Created For Ludum Dare 34
CMake
1
star
62

timber

I got bored one afternoon and started writing a desktop panel
Vala
1
star
63

vast-old

Vast is a space sim written in C++ using OpenGL
C++
1
star
64

pokerom

A GameBoy Color (GBC) emulator written in C++ with SDL 2
CMake
1
star