Change unparse to work with IndentWriter.
This commit is contained in:
parent
ce20cece21
commit
2b4e042602
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,9 @@
|
|||||||
use std::path::PathBuf;
|
|
||||||
use pest::Parser;
|
|
||||||
use deimos::ast::build::build_ast;
|
use deimos::ast::build::build_ast;
|
||||||
use deimos::ast::unparse::Unparse;
|
use deimos::ast::unparse::Unparse;
|
||||||
use deimos::parser::{DeimosParser, Rule};
|
use deimos::parser::{DeimosParser, Rule};
|
||||||
|
use deimos::util::indent_writer::IndentWriter;
|
||||||
|
use pest::Parser;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn unparse(path: &PathBuf) {
|
pub fn unparse(path: &PathBuf) {
|
||||||
let src = std::fs::read_to_string(path).expect(&format!("Could not read {:?}", path));
|
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) => {
|
Ok(mut pairs) => {
|
||||||
let compilation_unit_pair = pairs.next().unwrap();
|
let compilation_unit_pair = pairs.next().unwrap();
|
||||||
let compilation_unit = build_ast(compilation_unit_pair);
|
let compilation_unit = build_ast(compilation_unit_pair);
|
||||||
let mut out = String::new();
|
let mut writer = IndentWriter::new(0, " ", Box::new(std::io::stdout()));
|
||||||
compilation_unit.unparse(&mut out).expect("Failed to write to string.");
|
compilation_unit
|
||||||
println!("{}", out);
|
.unparse(&mut writer)
|
||||||
},
|
.expect("Failed to write to string.");
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user