1#![feature(new_range_api)]
2#![warn(missing_docs)]
3pub mod building;
11pub mod lexing;
13pub mod parsing;
15
16use oak_core::{errors::OakError, source::SourceText};
17use std::{fs::File, path::Path};
18
19pub fn source_from_path(path: &Path) -> Result<SourceText, OakError> {
21 match std::fs::read_to_string(path) {
22 Ok(o) => Ok(SourceText::new(o)),
23 Err(e) => Err(OakError::io_error(e, 0)),
24 }
25}
26
27pub fn json_from_path(path: &Path) -> Result<serde_json::Value, OakError> {
29 let content = std::fs::read_to_string(path).map_err(|e| OakError::io_error(e, 0))?;
30 serde_json::from_str(&content).map_err(|e| OakError::custom_error(e.to_string()))
31}
32
33pub fn open_file(path: &Path) -> Result<File, OakError> {
35 match File::open(path) {
36 Ok(o) => Ok(o),
37 Err(e) => Err(OakError::io_error(e, 0)),
38 }
39}
40
41pub fn create_file(path: &Path) -> Result<std::fs::File, OakError> {
43 if let Some(parent) = path.parent() {
44 std::fs::create_dir_all(parent).map_err(|e| OakError::custom_error(e.to_string()))?
45 }
46 std::fs::File::create(path).map_err(|e| OakError::custom_error(e.to_string()))
47}