diff options
author | Nadrieril | 2019-11-11 12:43:09 +0000 |
---|---|---|
committer | Nadrieril | 2019-11-11 13:50:36 +0000 |
commit | 330f063e80a51f8f399864f9d01412e1bff34fe9 (patch) | |
tree | d008005efc57222c0b33f5069c6ce8576cc7bd43 /dhall_syntax | |
parent | 5d5a356b8eb36e277c312e5550d1cb0a2f82e9fa (diff) |
Display first pretty type error
Diffstat (limited to 'dhall_syntax')
-rw-r--r-- | dhall_syntax/src/core/span.rs | 14 |
1 files changed, 14 insertions, 0 deletions
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>) -> 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) + } } |