tabnas-dmog 0.4.0

The dmog library and command (data mogrify): translates a document from any tabnas format into any other, streaming, and runs alchemy programs over JSON documents, composing tabnas-alchemy, tabnas-transduce and tabnas-render.
Documentation
//! dmog (data mogrify) as a library: what the `dmog` command does, for a
//! program to call.
//!
//! - **Translation.** [`translate()`] writes a document of any format
//!   [`formats()`] lists in any other, as it reads it: [`Translation`]
//!   compiles the route once, for many documents, and
//!   [`TranslateOptions`] holds what the command's options say.
//! - **The formats.** [`formats()`] lists them as values, and
//!   [`formats_json`] as `dmog formats` prints them; [`parsed_formats`]
//!   names those whose documents a program can read as their parse.
//! - **Programs.** [`Program`] compiles an alchemy program and runs it over
//!   a document, as `dmog run` does; [`canon`], [`format()`], [`check`],
//!   [`explain`] and [`explain_json`] answer what the commands of those
//!   names print.
//!
//! Input is a text, or a reader the run pulls from as it goes; output is a
//! text, or a writer the run writes to as it goes. Every failure is a
//! [`Fail`]: its [`Code`], its message, where it was found, and whether
//! output had already been written. The defaults are the command's:
//! [`default_limits`], the member a root is wrapped under, and the writer.
//!
//! A run compiles and evaluates on a thread of
//! [`tabnas_alchemy::STACK_BYTES`] that the library starts, so it may be
//! called from any thread. An [`Abort`] stops a run that is under way.
//!
//! ```
//! use tabnas_dmog::{translate_str, Program, ProgramOptions, Source, TranslateOptions};
//!
//! let json = translate_str("a: 1\nb: [x, y]\n", TranslateOptions::new("yaml", "json"))?;
//! assert_eq!(json, "{\"a\":1,\"b\":[\"x\",\"y\"]}\n");
//!
//! let names = Source::new(
//!     "names.alc",
//!     "def export [input]\n  pipe input\n    select (path each-index \"name\")\n    join \",\"\n",
//! );
//! let program = Program::new(names, ProgramOptions::default())?;
//! assert_eq!(program.run_str(r#"[{"name":"Ada"},{"name":"Alan"}]"#)?, "Ada,Alan");
//! # Ok::<(), tabnas_dmog::Fail>(())
//! ```
//!
//! The `dmog` command is this library's first user: `src/bin/dmog.rs`
//! parses the command line, opens the files, and turns a failure into its
//! exit status.

mod formats;
mod program;
mod stack;
mod translation;

#[doc(hidden)]
pub mod translate;

pub use formats::{formats, formats_json, parsed_formats, FormatInfo};
pub use program::{canon, check, explain, explain_json, format, Program, ProgramOptions, Render};
pub use stack::Abort;
pub use tabnas_alchemy::shared::{Code, Fail, Limits};
pub use translation::{translate, translate_str, TranslateOptions, Translation};

/// A program's text, and the name its failures cite it by.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Source {
    pub name: String,
    pub text: String,
}

impl Source {
    pub fn new(name: impl Into<String>, text: impl Into<String>) -> Source {
        Source {
            name: name.into(),
            text: text.into(),
        }
    }
}

/// The limits a run has when none are given: the command's.
pub fn default_limits() -> Limits {
    Limits::default()
}

/// The README's examples, which `cargo test --doc` runs.
#[cfg(doctest)]
#[doc = include_str!("../README.md")]
pub struct ReadmeDoctests;