diff options
Diffstat (limited to 'dhall/src')
-rw-r--r-- | dhall/src/semantics/parse.rs | 5 | ||||
-rw-r--r-- | dhall/src/semantics/resolve/resolve.rs | 21 |
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) => { |