diff options
Diffstat (limited to '')
-rw-r--r-- | dhall/src/error/builder.rs | 2 | ||||
-rw-r--r-- | dhall/src/semantics/tck/typecheck.rs | 7 | ||||
-rw-r--r-- | dhall/src/syntax/ast/expr.rs | 19 | ||||
-rw-r--r-- | dhall/src/syntax/ast/mod.rs | 2 | ||||
-rw-r--r-- | dhall/src/syntax/ast/span.rs | 31 | ||||
-rw-r--r-- | serde_dhall/src/serde.rs | 10 |
6 files changed, 18 insertions, 53 deletions
diff --git a/dhall/src/error/builder.rs b/dhall/src/error/builder.rs index 39f8dfb..b4c5073 100644 --- a/dhall/src/error/builder.rs +++ b/dhall/src/error/builder.rs @@ -7,7 +7,7 @@ use annotate_snippets::{ use crate::syntax::{ParsedSpan, Span}; #[derive(Debug, Clone, Default)] -pub struct ErrorBuilder { +pub(crate) struct ErrorBuilder { title: FreeAnnotation, annotations: Vec<SpannedAnnotation>, footer: Vec<FreeAnnotation>, diff --git a/dhall/src/semantics/tck/typecheck.rs b/dhall/src/semantics/tck/typecheck.rs index 972326b..319bb9d 100644 --- a/dhall/src/semantics/tck/typecheck.rs +++ b/dhall/src/semantics/tck/typecheck.rs @@ -53,11 +53,14 @@ fn function_check(a: Const, b: Const) -> Const { } } -pub fn mkerr<T, S: ToString>(msg: S) -> Result<T, TypeError> { +pub(crate) fn mkerr<T, S: ToString>(msg: S) -> Result<T, TypeError> { Err(TypeError::new(TypeMessage::Custom(msg.to_string()))) } -pub fn mk_span_err<T, S: ToString>(span: Span, msg: S) -> Result<T, TypeError> { +pub(crate) fn mk_span_err<T, S: ToString>( + span: Span, + msg: S, +) -> Result<T, TypeError> { mkerr( ErrorBuilder::new(msg.to_string()) .span_err(span, msg.to_string()) diff --git a/dhall/src/syntax/ast/expr.rs b/dhall/src/syntax/ast/expr.rs index a479b53..089c178 100644 --- a/dhall/src/syntax/ast/expr.rs +++ b/dhall/src/syntax/ast/expr.rs @@ -237,35 +237,22 @@ impl<SE> ExprKind<SE> { } impl Expr { - pub fn as_ref(&self) -> &UnspannedExpr { + pub(crate) fn as_ref(&self) -> &UnspannedExpr { &self.kind } pub fn kind(&self) -> &UnspannedExpr { &self.kind } - pub fn span(&self) -> Span { + pub(crate) fn span(&self) -> Span { self.span.clone() } - pub fn new(kind: UnspannedExpr, span: Span) -> Self { + pub(crate) fn new(kind: UnspannedExpr, span: Span) -> Self { Expr { kind: Box::new(kind), span, } } - - pub fn rewrap(&self, kind: UnspannedExpr) -> Expr { - Expr { - kind: Box::new(kind), - span: self.span.clone(), - } - } - pub fn with_span(self, span: Span) -> Self { - Expr { - kind: self.kind, - span, - } - } } pub fn trivial_result<T>(x: Result<T, !>) -> T { diff --git a/dhall/src/syntax/ast/mod.rs b/dhall/src/syntax/ast/mod.rs index 1950154..5e20c5d 100644 --- a/dhall/src/syntax/ast/mod.rs +++ b/dhall/src/syntax/ast/mod.rs @@ -5,7 +5,7 @@ pub use import::*; mod label; pub use label::*; mod span; -pub use span::*; +pub(crate) use span::*; mod text; pub use text::*; pub mod map; diff --git a/dhall/src/syntax/ast/span.rs b/dhall/src/syntax/ast/span.rs index fba6a2d..e75ea53 100644 --- a/dhall/src/syntax/ast/span.rs +++ b/dhall/src/syntax/ast/span.rs @@ -2,7 +2,7 @@ use std::rc::Rc; /// A location in the source text #[derive(Debug, Clone)] -pub struct ParsedSpan { +pub(crate) struct ParsedSpan { input: Rc<str>, /// # Safety /// @@ -15,7 +15,7 @@ pub struct ParsedSpan { } #[derive(Debug, Clone)] -pub enum Span { +pub(crate) enum Span { /// A location in the source text Parsed(ParsedSpan), /// For expressions obtained from decoding binary @@ -50,7 +50,7 @@ impl Span { /// Takes the union of the two spans, i.e. the range of input covered by the two spans plus any /// input between them. Assumes that the spans come from the same input. Fails if one of the /// spans does not point to an input location. - pub fn union(&self, other: &Span) -> Self { + pub(crate) fn union(&self, other: &Span) -> Self { use std::cmp::{max, min}; use Span::*; match (self, other) { @@ -67,31 +67,6 @@ impl Span { ), } } - - /// Merges two spans assumed to point to a similar thing. If only one of them points to an - /// input location, use that one. - pub fn merge(&self, other: &Span) -> Self { - use Span::*; - match (self, other) { - (Parsed(x), _) | (_, Parsed(x)) => Parsed(x.clone()), - (Artificial, _) | (_, Artificial) => Artificial, - (Decoded, Decoded) => Decoded, - } - } - - 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) - } } /// Convert a byte idx into a string into a char idx for consumption by annotate_snippets. diff --git a/serde_dhall/src/serde.rs b/serde_dhall/src/serde.rs index 160392d..4fd7815 100644 --- a/serde_dhall/src/serde.rs +++ b/serde_dhall/src/serde.rs @@ -48,7 +48,7 @@ impl<'de: 'a, 'a> serde::Deserializer<'de> for Deserializer<'a> { ))) }; - match expr.as_ref() { + match expr.kind() { Lit(Bool(x)) => visitor.visit_bool(*x), Lit(Natural(x)) => { if let Ok(x64) = (*x).try_into() { @@ -81,11 +81,11 @@ impl<'de: 'a, 'a> serde::Deserializer<'de> for Deserializer<'a> { xs.iter().map(|x| Deserializer(Cow::Borrowed(x))), )), SomeLit(x) => visitor.visit_some(Deserializer(Cow::Borrowed(x))), - App(f, x) => match f.as_ref() { + App(f, x) => match f.kind() { Builtin(dhall::syntax::Builtin::OptionalNone) => { visitor.visit_none() } - Field(y, name) => match y.as_ref() { + Field(y, name) => match y.kind() { UnionType(..) => { let name: String = name.into(); visitor.visit_enum(MapAccessDeserializer::new( @@ -103,7 +103,7 @@ impl<'de: 'a, 'a> serde::Deserializer<'de> for Deserializer<'a> { .visit_map(MapDeserializer::new(m.iter().map(|(k, v)| { (k.as_ref(), Deserializer(Cow::Borrowed(v))) }))), - Field(y, name) => match y.as_ref() { + Field(y, name) => match y.kind() { UnionType(..) => { let name: String = name.into(); visitor.visit_enum(MapAccessDeserializer::new( @@ -127,7 +127,7 @@ impl<'de: 'a, 'a> serde::Deserializer<'de> for Deserializer<'a> { use ExprKind::*; let expr = self.0.as_ref(); - match expr.as_ref() { + match expr.kind() { // Blindly takes keys in sorted order. RecordLit(m) => visitor.visit_seq(SeqDeserializer::new( m.iter().map(|(_, v)| Deserializer(Cow::Borrowed(v))), |