summaryrefslogtreecommitdiff
path: root/dhall/src/syntax/binary
diff options
context:
space:
mode:
Diffstat (limited to 'dhall/src/syntax/binary')
-rw-r--r--dhall/src/syntax/binary/decode.rs20
-rw-r--r--dhall/src/syntax/binary/encode.rs12
-rw-r--r--dhall/src/syntax/binary/mod.rs4
3 files changed, 18 insertions, 18 deletions
diff --git a/dhall/src/syntax/binary/decode.rs b/dhall/src/syntax/binary/decode.rs
index 2ecd7e0..3c93419 100644
--- a/dhall/src/syntax/binary/decode.rs
+++ b/dhall/src/syntax/binary/decode.rs
@@ -6,12 +6,12 @@ use crate::error::DecodeError;
use crate::syntax;
use crate::syntax::{
Expr, ExprKind, FilePath, FilePrefix, Hash, ImportMode, ImportTarget,
- Integer, InterpolatedText, Label, LitKind, Natural, Scheme, Span,
+ Integer, InterpolatedText, Label, Natural, NumKind, Scheme, Span,
UnspannedExpr, URL, V,
};
-use crate::DecodedExpr;
+type DecodedExpr = Expr;
-pub(crate) fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> {
+pub fn decode(data: &[u8]) -> Result<DecodedExpr, DecodeError> {
match serde_cbor::de::from_slice(data) {
Ok(v) => cbor_value_to_dhall(&v),
Err(e) => Err(DecodeError::CBORError(e)),
@@ -31,8 +31,8 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
String(s) => match Builtin::parse(s) {
Some(b) => ExprKind::Builtin(b),
None => match s.as_str() {
- "True" => Lit(LitKind::Bool(true)),
- "False" => Lit(LitKind::Bool(false)),
+ "True" => Num(NumKind::Bool(true)),
+ "False" => Num(NumKind::Bool(false)),
"Type" => Const(Const::Type),
"Kind" => Const(Const::Kind),
"Sort" => Const(Const::Sort),
@@ -44,8 +44,8 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
},
},
U64(n) => Var(V(Label::from("_"), *n as usize)),
- F64(x) => Lit(LitKind::Double((*x).into())),
- Bool(b) => Lit(LitKind::Bool(*b)),
+ F64(x) => Num(NumKind::Double((*x).into())),
+ Bool(b) => Num(NumKind::Bool(*b)),
Array(vec) => match vec.as_slice() {
[String(l), U64(n)] => {
if l.as_str() == "_" {
@@ -224,9 +224,9 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<DecodedExpr, DecodeError> {
let z = cbor_value_to_dhall(&z)?;
BoolIf(x, y, z)
}
- [U64(15), U64(x)] => Lit(LitKind::Natural(*x as Natural)),
- [U64(16), U64(x)] => Lit(LitKind::Integer(*x as Integer)),
- [U64(16), I64(x)] => Lit(LitKind::Integer(*x as Integer)),
+ [U64(15), U64(x)] => Num(NumKind::Natural(*x as Natural)),
+ [U64(16), U64(x)] => Num(NumKind::Integer(*x as Integer)),
+ [U64(16), I64(x)] => Num(NumKind::Integer(*x as Integer)),
[U64(18), String(first), rest @ ..] => {
TextLit(InterpolatedText::from((
first.clone(),
diff --git a/dhall/src/syntax/binary/encode.rs b/dhall/src/syntax/binary/encode.rs
index 9e6948e..8d22a9b 100644
--- a/dhall/src/syntax/binary/encode.rs
+++ b/dhall/src/syntax/binary/encode.rs
@@ -10,7 +10,7 @@ use crate::syntax::{
Scheme, V,
};
-pub(crate) fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
+pub fn encode(expr: &Expr) -> Result<Vec<u8>, EncodeError> {
serde_cbor::ser::to_vec(&Serialize::Expr(expr))
.map_err(EncodeError::CBORError)
}
@@ -48,7 +48,7 @@ where
use std::iter::once;
use syntax::Builtin;
use syntax::ExprKind::*;
- use syntax::LitKind::*;
+ use syntax::NumKind::*;
use self::Serialize::{RecordDupMap, RecordMap, UnionMap};
fn expr(x: &Expr) -> self::Serialize<'_> {
@@ -63,10 +63,10 @@ where
match e.as_ref() {
Const(c) => ser.serialize_str(&c.to_string()),
Builtin(b) => ser.serialize_str(&b.to_string()),
- Lit(Bool(b)) => ser.serialize_bool(*b),
- Lit(Natural(n)) => ser_seq!(ser; tag(15), U64(*n as u64)),
- Lit(Integer(n)) => ser_seq!(ser; tag(16), I64(*n as i64)),
- Lit(Double(n)) => {
+ Num(Bool(b)) => ser.serialize_bool(*b),
+ Num(Natural(n)) => ser_seq!(ser; tag(15), U64(*n as u64)),
+ Num(Integer(n)) => ser_seq!(ser; tag(16), I64(*n as i64)),
+ Num(Double(n)) => {
let n: f64 = (*n).into();
ser.serialize_f64(n)
}
diff --git a/dhall/src/syntax/binary/mod.rs b/dhall/src/syntax/binary/mod.rs
index 7ed1f6e..98e0520 100644
--- a/dhall/src/syntax/binary/mod.rs
+++ b/dhall/src/syntax/binary/mod.rs
@@ -1,4 +1,4 @@
mod decode;
mod encode;
-pub(crate) use decode::decode;
-pub(crate) use encode::encode;
+pub use decode::decode;
+pub use encode::encode;