summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2020-03-01 18:18:01 +0000
committerNadrieril2020-03-05 15:58:54 +0000
commitdf4495f30708180591b630bb720cfe81ff4118ce (patch)
tree7977c0582cae8b19947c7e89722898faf989b0fd /dhall/src
parentcbc1825313389746f08df5502568b2e13e04790d (diff)
Implement `as Text` imports
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/semantics/parse.rs5
-rw-r--r--dhall/src/semantics/resolve/resolve.rs21
2 files changed, 22 insertions, 4 deletions
diff --git a/dhall/src/semantics/parse.rs b/dhall/src/semantics/parse.rs
index ee35536..ffd5eca 100644
--- a/dhall/src/semantics/parse.rs
+++ b/dhall/src/semantics/parse.rs
@@ -9,9 +9,8 @@ use crate::syntax::parse_expr;
use crate::Parsed;
pub(crate) fn parse_file(f: &Path) -> Result<Parsed, Error> {
- let mut buffer = String::new();
- File::open(f)?.read_to_string(&mut buffer)?;
- let expr = parse_expr(&*buffer)?;
+ let text = std::fs::read_to_string(f)?;
+ let expr = parse_expr(&text)?;
let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned());
Ok(Parsed(expr, root))
}
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs
index ad2cd75..f419858 100644
--- a/dhall/src/semantics/resolve/resolve.rs
+++ b/dhall/src/semantics/resolve/resolve.rs
@@ -99,7 +99,26 @@ fn resolve_one_import(
let typed = resolve_with_env(env, parsed)?.typecheck()?;
Ok((typed.normalize().to_hir(), typed.ty().clone()))
}
- ImportMode::RawText => unimplemented!("{:?}", import),
+ ImportMode::RawText => {
+ let text = match &import.location {
+ ImportLocation::Local(prefix, path) => {
+ let path = compute_relative_path(root, prefix, path);
+ std::fs::read_to_string(path)?
+ }
+ ImportLocation::Env(var_name) => match env::var(var_name) {
+ Ok(val) => val,
+ Err(_) => Err(ImportError::MissingEnvVar)?,
+ },
+ ImportLocation::Missing => Err(ImportError::Missing)?,
+ _ => unimplemented!("{:?}", import),
+ };
+
+ let hir = Hir::new(
+ HirKind::Expr(ExprKind::TextLit(text.into())),
+ Span::Artificial,
+ );
+ Ok((hir, Type::from_builtin(Builtin::Text)))
+ }
ImportMode::Location => {
let (field_name, arg) = match &import.location {
ImportLocation::Local(prefix, path) => {