use std::fs::File; use std::io::Read; use std::path::Path; use dhall_syntax::parse_expr; use crate::error::Error; use crate::phase::resolve::ImportRoot; use crate::phase::Parsed; pub(crate) fn parse_file(f: &Path) -> Result { let mut buffer = String::new(); File::open(f)?.read_to_string(&mut buffer)?; let expr = parse_expr(&*buffer)?; let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned()); Ok(Parsed(expr, root)) } pub(crate) fn parse_str(s: &str) -> Result { let expr = parse_expr(s)?; let root = ImportRoot::LocalDir(std::env::current_dir()?); Ok(Parsed(expr, root)) } pub(crate) fn parse_binary_file(f: &Path) -> Result { let mut buffer = Vec::new(); File::open(f)?.read_to_end(&mut buffer)?; let expr = crate::phase::binary::decode(&buffer)?; let root = ImportRoot::LocalDir(f.parent().unwrap().to_owned()); Ok(Parsed(expr.note_absurd(), root)) } #[cfg(test)] mod spec_tests { #![rustfmt::skip] // See build.rs include!(concat!(env!("OUT_DIR"), "/parser_tests.rs")); }