My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/apps/koffice/libko/src/cass/format/gen.rs

32 lines
1.1 KiB

//! Cassiopeia line generator
//!
//! This module takes a set of IR lines, and generates strings from
//! them that are in accordance with the way that the parser of the
//! same version expects them.
use crate::cass::format::ir::{IrItem, IrType};
/// Take a line of IR and generate a string to print into a file
pub(crate) fn line(ir: &IrItem) -> String {
let IrItem { tt, lo } = ir;
match tt {
IrType::Ignore => "".into(),
IrType::Header(map) => format!(
"HEADER {}",
map.iter()
.map(|(k, v)| format!("{}={},", k, v))
.collect::<Vec<_>>()
.join("")
),
IrType::Start(time) => format!("START {}", time.to_string()),
// FIXME: find a better way to align the lines here rather
// than having to manually having to pad the 'STOP' commands
IrType::Stop(time) => format!("STOP {}", time.to_string()),
IrType::Invoice(date) => format!("INVOICE {}", date.to_string()),
}
}
pub(crate) fn head_comment() -> String {
";; generated by cassiopeia, be careful about editing by hand!".into()
}