blob: d5cb9f55708f7f97c62d53e7cada61037de7db3e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
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<Parsed, Error> {
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<Parsed, Error> {
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<Parsed, Error> {
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))
}
|