summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dhall/src/dhall_type.rs60
-rw-r--r--dhall/src/lib.rs3
-rw-r--r--dhall/tests/dhall_type.rs32
-rw-r--r--dhall_generator/src/dhall_type.rs30
-rw-r--r--dhall_generator/src/lib.rs6
5 files changed, 66 insertions, 65 deletions
diff --git a/dhall/src/dhall_type.rs b/dhall/src/dhall_type.rs
index 8abef32..6b0e06e 100644
--- a/dhall/src/dhall_type.rs
+++ b/dhall/src/dhall_type.rs
@@ -2,76 +2,76 @@ use dhall_core::*;
use dhall_generator::*;
#[derive(Debug, Clone)]
-pub enum DhallConversionError {}
+pub enum ConversionError {}
-pub trait DhallType: Sized {
- fn dhall_type() -> DhallExpr;
+pub trait Type {
+ fn get_type() -> DhallExpr;
// fn as_dhall(&self) -> DhallExpr;
// fn from_dhall(e: DhallExpr) -> Result<Self, DhallConversionError>;
}
-impl DhallType for bool {
- fn dhall_type() -> DhallExpr {
+impl Type for bool {
+ fn get_type() -> DhallExpr {
dhall_expr!(Bool)
}
}
-impl DhallType for Natural {
- fn dhall_type() -> DhallExpr {
+impl Type for Natural {
+ fn get_type() -> DhallExpr {
dhall_expr!(Natural)
}
}
-impl DhallType for Integer {
- fn dhall_type() -> DhallExpr {
+impl Type for Integer {
+ fn get_type() -> DhallExpr {
dhall_expr!(Integer)
}
}
-impl DhallType for String {
- fn dhall_type() -> DhallExpr {
+impl Type for String {
+ fn get_type() -> DhallExpr {
dhall_expr!(Text)
}
}
-impl<A: DhallType, B: DhallType> DhallType for (A, B) {
- fn dhall_type() -> DhallExpr {
- let ta = A::dhall_type();
- let tb = B::dhall_type();
+impl<A: Type, B: Type> Type for (A, B) {
+ fn get_type() -> DhallExpr {
+ let ta = A::get_type();
+ let tb = B::get_type();
dhall_expr!({ _1: ta, _2: tb })
}
}
-impl<T: DhallType> DhallType for Option<T> {
- fn dhall_type() -> DhallExpr {
- let t = T::dhall_type();
+impl<T: Type> Type for Option<T> {
+ fn get_type() -> DhallExpr {
+ let t = T::get_type();
dhall_expr!(Optional t)
}
}
-impl<T: DhallType> DhallType for Vec<T> {
- fn dhall_type() -> DhallExpr {
- let t = T::dhall_type();
+impl<T: Type> Type for Vec<T> {
+ fn get_type() -> DhallExpr {
+ let t = T::get_type();
dhall_expr!(List t)
}
}
-impl<'a, T: DhallType> DhallType for &'a T {
- fn dhall_type() -> DhallExpr {
- T::dhall_type()
+impl<'a, T: Type> Type for &'a T {
+ fn get_type() -> DhallExpr {
+ T::get_type()
}
}
-impl<T> DhallType for std::marker::PhantomData<T> {
- fn dhall_type() -> DhallExpr {
+impl<T> Type for std::marker::PhantomData<T> {
+ fn get_type() -> DhallExpr {
dhall_expr!({})
}
}
-impl<T: DhallType, E: DhallType> DhallType for Result<T, E> {
- fn dhall_type() -> DhallExpr {
- let tt = T::dhall_type();
- let te = E::dhall_type();
+impl<T: Type, E: Type> Type for Result<T, E> {
+ fn get_type() -> DhallExpr {
+ let tt = T::get_type();
+ let te = E::get_type();
dhall_expr!(< Ok: tt | Err: te>)
}
}
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index c0c1d6f..0270103 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -13,7 +13,8 @@ pub mod binary;
mod dhall_type;
pub mod imports;
pub mod typecheck;
-pub use dhall_type::*;
+pub use crate::dhall_type::*;
+pub use dhall_generator::Type;
pub use crate::imports::*;
diff --git a/dhall/tests/dhall_type.rs b/dhall/tests/dhall_type.rs
index 633d7c6..faece20 100644
--- a/dhall/tests/dhall_type.rs
+++ b/dhall/tests/dhall_type.rs
@@ -1,56 +1,56 @@
#![feature(proc_macro_hygiene)]
-use dhall::*;
-use dhall_generator::*;
+use dhall::Type;
+use dhall_generator::dhall_expr;
#[test]
fn test_dhall_type() {
- assert_eq!(bool::dhall_type(), dhall_expr!(Bool));
- assert_eq!(String::dhall_type(), dhall_expr!(Text));
+ assert_eq!(bool::get_type(), dhall_expr!(Bool));
+ assert_eq!(String::get_type(), dhall_expr!(Text));
assert_eq!(
- <(bool, Option<String>)>::dhall_type(),
+ <(bool, Option<String>)>::get_type(),
dhall_expr!({ _1: Bool, _2: Optional Text })
);
- #[derive(DhallType)]
+ #[derive(dhall::Type)]
#[allow(dead_code)]
struct A {
field1: bool,
field2: Option<bool>,
}
assert_eq!(
- A::dhall_type(),
+ <A as dhall::Type>::get_type(),
dhall_expr!({ field1: Bool, field2: Optional Bool })
);
- #[derive(DhallType)]
+ #[derive(Type)]
#[allow(dead_code)]
struct B<'a, T: 'a> {
field1: &'a T,
field2: Option<T>,
}
- assert_eq!(<B<'static, bool>>::dhall_type(), A::dhall_type());
+ assert_eq!(<B<'static, bool>>::get_type(), A::get_type());
- #[derive(DhallType)]
+ #[derive(Type)]
#[allow(dead_code)]
struct C<T>(T, Option<String>);
assert_eq!(
- <C<bool>>::dhall_type(),
- <(bool, Option<String>)>::dhall_type()
+ <C<bool>>::get_type(),
+ <(bool, Option<String>)>::get_type()
);
- #[derive(DhallType)]
+ #[derive(Type)]
#[allow(dead_code)]
struct D();
assert_eq!(
- <C<D>>::dhall_type(),
+ <C<D>>::get_type(),
dhall_expr!({ _1: {}, _2: Optional Text })
);
- #[derive(DhallType)]
+ #[derive(Type)]
#[allow(dead_code)]
enum E<T> {
A(T),
B(String),
};
- assert_eq!(<E<bool>>::dhall_type(), dhall_expr!(< A: Bool | B: Text >));
+ assert_eq!(<E<bool>>::get_type(), dhall_expr!(< A: Bool | B: Text >));
}
diff --git a/dhall_generator/src/dhall_type.rs b/dhall_generator/src/dhall_type.rs
index 42549bb..ac8eb4e 100644
--- a/dhall_generator/src/dhall_type.rs
+++ b/dhall_generator/src/dhall_type.rs
@@ -6,8 +6,8 @@ use syn::spanned::Spanned;
use syn::Error;
use syn::{parse_quote, DeriveInput};
-pub fn derive_dhall_type(input: TokenStream) -> TokenStream {
- TokenStream::from(match derive_dhall_type_inner(input) {
+pub fn derive_type(input: TokenStream) -> TokenStream {
+ TokenStream::from(match derive_type_inner(input) {
Ok(tokens) => tokens,
Err(err) => err.to_compile_error(),
})
@@ -44,7 +44,7 @@ pub fn derive_for_struct(
quote! {
m.insert(
dhall_core::Label::from(#name),
- <#ty as dhall::DhallType>::dhall_type()
+ <#ty as dhall::Type>::get_type()
);
}
});
@@ -95,7 +95,7 @@ pub fn derive_for_enum(
Ok(quote! {
m.insert(
dhall_core::Label::from(#name),
- <#ty as dhall::DhallType>::dhall_type()
+ <#ty as dhall::Type>::get_type()
);
})
})
@@ -109,15 +109,15 @@ pub fn derive_for_enum(
})) })
}
-pub fn derive_dhall_type_inner(
+pub fn derive_type_inner(
input: TokenStream,
) -> Result<proc_macro2::TokenStream, Error> {
let input: DeriveInput = syn::parse_macro_input::parse(input)?;
- // List of types that must impl DhallType
+ // List of types that must impl Type
let mut constraints = vec![];
- let dhall_type = match &input.data {
+ let get_type = match &input.data {
syn::Data::Struct(data) => derive_for_struct(data, &mut constraints)?,
syn::Data::Enum(data) if data.variants.is_empty() => {
return Err(Error::new(
@@ -142,13 +142,13 @@ pub fn derive_dhall_type_inner(
// Hygienic errors
let assertions = constraints.iter().enumerate().map(|(i, ty)| {
- // Ensure that ty: DhallType, with an appropriate span
+ // Ensure that ty: Type, with an appropriate span
let assert_name =
- syn::Ident::new(&format!("_AssertDhallType{}", i), ty.span());
+ syn::Ident::new(&format!("_AssertType{}", i), ty.span());
let mut local_where_clause = orig_where_clause.clone();
local_where_clause
.predicates
- .push(parse_quote!(#ty: dhall::DhallType));
+ .push(parse_quote!(#ty: dhall::Type));
let phantoms = generics.params.iter().map(|param| match param {
syn::GenericParam::Type(syn::TypeParam { ident, .. }) => {
quote!(#ident)
@@ -165,21 +165,21 @@ pub fn derive_dhall_type_inner(
}
});
- // Ensure that all the fields have a DhallType impl
+ // Ensure that all the fields have a Type impl
let mut where_clause = orig_where_clause.clone();
for ty in constraints.iter() {
where_clause
.predicates
- .push(parse_quote!(#ty: dhall::DhallType));
+ .push(parse_quote!(#ty: dhall::Type));
}
let ident = &input.ident;
let tokens = quote! {
- impl #impl_generics dhall::DhallType for #ident #ty_generics
+ impl #impl_generics dhall::Type for #ident #ty_generics
#where_clause {
- fn dhall_type() -> dhall_core::DhallExpr {
+ fn get_type() -> dhall_core::DhallExpr {
#(#assertions)*
- #dhall_type
+ #get_type
}
}
};
diff --git a/dhall_generator/src/lib.rs b/dhall_generator/src/lib.rs
index b52c454..d720b67 100644
--- a/dhall_generator/src/lib.rs
+++ b/dhall_generator/src/lib.rs
@@ -10,7 +10,7 @@ pub fn dhall_expr(input: TokenStream) -> TokenStream {
dhall_expr::dhall_expr(input)
}
-#[proc_macro_derive(DhallType)]
-pub fn derive_dhall_type(input: TokenStream) -> TokenStream {
- dhall_type::derive_dhall_type(input)
+#[proc_macro_derive(Type)]
+pub fn derive_type(input: TokenStream) -> TokenStream {
+ dhall_type::derive_type(input)
}