summaryrefslogtreecommitdiff
path: root/dhall/src/semantics
diff options
context:
space:
mode:
authorNadrieril2020-03-01 17:26:59 +0000
committerNadrieril2020-03-05 15:58:54 +0000
commit386f34af802a812c2af8ece2cc427cfb5a7c1fe8 (patch)
tree2e6f092e5dff06f34f4a986ce3fc05cad5c957e4 /dhall/src/semantics
parent24ff14dc98b83ddc12239a0eae4852c9cd87d41f (diff)
Implement `missing` and `env:VAR` imports
Diffstat (limited to 'dhall/src/semantics')
-rw-r--r--dhall/src/semantics/resolve/resolve.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs
index b27dd2c..bf7aabb 100644
--- a/dhall/src/semantics/resolve/resolve.rs
+++ b/dhall/src/semantics/resolve/resolve.rs
@@ -1,6 +1,7 @@
use itertools::Itertools;
use std::borrow::Cow;
-use std::path::{Path, PathBuf};
+use std::env;
+use std::path::PathBuf;
use crate::error::ErrorBuilder;
use crate::error::{Error, ImportError};
@@ -47,8 +48,21 @@ fn resolve_one_import(
FilePrefix::Here => cwd.join(path_buf),
_ => unimplemented!("{:?}", import),
};
- Ok(load_import(env, &path_buf)?)
+
+ let parsed = Parsed::parse_file(&path_buf)?;
+ let typed = resolve_with_env(env, parsed)?.typecheck()?;
+ Ok((typed.normalize().to_hir(), typed.ty().clone()))
+ }
+ ImportLocation::Env(var_name) => {
+ let val = match env::var(var_name) {
+ Ok(val) => val,
+ Err(_) => Err(ImportError::MissingEnvVar)?,
+ };
+ let parsed = Parsed::parse_str(&val)?;
+ let typed = resolve_with_env(env, parsed)?.typecheck()?;
+ Ok((typed.normalize().to_hir(), typed.ty().clone()))
}
+ ImportLocation::Missing => Err(ImportError::Missing.into()),
_ => unimplemented!("{:?}", import),
}
}
@@ -122,12 +136,6 @@ fn resolve_one_import(
}
}
-fn load_import(env: &mut ImportEnv, f: &Path) -> Result<TypedHir, Error> {
- let parsed = Parsed::parse_file(f)?;
- let typed = resolve_with_env(env, parsed)?.typecheck()?;
- Ok((typed.normalize().to_hir(), typed.ty().clone()))
-}
-
/// Desugar the first level of the expression.
fn desugar(expr: &Expr) -> Cow<'_, Expr> {
match expr.kind() {