planus_translation/
lib.rs1#[macro_use]
9extern crate lalrpop_util;
10
11mod ast_convert;
12mod intermediate_language;
13
14mod ctx;
15mod error;
16mod parser;
17mod pretty_print;
18mod util;
19
20use std::path::Path;
21
22pub use ast_convert::ConverterOptions;
23pub use error::ErrorKind;
24pub use intermediate_language::{translate_files, translate_files_with_options};
25
26pub fn format_file(path: &impl AsRef<Path>, ignore_errors: bool) -> Option<String> {
27 let mut ctx = ctx::Ctx::default();
28 let file_id = ctx.add_file(path, []).unwrap();
29 if let Some(parsed) = ctx.parse_file(file_id) {
30 if ctx.has_errors() && !ignore_errors {
31 None
32 } else {
33 let mut s = String::new();
34 if pretty_print::pretty_print(ctx.get_source(file_id), &parsed, &mut s).is_ok() {
35 Some(s)
36 } else {
37 None
38 }
39 }
40 } else {
41 None
42 }
43}