Add python file builder

This commit is contained in:
a2x
2023-10-17 12:06:23 +10:00
parent c55bdf15a2
commit 0a86db6b40
86 changed files with 17670 additions and 436 deletions

View File

@@ -0,0 +1,43 @@
use std::io::{Result, Write};
use super::FileBuilder;
#[derive(Debug, PartialEq)]
pub struct PythonFileBuilder;
impl FileBuilder for PythonFileBuilder {
fn extension(&mut self) -> &str {
"py"
}
fn write_top_level(&mut self, _output: &mut dyn Write) -> Result<()> {
Ok(())
}
fn write_namespace(&mut self, output: &mut dyn Write, name: &str) -> Result<()> {
write!(output, "class {}:\n", name)?;
Ok(())
}
fn write_variable(
&mut self,
output: &mut dyn Write,
name: &str,
value: usize,
comment: Option<&str>,
) -> Result<()> {
match comment {
Some(comment) => write!(output, " {} = {:#X} # {}\n", name, value, comment),
None => write!(output, " {} = {:#X}\n", name, value),
}
}
fn write_closure(&mut self, output: &mut dyn Write, eof: bool) -> Result<()> {
if !eof {
write!(output, "\n")?;
}
Ok(())
}
}