Skip to main content

Crate tabnas_dmog

Crate tabnas_dmog 

Source
Expand description

dmog (data mogrify) as a library: what the dmog command does, for a program to call.

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");

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.

Structs§

Abort
A handle that stops a run: Abort::abort makes every run given it (run_with_abort) fail with Code::Aborted. A run checks it between parse steps and as its program’s functions run, and one given an aborted handle fails before it starts. Clones share one state, so a clone can be moved to the thread that decides to stop.
Fail
A failure: a code, and what is known about where and why.
FormatInfo
One format a translation reads and writes: one entry of dmog formats, as its package’s translation parts describe it.
Limits
Per-run limits. Every field is named in a failure as written here.
Program
A program compiled once, to run over many documents.
ProgramOptions
How a program is run, as dmog run’s options say it.
Source
A program’s text, and the name its failures cite it by.
TranslateOptions
What a translation reads and writes, as dmog translate’s options say it.
Translation
A translation compiled once, to run over many documents.

Enums§

Code
The stable failure codes.
Render
How a program’s table or JSON events are written.

Functions§

canon
The program in canonical form, as dmog canon prints it.
check
Whether the program reads, desugars, resolves and checks, and builds its plan, as dmog check asks it: the failure where it does not.
default_limits
The limits a run has when none are given: the command’s.
explain
The program’s plan report, as dmog explain prints it.
explain_json
explain’s report as one JSON object.
format
The program in layout form, as dmog format prints it.
formats
Every format, by id.
formats_json
formats as the JSON array dmog formats prints, without its final line feed.
parsed_formats
The ids of the formats whose documents are parsed, in the order formats lists them: the formats a program’s grammar takes, as dmog run --grammar does. A format whose documents are read only as the tree its package makes of them, such as expr, is not among them, which FormatInfo does not say.
translate
Translate what input gives into output, as Translation::run does.
translate_str
The translation of input, as Translation::run_str answers it.