From facd2c587d96510c5a808f19d37b40c1fc2d2618 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 11 Nov 2019 17:20:48 +0000 Subject: Parse projection by expression --- dhall/build.rs | 23 +---------------------- dhall/src/phase/binary.rs | 10 ++++++++++ dhall/src/phase/normalize.rs | 1 + dhall/src/phase/typecheck.rs | 1 + 4 files changed, 13 insertions(+), 22 deletions(-) (limited to 'dhall') diff --git a/dhall/build.rs b/dhall/build.rs index 337480f..a0106de 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -125,12 +125,6 @@ fn main() -> std::io::Result<()> { || path == "largeExpression" // Pretty sure the test is incorrect || path == "unit/import/urls/quotedPathFakeUrlEncode" - // TODO: projection by expression - || path == "recordProjectionByExpression" - || path == "RecordProjectionByType" - || path == "unit/RecordProjectionByType" - || path == "unit/RecordProjectionByTypeEmpty" - || path == "unit/RecordProjectFields" // TODO: RFC3986 URLs || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" @@ -163,11 +157,6 @@ fn main() -> std::io::Result<()> { false // Too slow in debug mode || path == "largeExpression" - // TODO: projection by expression - || path == "recordProjectionByExpression" - || path == "RecordProjectionByType" - || path == "unit/RecordProjectionByType" - || path == "unit/RecordProjectionByTypeEmpty" // TODO: RFC3986 URLs || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" @@ -194,11 +183,6 @@ fn main() -> std::io::Result<()> { || path == "double" || path == "unit/DoubleLitExponentNoDot" || path == "unit/DoubleLitSecretelyInt" - // TODO: projection by expression - || path == "recordProjectionByExpression" - || path == "RecordProjectionByType" - || path == "unit/RecordProjectionByType" - || path == "unit/RecordProjectionByTypeEmpty" // TODO: RFC3986 URLs || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" @@ -215,12 +199,7 @@ fn main() -> std::io::Result<()> { module_name: "binary_decoding_success", directory: spec_tests_dir.join("binary-decode/success/"), variant: "BinaryDecodingSuccess", - path_filter: |path: &str| { - false - // TODO: projection by expression - || path == "unit/RecordProjectFields" - || path == "unit/recordProjectionByExpression" - }, + path_filter: |_path: &str| false, input_type: FileType::Binary, output_type: Some(FileType::Text), }, diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index b4f18da..464d71a 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -181,6 +181,15 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result { let l = Label::from(l.as_str()); Field(x, l) } + [U64(10), x, Array(arr)] => { + let x = cbor_value_to_dhall(&x)?; + if let [y] = arr.as_slice() { + let y = cbor_value_to_dhall(&y)?; + ProjectionByExpr(x, y) + } else { + Err(DecodeError::WrongFormatError("projection-by-expr".to_owned()))? + } + } [U64(10), x, rest @ ..] => { let x = cbor_value_to_dhall(&x)?; let labels = rest @@ -577,6 +586,7 @@ where .chain(once(expr(x))) .chain(ls.iter().map(label)), ), + ProjectionByExpr(x, y) => ser_seq!(ser; tag(10), expr(x), vec![expr(y)]), Import(import) => serialize_import(ser, import), Embed(_) => unimplemented!( "An expression with resolved imports cannot be binary-encoded" diff --git a/dhall/src/phase/normalize.rs b/dhall/src/phase/normalize.rs index 0992f74..ae1aefe 100644 --- a/dhall/src/phase/normalize.rs +++ b/dhall/src/phase/normalize.rs @@ -738,6 +738,7 @@ pub(crate) fn normalize_one_layer( } } } + ExprF::ProjectionByExpr(_, _) => unimplemented!("selection by expression"), ExprF::Merge(ref handlers, ref variant, _) => { let handlers_borrow = handlers.as_whnf(); diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 33919e4..265a20e 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -787,6 +787,7 @@ fn type_last_layer( record_type.get_type()?, )) } + ProjectionByExpr(_, _) => unimplemented!("selection by expression"), }; Ok(match ret { -- cgit v1.2.3