From 2a915471f70356093bcaec8fc756f64d35becddb Mon Sep 17 00:00:00 2001 From: Jean Mertz Date: Mon, 11 Jan 2021 14:21:02 +0100 Subject: [PATCH 01/21] feat(remap): diagnostic error messages Signed-off-by: Jean Mertz --- Cargo.lock | 12 +++ lib/remap-lang/Cargo.toml | 2 + lib/remap-lang/src/diagnostic.rs | 150 ++++++++++++++++++++++++++ lib/remap-lang/src/error.rs | 179 +++++++++++++++++++++++-------- lib/remap-lang/src/lib.rs | 4 +- lib/remap-lang/src/parser.rs | 17 +-- lib/remap-lang/src/program.rs | 82 +++++--------- lib/remap-lang/src/runtime.rs | 12 ++- lib/remap-tests/src/main.rs | 6 +- 9 files changed, 339 insertions(+), 125 deletions(-) create mode 100644 lib/remap-lang/src/diagnostic.rs diff --git a/Cargo.lock b/Cargo.lock index 4583636d22e68..794736a9015ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -943,6 +943,16 @@ dependencies = [ "tracing 0.1.22", ] +[[package]] +name = "codespan-reporting" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6ce42b8998a383572e0a802d859b1f00c79b7b7474e62fff88ee5c2845d9c13" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "colored" version = "2.0.0" @@ -5353,6 +5363,7 @@ dependencies = [ "bitflags", "bytes 0.5.6", "chrono", + "codespan-reporting", "criterion", "dyn-clone", "paste", @@ -5360,6 +5371,7 @@ dependencies = [ "pest_derive", "regex", "serde", + "termcolor", "thiserror", ] diff --git a/lib/remap-lang/Cargo.toml b/lib/remap-lang/Cargo.toml index 296fa5200a057..b77db4bb5c6cb 100644 --- a/lib/remap-lang/Cargo.toml +++ b/lib/remap-lang/Cargo.toml @@ -10,6 +10,7 @@ license = "MPL-2.0" bitflags = "1" bytes = "0.5.6" chrono = "0.4" +codespan-reporting = "0.11" dyn-clone = "1" paste = "1" pest = "2" @@ -17,6 +18,7 @@ pest_derive = "2" regex = "1" serde = "1" thiserror = "1" +termcolor = "1" [dev-dependencies] criterion = "0.3" diff --git a/lib/remap-lang/src/diagnostic.rs b/lib/remap-lang/src/diagnostic.rs new file mode 100644 index 0000000000000..e532fac374ecd --- /dev/null +++ b/lib/remap-lang/src/diagnostic.rs @@ -0,0 +1,150 @@ +use crate::value::Kind; +use codespan_reporting::diagnostic; +use std::fmt; +use std::ops::Range; + +#[derive(Debug, Clone, PartialEq)] +pub struct Diagnostic { + pub(crate) severity: Severity, + pub(crate) message: Message, + pub(crate) labels: Vec