ingraph-codegen 0.1.0

The emission engine behind ingraph-derive: a plain declaration model in, the ingraph framework faces out.
Documentation
//! The duration grammar at EXPANSION time — `every = "10m"` read into the value the emission
//! spells.
//!
//! # ONE grammar, two crates, and why the copy is here rather than borrowed
//!
//! The user's ruling on the duration word is that both sides speak ONE grammar: the runtime filter's
//! `DurationFilter::parse_operand` and this expansion-time reader accept exactly the same strings
//! and answer with exactly the same values. `ingraph` cannot lend this crate its copy — `ingraph`
//! expands THROUGH the derive, which is built on this crate, so the edge would run the wrong way —
//! so the table is copied and PINNED: `ingraph-derive`'s `duration_parity` suite reads both files
//! and refuses a byte of drift below the first constant, then reads one corpus through both entries
//! and refuses a difference in either the value or the acceptance.
//!
//! # The two grammars inside the one
//!
//! [`jiff::SignedDuration`]'s own `FromStr` runs first — ISO 8601 (`PT1H30M30S`), jiff's friendly
//! form (`1h 30m 30s`), a leading sign on either — and only its refusal reaches [`wide`], the
//! normalization table that answers the four CALENDAR units jiff declines for this type. jiff first
//! settles the overlap (its reading wins every string it accepts) and settles the ERROR (a string
//! neither grammar takes reports jiff's refusal, which names the unit it found and where).
//!
//! **The month and the year are fixed averages** — 30.44 and 365.25 days — kept as a documented
//! convenience by the user's own word on the months exception, and not calendar arithmetic. `1M` is
//! a MONTH and `1m` is a minute.

use jiff::SignedDuration;

mod wide;

/// One duration from text, in the grammar both crates speak.
///
/// The expansion-time twin of `ingraph`'s `DurationFilter::parse_operand`, character for character
/// in what it accepts and in what it answers — see the module note for the pin that keeps it so.
///
/// # Errors
///
/// jiff's own refusal, which names the unit it found and where. The wide table makes no message of
/// its own: the caller already holds one that is more specific, and a second would only have to be
/// chosen between. A value the grammar reads but `SignedDuration` cannot hold — `292471208677y` —
/// refuses at the CROSSING instead, since *the grammar was fine and the value does not fit* is the
/// more useful answer.
pub fn parse(text: &str) -> Result<SignedDuration, jiff::Error> {
  match text.parse() {
    Ok(operand) => Ok(operand),
    Err(refusal) => match wide::parse(text) {
      Some(wide) => SignedDuration::try_from(wide),
      None => Err(refusal),
    },
  }
}

#[cfg(test)]
mod tests;