From 330f063e80a51f8f399864f9d01412e1bff34fe9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 11 Nov 2019 12:43:09 +0000 Subject: Display first pretty type error --- dhall_syntax/src/core/span.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'dhall_syntax') diff --git a/dhall_syntax/src/core/span.rs b/dhall_syntax/src/core/span.rs index fa89c30..e2bf26d 100644 --- a/dhall_syntax/src/core/span.rs +++ b/dhall_syntax/src/core/span.rs @@ -53,4 +53,18 @@ impl Span { ), } } + + pub fn error(&self, message: impl Into) -> String { + use pest::error::{Error, ErrorVariant}; + use pest::Span; + let message: String = message.into(); + let span = match self { + self::Span::Parsed(span) => span, + _ => return format!("Unknown location: {}", message), + }; + let span = Span::new(&*span.input, span.start, span.end).unwrap(); + let err: ErrorVariant = ErrorVariant::CustomError { message }; + let err = Error::new_from_span(err, span); + format!("{}", err) + } } -- cgit v1.2.3