Change unparse to work with IndentWriter.

This commit is contained in:
Jesse Brault 2025-05-16 08:05:59 -05:00
parent ce20cece21
commit 2b4e042602
2 changed files with 456 additions and 399 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,9 @@
use std::path::PathBuf;
use pest::Parser;
use deimos::ast::build::build_ast;
use deimos::ast::unparse::Unparse;
use deimos::parser::{DeimosParser, Rule};
use deimos::util::indent_writer::IndentWriter;
use pest::Parser;
use std::path::PathBuf;
pub fn unparse(path: &PathBuf) {
let src = std::fs::read_to_string(path).expect(&format!("Could not read {:?}", path));
@ -11,10 +12,11 @@ pub fn unparse(path: &PathBuf) {
Ok(mut pairs) => {
let compilation_unit_pair = pairs.next().unwrap();
let compilation_unit = build_ast(compilation_unit_pair);
let mut out = String::new();
compilation_unit.unparse(&mut out).expect("Failed to write to string.");
println!("{}", out);
},
let mut writer = IndentWriter::new(0, " ", Box::new(std::io::stdout()));
compilation_unit
.unparse(&mut writer)
.expect("Failed to write to string.");
}
Err(e) => {
eprintln!("{}", e);
}