diff options
author | Mx Kookie <kookie@spacekookie.de> | 2020-12-15 19:41:48 +0000 |
---|---|---|
committer | Mx Kookie <kookie@spacekookie.de> | 2020-12-15 19:41:48 +0000 |
commit | d7fff0b83e0bc931e29a3e64c1f978a09a3fd429 (patch) | |
tree | 6328b2700e74fae191967391c9f8f6b054c36c1a /apps/cassiopeia/src/format/gen.rs | |
parent | bfe67afa8a9238bd2a3bfdc9079917c81c8cfef3 (diff) |
cassiopeia: finishing up version 0.3.0
This commit does kind of a lot to get cass(1) over the finish line.
For one it implements all the CLI functions (well, almost all) with
their respective parameters, and also creates a new `gen` module which
uses the IR stream to generate a new file based on the old one, while
updating header fields that need to be updated (currently only
`version`).
This version does nothing with the actual header values, and probably
has a lot of bugs. More documentation will follow in future
cassiopeia commits.
Diffstat (limited to 'apps/cassiopeia/src/format/gen.rs')
-rw-r--r-- | apps/cassiopeia/src/format/gen.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/cassiopeia/src/format/gen.rs b/apps/cassiopeia/src/format/gen.rs new file mode 100644 index 000000000000..2bcd6cc724fd --- /dev/null +++ b/apps/cassiopeia/src/format/gen.rs @@ -0,0 +1,33 @@ +//! 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::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() +} + |