summaryrefslogtreecommitdiff
path: root/dhall/src/simple.rs
diff options
context:
space:
mode:
Diffstat (limited to 'dhall/src/simple.rs')
-rw-r--r--dhall/src/simple.rs52
1 files changed, 51 insertions, 1 deletions
diff --git a/dhall/src/simple.rs b/dhall/src/simple.rs
index 6457291..9d3846e 100644
--- a/dhall/src/simple.rs
+++ b/dhall/src/simple.rs
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;
-use crate::syntax::LitKind;
+use crate::syntax::{Builtin, LitKind};
+use crate::Normalized;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SimpleValue {
@@ -17,6 +18,24 @@ pub enum SValKind {
Text(String),
}
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct SimpleType {
+ kind: Box<STyKind>,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum STyKind {
+ Bool,
+ Natural,
+ Integer,
+ Double,
+ Text,
+ Optional(SimpleType),
+ List(SimpleType),
+ Record(BTreeMap<String, SimpleType>),
+ Union(BTreeMap<String, Option<SimpleType>>),
+}
+
impl SimpleValue {
pub(crate) fn new(kind: SValKind) -> Self {
SimpleValue {
@@ -27,3 +46,34 @@ impl SimpleValue {
self.kind.as_ref()
}
}
+
+impl SimpleType {
+ pub fn new(kind: STyKind) -> Self {
+ SimpleType {
+ kind: Box::new(kind),
+ }
+ }
+ pub fn kind(&self) -> &STyKind {
+ self.kind.as_ref()
+ }
+ pub fn into_normalized(self) -> Normalized {
+ match *self.kind {
+ STyKind::Bool => Normalized::make_builtin_type(Builtin::Bool),
+ STyKind::Natural => Normalized::make_builtin_type(Builtin::Natural),
+ STyKind::Integer => Normalized::make_builtin_type(Builtin::Integer),
+ STyKind::Double => Normalized::make_builtin_type(Builtin::Double),
+ STyKind::Text => Normalized::make_builtin_type(Builtin::Text),
+ STyKind::Optional(t) => {
+ Normalized::make_optional_type(t.into_normalized())
+ }
+ STyKind::List(t) => Normalized::make_list_type(t.into_normalized()),
+ STyKind::Record(kts) => Normalized::make_record_type(
+ kts.into_iter().map(|(k, t)| (k, t.into_normalized())),
+ ),
+ STyKind::Union(kts) => Normalized::make_union_type(
+ kts.into_iter()
+ .map(|(k, t)| (k, t.map(|t| t.into_normalized()))),
+ ),
+ }
+ }
+}