use oak_core::source::{SourceBuffer, ToSource};
#[cfg(feature = "oak-pretty-print")]
use oak_pretty_print::{Document, PrinterConfig};
#[cfg(feature = "oak-pretty-print")]
use oak_pretty_print::to_doc::AsDocument;
use crate::ast::JasmRoot;
pub struct JasmFormatter {
indent_size: usize,
}
impl JasmFormatter {
pub fn new() -> Self {
Self { indent_size: 4 }
}
pub fn format(&self, root: &JasmRoot) -> String {
let mut buffer = SourceBuffer::new();
root.to_source(&mut buffer);
buffer.to_string()
}
#[cfg(feature = "oak-pretty-print")]
pub fn format_pretty(&self, root: &JasmRoot) -> String {
let doc = root.as_document(&Default::default());
doc.render()
}
#[cfg(not(feature = "oak-pretty-print"))]
pub fn format_pretty(&self, root: &JasmRoot) -> String {
self.format(root)
}
}
impl Default for JasmFormatter {
fn default() -> Self {
Self::new()
}
}