summaryrefslogtreecommitdiff
path: root/dhall/src/binary.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall/src/binary.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs
index 9c31d4c..0d9f28a 100644
--- a/dhall/src/binary.rs
+++ b/dhall/src/binary.rs
@@ -2,7 +2,7 @@ use dhall_syntax::*;
use itertools::*;
use serde_cbor::value::value as cbor;
-type ParsedExpr = SubExpr<X, Import>;
+type ParsedExpr = SubExpr<Label, X, Import>;
#[derive(Debug)]
pub enum DecodeError {
@@ -18,28 +18,32 @@ pub fn decode(data: &[u8]) -> Result<ParsedExpr, DecodeError> {
}
fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {
- use cbor::Value::*;
+ use cbor::Value::{Array, Bool, Null, Object, String, F64, I64, U64};
use dhall_syntax::{BinOp, Builtin, Const};
- use ExprF::*;
+ use ExprF::{
+ Annot, App, BoolIf, BoolLit, DoubleLit, Embed, EmptyListLit, Field,
+ IntegerLit, Lam, Let, Merge, NEListLit, NaturalLit, OldOptionalLit, Pi,
+ RecordLit, RecordType, SomeLit, TextLit, UnionLit, UnionType,
+ };
Ok(rc(match data {
String(s) => match Builtin::parse(s) {
Some(b) => ExprF::Builtin(b),
None => match s.as_str() {
"True" => BoolLit(true),
"False" => BoolLit(false),
- "Type" => Const(Const::Type),
- "Kind" => Const(Const::Kind),
- "Sort" => Const(Const::Sort),
+ "Type" => ExprF::Const(Const::Type),
+ "Kind" => ExprF::Const(Const::Kind),
+ "Sort" => ExprF::Const(Const::Sort),
_ => Err(DecodeError::WrongFormatError("builtin".to_owned()))?,
},
},
- U64(n) => Var(V(Label::from("_"), *n as usize)),
+ U64(n) => ExprF::Var(Var(Label::from("_"), *n as usize)),
F64(x) => DoubleLit((*x).into()),
Bool(b) => BoolLit(*b),
Array(vec) => match vec.as_slice() {
[String(l), U64(n)] => {
let l = Label::from(l.as_str());
- Var(V(l, *n as usize))
+ ExprF::Var(Var(l, *n as usize))
}
[U64(0), f, args..] => {
let mut f = cbor_value_to_dhall(&f)?;
@@ -92,7 +96,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {
Err(DecodeError::WrongFormatError("binop".to_owned()))?
}
};
- BinOp(op, x, y)
+ ExprF::BinOp(op, x, y)
}
[U64(4), t] => {
let t = cbor_value_to_dhall(&t)?;