diff options
-rw-r--r-- | Cargo.lock | 7 | ||||
m--------- | dhall-lang | 0 | ||||
-rw-r--r-- | dhall/build.rs | 15 | ||||
-rw-r--r-- | dhall/src/phase/binary.rs | 24 | ||||
-rw-r--r-- | dhall/src/phase/typecheck.rs | 4 | ||||
-rw-r--r-- | dhall_generated_parser/src/dhall.pest.visibility | 1 | ||||
-rw-r--r-- | dhall_syntax/Cargo.toml | 1 | ||||
-rw-r--r-- | dhall_syntax/src/core/import.rs | 5 | ||||
-rw-r--r-- | dhall_syntax/src/parser.rs | 19 | ||||
-rw-r--r-- | dhall_syntax/src/printer.rs | 4 | ||||
-rw-r--r-- | tests_buffer | 1 |
11 files changed, 53 insertions, 28 deletions
@@ -107,6 +107,7 @@ version = "0.1.0" dependencies = [ "dhall_generated_parser 0.1.0", "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "improved_slice_patterns 2.0.0", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -151,6 +152,11 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "improved_slice_patterns" version = "2.0.0" @@ -439,6 +445,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" "checksum half 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9353c2a89d550b58fa0061d8ed8d002a7d8cdf2494eb0e432859bd3a9e543836" +"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" diff --git a/dhall-lang b/dhall-lang -Subproject f12c7b5c37b9667162255d9562c811896965eff +Subproject ee528e5a89f78bce2c28167b5dfb7e7ea6b3d6c diff --git a/dhall/build.rs b/dhall/build.rs index 46bb3a4..3f09d47 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -35,11 +35,11 @@ fn dhall_files_in_dir<'a>( } fn make_test_module( - w: &mut impl Write, - mod_name: &str, - dir: &Path, - feature: &str, - mut exclude: impl FnMut(&str) -> bool, + w: &mut impl Write, // Where to output the generated code + mod_name: &str, // Name of the module, used in the output of `cargo test` + dir: &Path, // Directory containing the tests files + feature: &str, // Relevant variant of `dhall::tests::Feature` + mut exclude: impl FnMut(&str) -> bool, // Given a file name, whether to exclude it ) -> std::io::Result<()> { writeln!(w, "mod {} {{", mod_name)?; for (name, path) in dhall_files_in_dir(&dir.join("success/"), true) { @@ -67,6 +67,8 @@ fn make_test_module( } fn main() -> std::io::Result<()> { + // Tries to detect when the submodule gets updated; doesn't really work. + // To force regeneration of the test list, just `touch dhall-lang/.git` println!("cargo:rerun-if-changed=../dhall-lang/.git"); println!( "cargo:rerun-if-changed=../.git/modules/dhall-lang/refs/heads/master" @@ -129,6 +131,9 @@ fn main() -> std::io::Result<()> { path == "success/simple/integerToDouble" // Too slow || path == "success/remoteSystems" + // TODO: selection by expression + || path == "success/unit/RecordProjectionTypeEmpty" + || path == "success/unit/RecordProjectionTypeNonEmpty" }, )?; diff --git a/dhall/src/phase/binary.rs b/dhall/src/phase/binary.rs index 96eaa6c..1812131 100644 --- a/dhall/src/phase/binary.rs +++ b/dhall/src/phase/binary.rs @@ -196,17 +196,15 @@ fn cbor_value_to_dhall( }; let hash = match hash { Null => None, - Array(vec) => match vec.as_slice() { - [String(protocol), String(hash)] => Some(Hash { - protocol: protocol.clone(), - hash: hash.clone(), - }), - _ => Err(DecodeError::WrongFormatError( - "import/hash".to_owned(), - ))?, + Bytes(bytes) => match bytes.as_slice() { + [18, 32, rest..] => Some(Hash::SHA256(rest.to_vec())), + _ => Err(DecodeError::WrongFormatError(format!( + "import/hash/unknown_multihash: {:?}", + bytes + )))?, }, _ => Err(DecodeError::WrongFormatError( - "import/hash".to_owned(), + "import/hash/should_be_bytes".to_owned(), ))?, }; let mut rest = rest.iter(); @@ -518,7 +516,7 @@ fn serialize_import<S>(ser: S, import: &Import) -> Result<S::Ok, S::Error> where S: serde::ser::Serializer, { - use cbor::Value::{Array, Null, String, U64}; + use cbor::Value::{Bytes, Null, U64}; use serde::ser::SerializeSeq; let count = 4 + match &import.location_hashed.location { @@ -533,8 +531,10 @@ where let hash = match &import.location_hashed.hash { None => Null, - Some(h) => { - Array(vec![String(h.protocol.clone()), String(h.hash.clone())]) + Some(Hash::SHA256(h)) => { + let mut bytes = vec![18, 32]; + bytes.extend_from_slice(h); + Bytes(bytes) } }; ser_seq.serialize_element(&hash)?; diff --git a/dhall/src/phase/typecheck.rs b/dhall/src/phase/typecheck.rs index 11d6c7a..53ad99b 100644 --- a/dhall/src/phase/typecheck.rs +++ b/dhall/src/phase/typecheck.rs @@ -1118,7 +1118,6 @@ mod spec_tests { tc_success!(tc_success_recordOfTypes, "recordOfTypes"); // tc_success!(tc_success_simple_access_0, "simple/access/0"); // tc_success!(tc_success_simple_access_1, "simple/access/1"); - // tc_success!(tc_success_simple_alternativesAreTypes, "simple/alternativesAreTypes"); // tc_success!(tc_success_simple_anonymousFunctionsInTypes, "simple/anonymousFunctionsInTypes"); // tc_success!(tc_success_simple_fieldsAreTypes, "simple/fieldsAreTypes"); // tc_success!(tc_success_simple_kindParameter, "simple/kindParameter"); @@ -1248,6 +1247,7 @@ mod spec_tests { ti_success!(ti_success_unit_ListReverse, "unit/ListReverse"); ti_success!(ti_success_unit_MergeEmptyUnion, "unit/MergeEmptyUnion"); ti_success!(ti_success_unit_MergeOne, "unit/MergeOne"); + ti_success!(ti_success_unit_MergeOneEmpty, "unit/MergeOneEmpty"); ti_success!(ti_success_unit_MergeOneWithAnnotation, "unit/MergeOneWithAnnotation"); ti_success!(ti_success_unit_Natural, "unit/Natural"); ti_success!(ti_success_unit_NaturalBuild, "unit/NaturalBuild"); @@ -1334,7 +1334,7 @@ mod spec_tests { ti_success!(ti_success_unit_TypeAnnotationSort, "unit/TypeAnnotationSort"); ti_success!(ti_success_unit_UnionConstructorEmptyField, "unit/UnionConstructorEmptyField"); ti_success!(ti_success_unit_UnionConstructorField, "unit/UnionConstructorField"); - ti_success!(ti_success_unit_UnionOne, "unit/UnionOne"); + ti_success!(ti_success_unit_UnionLiteralOne, "unit/UnionLiteralOne"); ti_success!(ti_success_unit_UnionTypeEmpty, "unit/UnionTypeEmpty"); ti_success!(ti_success_unit_UnionTypeKind, "unit/UnionTypeKind"); ti_success!(ti_success_unit_UnionTypeOne, "unit/UnionTypeOne"); diff --git a/dhall_generated_parser/src/dhall.pest.visibility b/dhall_generated_parser/src/dhall.pest.visibility index 6e83052..60de54d 100644 --- a/dhall_generated_parser/src/dhall.pest.visibility +++ b/dhall_generated_parser/src/dhall.pest.visibility @@ -155,6 +155,7 @@ first_application_expression selector_expression selector labels +# type_selector primitive_expression # record_type_or_literal empty_record_literal diff --git a/dhall_syntax/Cargo.toml b/dhall_syntax/Cargo.toml index b25a0fe..6a61b09 100644 --- a/dhall_syntax/Cargo.toml +++ b/dhall_syntax/Cargo.toml @@ -14,5 +14,6 @@ percent-encoding = "1.0.1" pest = "2.1" either = "1.5.2" take_mut = "0.2.2" +hex = "0.3.2" dhall_generated_parser = { path = "../dhall_generated_parser" } improved_slice_patterns = { version = "2.0.0", path = "../improved_slice_patterns" } diff --git a/dhall_syntax/src/core/import.rs b/dhall_syntax/src/core/import.rs index fbf2f7b..c328e34 100644 --- a/dhall_syntax/src/core/import.rs +++ b/dhall_syntax/src/core/import.rs @@ -43,9 +43,8 @@ pub enum ImportMode { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Hash { - pub protocol: String, - pub hash: String, +pub enum Hash { + SHA256(Vec<u8>), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/dhall_syntax/src/parser.rs b/dhall_syntax/src/parser.rs index 316ef2f..9d9a374 100644 --- a/dhall_syntax/src/parser.rs +++ b/dhall_syntax/src/parser.rs @@ -461,6 +461,11 @@ make_parser! { lines.push(vec![]); lines }, + [single_quote_char("\r\n"), single_quote_continue(lines)] => { + let mut lines = lines; + lines.push(vec![]); + lines + }, [single_quote_char(c), single_quote_continue(lines)] => { // TODO: don't allocate for every char let c = InterpolatedTextContents::Text(c.to_owned()); @@ -654,12 +659,15 @@ make_parser! { }, )); - rule!(hash<Hash>; captured_str!(s) => - Hash { - protocol: s.trim()[..6].to_owned(), - hash: s.trim()[7..].to_owned(), + rule!(hash<Hash>; captured_str!(s) => { + let s = s.trim(); + let protocol = &s[..6]; + let hash = &s[7..]; + if protocol != "sha256" { + Err(format!("Unknown hashing protocol '{}'", protocol))? } - ); + Hash::SHA256(hex::decode(hash).unwrap()) + }); rule!(import_hashed<ImportHashed>; children!( [import_type(location)] => @@ -870,6 +878,7 @@ make_parser! { rule!(selector<Either<Label, Vec<Label>>>; children!( [label(l)] => Either::Left(l), [labels(ls)] => Either::Right(ls), + [expression(e)] => unimplemented!("selection by expression"), // TODO )); rule!(labels<Vec<Label>>; children!( diff --git a/dhall_syntax/src/printer.rs b/dhall_syntax/src/printer.rs index f1ce230..dbed55d 100644 --- a/dhall_syntax/src/printer.rs +++ b/dhall_syntax/src/printer.rs @@ -348,7 +348,9 @@ impl Display for Label { impl Display for Hash { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "{}:{}", self.protocol, self.hash) + match self { + Hash::SHA256(hash) => write!(f, "sha256:{}", hex::encode(hash)), + } } } impl Display for ImportHashed { diff --git a/tests_buffer b/tests_buffer index 75a233b..1ea9a1c 100644 --- a/tests_buffer +++ b/tests_buffer @@ -5,6 +5,7 @@ text interpolation and escapes remove `double` remove imports/parenthesizeUsing remove multilet +selection by expression unit tests success/ imports/ Missing missing |