diff options
author | Nadrieril | 2020-03-04 21:26:01 +0000 |
---|---|---|
committer | Nadrieril | 2020-03-05 15:58:54 +0000 |
commit | 903d6c0bba36a6696eb337ae84b962f4cc48b5b5 (patch) | |
tree | 63cb58b2b566fb5532e59b1455fffc82fa89ce0d /dhall/src/semantics/parse.rs | |
parent | 5a9a5859eec0cf7deebf7fa07fe99f8dc8722ec8 (diff) |
Implement remote imports and cleanup import chaining
Diffstat (limited to '')
-rw-r--r-- | dhall/src/semantics/parse.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/dhall/src/semantics/parse.rs b/dhall/src/semantics/parse.rs index ffd5eca..45860d0 100644 --- a/dhall/src/semantics/parse.rs +++ b/dhall/src/semantics/parse.rs @@ -1,9 +1,10 @@ use std::fs::File; use std::io::Read; use std::path::Path; +use url::Url; use crate::error::Error; -use crate::semantics::resolve::ImportRoot; +use crate::semantics::resolve::ImportLocation; use crate::syntax::binary; use crate::syntax::parse_expr; use crate::Parsed; @@ -11,19 +12,26 @@ use crate::Parsed; pub(crate) fn parse_file(f: &Path) -> Result<Parsed, Error> { let text = std::fs::read_to_string(f)?; let expr = parse_expr(&text)?; - let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned()); + let root = ImportLocation::Local(f.to_owned()); + Ok(Parsed(expr, root)) +} + +pub(crate) fn parse_remote(url: Url) -> Result<Parsed, Error> { + let body = reqwest::blocking::get(url.clone()).unwrap().text().unwrap(); + let expr = parse_expr(&body)?; + let root = ImportLocation::Remote(url); Ok(Parsed(expr, root)) } pub(crate) fn parse_str(s: &str) -> Result<Parsed, Error> { let expr = parse_expr(s)?; - let root = ImportRoot::LocalDir(std::env::current_dir()?); + let root = ImportLocation::Missing; Ok(Parsed(expr, root)) } pub(crate) fn parse_binary(data: &[u8]) -> Result<Parsed, Error> { let expr = binary::decode(data)?; - let root = ImportRoot::LocalDir(std::env::current_dir()?); + let root = ImportLocation::Missing; Ok(Parsed(expr, root)) } @@ -31,6 +39,6 @@ pub(crate) fn parse_binary_file(f: &Path) -> Result<Parsed, Error> { let mut buffer = Vec::new(); File::open(f)?.read_to_end(&mut buffer)?; let expr = binary::decode(&buffer)?; - let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned()); + let root = ImportLocation::Local(f.to_owned()); Ok(Parsed(expr, root)) } |