summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall/src/lib.rs1
-rw-r--r--dhall/tests/dhall_type.rs15
-rw-r--r--dhall_core/src/dhall_type.rs10
-rw-r--r--dhall_core/src/lib.rs2
-rw-r--r--dhall_generator/src/dhall_expr.rs3
-rw-r--r--dhall_generator/src/dhall_type.rs15
-rw-r--r--dhall_generator/src/lib.rs9
7 files changed, 53 insertions, 2 deletions
diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs
index 3e76395..d9f9edb 100644
--- a/dhall/src/lib.rs
+++ b/dhall/src/lib.rs
@@ -10,7 +10,6 @@
mod normalize;
pub use crate::normalize::*;
pub mod binary;
-// pub mod dhall_type;
pub mod imports;
pub mod typecheck;
diff --git a/dhall/tests/dhall_type.rs b/dhall/tests/dhall_type.rs
new file mode 100644
index 0000000..cbb71a4
--- /dev/null
+++ b/dhall/tests/dhall_type.rs
@@ -0,0 +1,15 @@
+#![feature(proc_macro_hygiene)]
+use dhall_core::*;
+use dhall_generator::*;
+
+#[derive(DhallType)]
+struct A {
+ _field1: bool,
+ // field2: Option<bool>,
+}
+
+#[test]
+fn test_dhall_type_a() {
+ assert_eq!(A::dhall_type(), dhall_expr!(False));
+ // assert_eq!(A::dhall_type(), dhall_expr!({ field1: Bool }));
+}
diff --git a/dhall_core/src/dhall_type.rs b/dhall_core/src/dhall_type.rs
new file mode 100644
index 0000000..3635e67
--- /dev/null
+++ b/dhall_core/src/dhall_type.rs
@@ -0,0 +1,10 @@
+use crate::*;
+
+#[derive(Debug, Clone)]
+pub enum DhallConversionError {}
+
+pub trait DhallType: Sized {
+ fn dhall_type() -> DhallExpr;
+ // fn as_dhall(&self) -> DhallExpr;
+ // fn from_dhall(e: DhallExpr) -> Result<Self, DhallConversionError>;
+}
diff --git a/dhall_core/src/lib.rs b/dhall_core/src/lib.rs
index 0874b09..b15c644 100644
--- a/dhall_core/src/lib.rs
+++ b/dhall_core/src/lib.rs
@@ -18,4 +18,6 @@ mod printer;
pub use crate::printer::*;
mod parser;
pub use crate::parser::*;
+mod dhall_type;
+pub use dhall_type::*;
pub mod context;
diff --git a/dhall_generator/src/dhall_expr.rs b/dhall_generator/src/dhall_expr.rs
index 1eb4580..1ee4d1a 100644
--- a/dhall_generator/src/dhall_expr.rs
+++ b/dhall_generator/src/dhall_expr.rs
@@ -62,6 +62,9 @@ fn dhall_to_tokenstream(
NaturalLit(n) => {
quote! { dhall_core::Expr::NaturalLit(#n) }
}
+ BoolLit(b) => {
+ quote! { dhall_core::Expr::BoolLit(#b) }
+ }
EmptyOptionalLit(x) => {
let x = dhall_to_tokenstream_bx(x, ctx);
quote! { dhall_core::Expr::EmptyOptionalLit(#x) }
diff --git a/dhall_generator/src/dhall_type.rs b/dhall_generator/src/dhall_type.rs
new file mode 100644
index 0000000..7cfd945
--- /dev/null
+++ b/dhall_generator/src/dhall_type.rs
@@ -0,0 +1,15 @@
+extern crate proc_macro;
+// use dhall_core::*;
+// use proc_macro2::TokenStream;
+use quote::quote;
+
+pub fn derive_dhall_type(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+ (quote!{
+ impl DhallType for A {
+ fn dhall_type() -> dhall_core::DhallExpr {
+ dhall_core::rc(dhall_core::Expr::BoolLit(false))
+ }
+ }
+ }).into()
+}
+
diff --git a/dhall_generator/src/lib.rs b/dhall_generator/src/lib.rs
index 7d3304b..b52c454 100644
--- a/dhall_generator/src/lib.rs
+++ b/dhall_generator/src/lib.rs
@@ -1,9 +1,16 @@
extern crate proc_macro;
mod dhall_expr;
+mod dhall_type;
+
+use proc_macro::TokenStream;
#[proc_macro]
-pub fn dhall_expr(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
+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)
+}