diff options
Diffstat (limited to '')
-rw-r--r-- | dhall/src/imports.rs | 26 | ||||
-rw-r--r-- | dhall/src/tests.rs | 8 |
2 files changed, 16 insertions, 18 deletions
diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index 3c33b4e..cedc072 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -1,6 +1,3 @@ -// use dhall_core::{Expr, FilePrefix, Import, ImportLocation, ImportMode, X}; -use dhall_core::{Expr, Import, X}; -// use std::path::Path; use crate::error::Error; use crate::expr::*; use dhall_core::*; @@ -27,7 +24,7 @@ pub enum ImportRoot { fn resolve_import( import: &Import, root: &ImportRoot, -) -> Result<Expr<X, X>, ImportError> { +) -> Result<Resolved, ImportError> { use self::ImportRoot::*; use dhall_core::FilePrefix::*; use dhall_core::ImportLocation::*; @@ -37,11 +34,12 @@ fn resolve_import( match &import.location_hashed.location { Local(prefix, path) => { let path = match prefix { + // TODO: fail gracefully Parent => cwd.parent().unwrap().join(path), Here => cwd.join(path), _ => unimplemented!("{:?}", import), }; - Ok(load_dhall_file(&path, true).map_err(|e| { + Ok(load_import(&path).map_err(|e| { ImportError::Recursive(import.clone(), Box::new(e)) })?) } @@ -49,6 +47,10 @@ fn resolve_import( } } +fn load_import(f: &Path) -> Result<Resolved, Error> { + Ok(Parsed::parse_file(f)?.resolve()?) +} + fn resolve_expr( Parsed(expr, root): Parsed, allow_imports: bool, @@ -56,7 +58,7 @@ fn resolve_expr( let resolve = |import: &Import| -> Result<SubExpr<X, X>, ImportError> { if allow_imports { let expr = resolve_import(import, &root)?; - Ok(expr.roll()) + Ok(expr.0) } else { Err(ImportError::UnexpectedImport(import.clone())) } @@ -96,12 +98,8 @@ impl Parsed { } } -// Deprecated -pub fn load_dhall_file( - f: &Path, - resolve_imports: bool, -) -> Result<Expr<X, X>, Error> { - let expr = Parsed::parse_file(f)?; - let expr = resolve_expr(expr, resolve_imports)?; - Ok(expr.0.unroll()) +// Deprecated, used for tests only +#[allow(dead_code)] +pub fn load_dhall_file(f: &Path) -> Result<SubExpr<X, X>, Error> { + Ok(load_import(f)?.0) } diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 9e78c2f..dede639 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -48,8 +48,8 @@ pub enum Feature { } // Deprecated -fn read_dhall_file<'i>(file_path: &str) -> Result<Expr<X, X>> { - crate::imports::load_dhall_file(&PathBuf::from(file_path), true) +fn read_dhall_file<'i>(file_path: &str) -> Result<SubExpr<X, X>> { + crate::imports::load_dhall_file(&PathBuf::from(file_path)) } fn parse_file_str<'i>(file_path: &str) -> Result<Parsed> { @@ -134,9 +134,9 @@ pub fn run_test(base_path: &str, feature: Feature) { .spawn(|| { let expr_file_path = base_path.clone() + "A.dhall"; let expected_file_path = base_path + "B.dhall"; - let expr = rc(read_dhall_file(&expr_file_path).unwrap()); + let expr = read_dhall_file(&expr_file_path).unwrap(); let expected = - rc(read_dhall_file(&expected_file_path).unwrap()); + read_dhall_file(&expected_file_path).unwrap(); typecheck::type_of(dhall::subexpr!(expr: expected)) .unwrap(); }) |