summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2020-03-13 16:16:56 +0000
committerNadrieril2020-03-31 21:44:01 +0100
commit6fdae6f8026fe9357de63c5557676f4def3eaf92 (patch)
tree2281e9894a18a183980d4b033e00e95d9a633a05 /dhall/src
parent60425d58151fef142b066d523dc4d5e832070b9c (diff)
Remove Normalized and friends from public API
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/lib.rs42
-rw-r--r--dhall/src/simple.rs7
-rw-r--r--dhall/src/tests.rs2
3 files changed, 20 insertions, 31 deletions
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index 60b7a0e..7300d88 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -26,31 +26,31 @@ use crate::semantics::{
use crate::syntax::binary;
use crate::syntax::{Builtin, Expr};
-pub type ParsedExpr = Expr;
-pub type DecodedExpr = Expr;
-pub type ResolvedExpr = Expr;
-pub type NormalizedExpr = Expr;
+pub(crate) type ParsedExpr = Expr;
+pub(crate) type DecodedExpr = Expr;
+pub(crate) type ResolvedExpr = Expr;
+pub(crate) type NormalizedExpr = Expr;
pub use crate::simple::{STyKind, SValKind, SimpleType, SimpleValue};
#[derive(Debug, Clone)]
-pub struct Parsed(ParsedExpr, ImportLocation);
+pub(crate) struct Parsed(ParsedExpr, ImportLocation);
/// An expression where all imports have been resolved
///
/// Invariant: there must be no `Import` nodes or `ImportAlt` operations left.
#[derive(Debug, Clone)]
-pub struct Resolved(Hir);
+pub(crate) struct Resolved(Hir);
/// A typed expression
#[derive(Debug, Clone)]
-pub struct Typed {
+pub(crate) struct Typed {
hir: Hir,
ty: Type,
}
/// A normalized expression.
#[derive(Debug, Clone)]
-pub struct Normalized(Nir);
+pub(crate) struct Normalized(Nir);
/// A Dhall value.
#[derive(Debug, Clone)]
@@ -81,6 +81,7 @@ impl Parsed {
pub fn parse_binary_file(f: &Path) -> Result<Parsed, Error> {
parse::parse_binary_file(f)
}
+ #[allow(dead_code)]
pub fn parse_binary(data: &[u8]) -> Result<Parsed, Error> {
parse::parse_binary(data)
}
@@ -88,13 +89,6 @@ impl Parsed {
pub fn resolve(self) -> Result<Resolved, Error> {
resolve::resolve(self)
}
- pub fn skip_resolve(self) -> Result<Resolved, Error> {
- Ok(Resolved(resolve::skip_resolve(&self.0)?))
- }
-
- pub fn encode(&self) -> Result<Vec<u8>, EncodeError> {
- binary::encode(&self.0)
- }
/// Converts a value back to the corresponding AST expression.
pub fn to_expr(&self) -> ParsedExpr {
@@ -156,14 +150,6 @@ impl Normalized {
pub fn to_expr(&self) -> NormalizedExpr {
self.0.to_expr(ToExprOptions::default())
}
- /// Converts a value into a SimpleValue.
- pub fn to_simple_value(&self) -> Result<SimpleValue, Expr> {
- self.0.to_simple_value().ok_or_else(|| self.to_expr())
- }
- /// Converts a value into a SimpleType.
- pub fn to_simple_type(&self) -> Result<SimpleType, Expr> {
- self.0.to_simple_type().ok_or_else(|| self.to_expr())
- }
/// Converts a value back to the corresponding Hir expression.
pub(crate) fn to_hir(&self) -> Hir {
self.0.to_hir_noenv()
@@ -186,25 +172,25 @@ impl Normalized {
Normalized(th)
}
- pub fn make_builtin_type(b: Builtin) -> Self {
+ pub(crate) fn make_builtin_type(b: Builtin) -> Self {
Normalized::from_nir(Nir::from_builtin(b))
}
- pub fn make_optional_type(t: Normalized) -> Self {
+ pub(crate) fn make_optional_type(t: Normalized) -> Self {
Normalized::from_nir(
Nir::from_builtin(Builtin::Optional).app(t.to_nir()),
)
}
- pub fn make_list_type(t: Normalized) -> Self {
+ pub(crate) fn make_list_type(t: Normalized) -> Self {
Normalized::from_nir(Nir::from_builtin(Builtin::List).app(t.to_nir()))
}
- pub fn make_record_type(
+ pub(crate) fn make_record_type(
kts: impl Iterator<Item = (String, Normalized)>,
) -> Self {
Normalized::from_kind(NirKind::RecordType(
kts.map(|(k, t)| (k.into(), t.into_nir())).collect(),
))
}
- pub fn make_union_type(
+ pub(crate) fn make_union_type(
kts: impl Iterator<Item = (String, Option<Normalized>)>,
) -> Self {
Normalized::from_kind(NirKind::UnionType(
diff --git a/dhall/src/simple.rs b/dhall/src/simple.rs
index 9d3846e..014053e 100644
--- a/dhall/src/simple.rs
+++ b/dhall/src/simple.rs
@@ -1,7 +1,7 @@
use std::collections::BTreeMap;
use crate::syntax::{Builtin, LitKind};
-use crate::Normalized;
+use crate::{Normalized, Value};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SimpleValue {
@@ -56,7 +56,10 @@ impl SimpleType {
pub fn kind(&self) -> &STyKind {
self.kind.as_ref()
}
- pub fn into_normalized(self) -> Normalized {
+ pub fn to_value(&self) -> Value {
+ self.clone().into_normalized().to_value()
+ }
+ fn into_normalized(self) -> Normalized {
match *self.kind {
STyKind::Bool => Normalized::make_builtin_type(Builtin::Bool),
STyKind::Natural => Normalized::make_builtin_type(Builtin::Natural),
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs
index a5a278c..659f6f7 100644
--- a/dhall/src/tests.rs
+++ b/dhall/src/tests.rs
@@ -302,7 +302,7 @@ fn run_test(test: Test) -> Result<()> {
expected.compare(expr)?;
}
ImportFailure(expr, expected) => {
- let err = expr.parse()?.resolve().unwrap_err();
+ let err = expr.resolve().unwrap_err();
expected.compare_ui(err)?;
}
TypeInferenceSuccess(expr, expected) => {