summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-03-22 00:01:30 +0100
committerNadrieril2019-03-22 00:01:30 +0100
commitfe38fd6a8859447a154a5698a3e21d9203262be2 (patch)
tree814b0db038315f4b193374a9f5f9e672941bb0c3 /dhall
parent66e7c7750844bc976f23616c4a0103e778bdf4bd (diff)
Parse a lot more of the import types
Diffstat (limited to 'dhall')
-rw-r--r--dhall/src/binary.rs93
-rw-r--r--dhall/src/imports.rs1
-rw-r--r--dhall/tests/parser.rs14
3 files changed, 91 insertions, 17 deletions
diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs
index 8fe66f5..a028e82 100644
--- a/dhall/src/binary.rs
+++ b/dhall/src/binary.rs
@@ -1,7 +1,6 @@
use dhall_core::*;
use itertools::*;
use serde_cbor::value::value as cbor;
-use std::path::PathBuf;
use std::rc::Rc;
type ParsedExpr = Rc<Expr<X, Import>>;
@@ -180,18 +179,92 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> {
.collect::<Result<_, _>>()?,
)))
}
- [U64(24), Null, U64(0), U64(3), rest..] => {
- let mut path = PathBuf::new();
- for s in rest {
- match s {
- String(s) => path.push(s),
- _ => Err(DecodeError::WrongFormatError)?,
+ [U64(24), _hash, U64(mode), U64(scheme), rest..] => {
+ let mode = match mode {
+ 1 => ImportMode::RawText,
+ _ => ImportMode::Code,
+ };
+ let mut rest = rest.iter();
+ let location = match scheme {
+ 0 | 1 => {
+ let scheme = match scheme {
+ 0 => Scheme::HTTP,
+ _ => Scheme::HTTPS,
+ };
+ let _headers = match rest.next() {
+ Some(Null) => (),
+ _ => Err(DecodeError::WrongFormatError(
+ "import/remote/headers".to_owned(),
+ ))?,
+ };
+ let authority = match rest.next() {
+ Some(String(s)) => s.to_owned(),
+ _ => Err(DecodeError::WrongFormatError(
+ "import/remote/authority".to_owned(),
+ ))?,
+ };
+ let query = match rest.next_back() {
+ Some(Null) => None,
+ Some(String(s)) => Some(s.to_owned()),
+ _ => Err(DecodeError::WrongFormatError(
+ "import/remote/query".to_owned(),
+ ))?,
+ };
+ let path = rest
+ .map(|s| {
+ s.as_string().ok_or(
+ DecodeError::WrongFormatError(
+ "import/remote/path".to_owned(),
+ ),
+ )
+ })
+ .collect::<Result<_, _>>()?;
+ ImportLocation::Remote(URL {
+ scheme,
+ authority,
+ path,
+ query,
+ })
}
- }
+ 2 | 3 | 4 | 5 => {
+ let prefix = match scheme {
+ 2 => FilePrefix::Absolute,
+ 3 => FilePrefix::Here,
+ 4 => FilePrefix::Parent,
+ 5 => FilePrefix::Home,
+ _ => Err(DecodeError::WrongFormatError(
+ "import/local/prefix".to_owned(),
+ ))?,
+ };
+ let path = rest
+ .map(|s| {
+ s.as_string().ok_or(
+ DecodeError::WrongFormatError(
+ "import/local/path".to_owned(),
+ ),
+ )
+ })
+ .collect::<Result<_, _>>()?;
+ ImportLocation::Local(prefix, path)
+ }
+ 6 => {
+ let env = match rest.next() {
+ Some(String(s)) => s.to_owned(),
+ _ => Err(DecodeError::WrongFormatError(
+ "import/env".to_owned(),
+ ))?,
+ };
+ ImportLocation::Env(env)
+ }
+ 7 => ImportLocation::Missing,
+ _ => Err(DecodeError::WrongFormatError(
+ "import/type".to_owned(),
+ ))?,
+ };
Embed(Import {
- mode: ImportMode::Code,
+ mode,
hash: None,
- location: ImportLocation::Local(FilePrefix::Here, path),
+ location,
})
}
[U64(25), bindings..] => {
diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs
index 9f60ee7..8a2edce 100644
--- a/dhall/src/imports.rs
+++ b/dhall/src/imports.rs
@@ -38,6 +38,7 @@ fn resolve_import(
};
load_dhall_file(&path, true)
}
+ _ => unimplemented!("{:?}", import),
}
}
diff --git a/dhall/tests/parser.rs b/dhall/tests/parser.rs
index 79a059d..637341d 100644
--- a/dhall/tests/parser.rs
+++ b/dhall/tests/parser.rs
@@ -14,13 +14,13 @@ macro_rules! parser_failure {
}
parser_success!(spec_parser_success_annotations, "annotations");
-// parser_success!(spec_parser_success_asText, "asText");
+parser_success!(spec_parser_success_asText, "asText");
parser_success!(spec_parser_success_blockComment, "blockComment");
parser_success!(spec_parser_success_builtins, "builtins");
parser_success!(spec_parser_success_collectionImportType, "collectionImportType");
parser_success!(spec_parser_success_double, "double");
parser_success!(spec_parser_success_doubleQuotedString, "doubleQuotedString");
-// parser_success!(spec_parser_success_environmentVariables, "environmentVariables");
+parser_success!(spec_parser_success_environmentVariables, "environmentVariables");
// parser_success!(spec_parser_success_escapedDoubleQuotedString, "escapedDoubleQuotedString");
parser_success!(spec_parser_success_escapedSingleQuotedString, "escapedSingleQuotedString");
parser_success!(spec_parser_success_fields, "fields");
@@ -28,7 +28,7 @@ parser_success!(spec_parser_success_forall, "forall");
parser_success!(spec_parser_success_functionType, "functionType");
parser_success!(spec_parser_success_identifier, "identifier");
parser_success!(spec_parser_success_ifThenElse, "ifThenElse");
-// parser_success!(spec_parser_success_importAlt, "importAlt");
+parser_success!(spec_parser_success_importAlt, "importAlt");
parser_success!(spec_parser_success_interpolatedDoubleQuotedString, "interpolatedDoubleQuotedString");
parser_success!(spec_parser_success_interpolatedSingleQuotedString, "interpolatedSingleQuotedString");
parser_success!(spec_parser_success_label, "label");
@@ -43,10 +43,10 @@ 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_pathTermination, "pathTermination");
-// parser_success!(spec_parser_success_paths, "paths");
+parser_success!(spec_parser_success_pathTermination, "pathTermination");
+parser_success!(spec_parser_success_paths, "paths");
// parser_success!(spec_parser_success_quotedLabel, "quotedLabel");
-// parser_success!(spec_parser_success_quotedPaths, "quotedPaths");
+parser_success!(spec_parser_success_quotedPaths, "quotedPaths");
parser_success!(spec_parser_success_record, "record");
parser_success!(spec_parser_success_reservedPrefix, "reservedPrefix");
parser_success!(spec_parser_success_singleQuotedString, "singleQuotedString");
@@ -54,7 +54,7 @@ parser_success!(spec_parser_success_sort, "sort");
parser_success!(spec_parser_success_template, "template");
parser_success!(spec_parser_success_unicodeComment, "unicodeComment");
parser_success!(spec_parser_success_unicodeDoubleQuotedString, "unicodeDoubleQuotedString");
-// parser_success!(spec_parser_success_unicodePaths, "unicodePaths");
+parser_success!(spec_parser_success_unicodePaths, "unicodePaths");
parser_success!(spec_parser_success_union, "union");
// parser_success!(spec_parser_success_urls, "urls");
parser_success!(spec_parser_success_whitespace, "whitespace");