From 4c159640e5ee77ffa48b85a5bffa56350cf933ef Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 4 May 2019 17:59:05 +0200 Subject: Make SubExpr generic in the variable labels type --- dhall/src/binary.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'dhall/src/binary.rs') 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; +type ParsedExpr = SubExpr; #[derive(Debug)] pub enum DecodeError { @@ -18,28 +18,32 @@ pub fn decode(data: &[u8]) -> Result { } fn cbor_value_to_dhall(data: &cbor::Value) -> Result { - 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 { 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)?; -- cgit v1.2.3