diff options
author | Nadrieril | 2019-03-21 22:08:23 +0100 |
---|---|---|
committer | Nadrieril | 2019-03-21 22:08:23 +0100 |
commit | 4b99a3fb46191a83fa8551f21b98cff689bbb338 (patch) | |
tree | 0d07b39dbcf794c9fe1174aeb6fb4923df2fd9b7 /dhall/src | |
parent | ea08d2528d2ee46446ac8981e72af5c610e43ce1 (diff) |
Improve import handling in parser
Diffstat (limited to '')
-rw-r--r-- | dhall/src/binary.rs | 15 | ||||
-rw-r--r-- | dhall/src/imports.rs | 9 | ||||
-rw-r--r-- | dhall/src/lib.rs | 11 |
3 files changed, 34 insertions, 1 deletions
diff --git a/dhall/src/binary.rs b/dhall/src/binary.rs index 8c5b902..1fa075e 100644 --- a/dhall/src/binary.rs +++ b/dhall/src/binary.rs @@ -1,6 +1,7 @@ use dhall_core::*; use itertools::*; use serde_cbor::value::value as cbor; +use std::path::PathBuf; use std::rc::Rc; type ParsedExpr = Rc<Expr<X, Import>>; @@ -175,6 +176,20 @@ fn cbor_value_to_dhall(data: &cbor::Value) -> Result<ParsedExpr, DecodeError> { .collect::<Result<_, _>>()?, ))) } + [U64(24), Null, U64(0), U64(3), rest..] => { + let mut path = PathBuf::new(); + for s in rest { + match s { + String(s) => path.push(s), + _ => Err(DecodeError::WrongFormatError)?, + } + } + Embed(Import { + mode: ImportMode::Code, + hash: None, + location: ImportLocation::Local(FilePrefix::Here, path), + }) + } [U64(25), bindings..] => { let mut tuples = bindings.iter().tuples(); let bindings = (&mut tuples) diff --git a/dhall/src/imports.rs b/dhall/src/imports.rs index 2435663..9f60ee7 100644 --- a/dhall/src/imports.rs +++ b/dhall/src/imports.rs @@ -84,3 +84,12 @@ pub fn load_dhall_file( }; Ok(expr) } + +pub fn load_dhall_file_no_resolve_imports( + f: &Path, +) -> Result<ParsedExpr, DhallError> { + let mut buffer = String::new(); + File::open(f)?.read_to_string(&mut buffer)?; + let expr = parse_expr(&*buffer)?; + Ok(expr) +} diff --git a/dhall/src/lib.rs b/dhall/src/lib.rs index d8ca955..dcc1ff3 100644 --- a/dhall/src/lib.rs +++ b/dhall/src/lib.rs @@ -10,7 +10,16 @@ mod normalize; pub use crate::normalize::*; pub mod binary; +pub mod dhall_type; pub mod imports; pub mod typecheck; -pub use crate::imports::{load_dhall_file, DhallError}; +pub use crate::imports::*; + +pub struct DhallExpr(dhall_core::DhallExpr); + +impl DhallExpr { + pub fn normalize(self) -> Self { + DhallExpr(crate::normalize::normalize(self.0)) + } +} |