diff options
Diffstat (limited to 'dhall')
| -rw-r--r-- | dhall/src/binary.rs | 35 | ||||
| -rw-r--r-- | dhall/src/imports.rs | 2 | ||||
| -rw-r--r-- | dhall/tests/parser.rs | 2 | 
3 files changed, 32 insertions, 7 deletions
| diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs index a028e82..eb96da2 100644 --- a/dhall/src/binary.rs +++ b/dhall/src/binary.rs @@ -179,11 +179,26 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {                          .collect::<Result<_, _>>()?,                  )))              } -            [U64(24), _hash, U64(mode), U64(scheme), rest..] => { +            [U64(24), hash, U64(mode), U64(scheme), rest..] => {                  let mode = match mode {                      1 => ImportMode::RawText,                      _ => ImportMode::Code,                  }; +                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(), +                        ))?, +                    }, +                    _ => Err(DecodeError::WrongFormatError( +                        "import/hash".to_owned(), +                    ))?, +                };                  let mut rest = rest.iter();                  let location = match scheme {                      0 | 1 => { @@ -191,8 +206,18 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {                              0 => Scheme::HTTP,                              _ => Scheme::HTTPS,                          }; -                        let _headers = match rest.next() { -                            Some(Null) => (), +                        let headers = match rest.next() { +                            Some(Null) => None, +                            Some(x) => { +                                match cbor_value_to_dhall(&x)?.as_ref() { +                                    Embed(import) => Some(Box::new( +                                        import.location_hashed.clone(), +                                    )), +                                    _ => Err(DecodeError::WrongFormatError( +                                        "import/remote/headers".to_owned(), +                                    ))?, +                                } +                            }                              _ => Err(DecodeError::WrongFormatError(                                  "import/remote/headers".to_owned(),                              ))?, @@ -224,6 +249,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {                              authority,                              path,                              query, +                            headers,                          })                      }                      2 | 3 | 4 | 5 => { @@ -263,8 +289,7 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {                  };                  Embed(Import {                      mode, -                    hash: None, -                    location, +                    location_hashed: ImportHashed { hash, location },                  })              }              [U64(25), bindings..] => { diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index 8a2edce..8df4e97 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -29,7 +29,7 @@ fn resolve_import(      let cwd = match root {          LocalDir(cwd) => cwd,      }; -    match &import.location { +    match &import.location_hashed.location {          Local(prefix, path) => {              let path = match prefix {                  Parent => cwd.parent().unwrap().join(path), diff --git a/dhall/tests/parser.rs b/dhall/tests/parser.rs index 5f57068..1db8d33 100644 --- a/dhall/tests/parser.rs +++ b/dhall/tests/parser.rs @@ -42,7 +42,7 @@ parser_success!(spec_parser_success_multilet, "multilet");  parser_success!(spec_parser_success_natural, "natural");  parser_success!(spec_parser_success_nestedBlockComment, "nestedBlockComment");  parser_success!(spec_parser_success_operators, "operators"); -// parser_success!(spec_parser_success_parenthesizeUsing, "parenthesizeUsing"); +parser_success!(spec_parser_success_parenthesizeUsing, "parenthesizeUsing");  parser_success!(spec_parser_success_pathTermination, "pathTermination");  parser_success!(spec_parser_success_paths, "paths");  parser_success!(spec_parser_success_quotedLabel, "quotedLabel"); | 
