summaryrefslogtreecommitdiff
path: root/dhall_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'dhall_syntax/src')
-rw-r--r--dhall_syntax/src/core/span.rs14
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)
+ }
}