diff options
author | Nadrieril | 2020-03-01 18:18:01 +0000 |
---|---|---|
committer | Nadrieril | 2020-03-05 15:58:54 +0000 |
commit | df4495f30708180591b630bb720cfe81ff4118ce (patch) | |
tree | 7977c0582cae8b19947c7e89722898faf989b0fd /dhall/src/semantics/resolve | |
parent | cbc1825313389746f08df5502568b2e13e04790d (diff) |
Implement `as Text` imports
Diffstat (limited to '')
-rw-r--r-- | dhall/src/semantics/resolve/resolve.rs | 21 |
1 files changed, 20 insertions, 1 deletions
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) => { |