Expand description
dmog (data mogrify) as a library: what the dmog command does, for a
program to call.
- Translation.
translate()writes a document of any formatformats()lists in any other, as it reads it:Translationcompiles the route once, for many documents, andTranslateOptionsholds what the command’s options say. - The formats.
formats()lists them as values, andformats_jsonasdmog formatsprints them;parsed_formatsnames those whose documents a program can read as their parse. - Programs.
Programcompiles an alchemy program and runs it over a document, asdmog rundoes;canon,format(),check,explainandexplain_jsonanswer 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");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::abortmakes every run given it (run_with_abort) fail withCode::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.
- Format
Info - 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.
- Program
Options - 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.
- Translate
Options - What a translation reads and writes, as
dmog translate’s options say it. - Translation
- A translation compiled once, to run over many documents.
Enums§
Functions§
- canon
- The program in canonical form, as
dmog canonprints it. - check
- Whether the program reads, desugars, resolves and checks, and builds
its plan, as
dmog checkasks 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 explainprints it. - explain_
json explain’s report as one JSON object.- format
- The program in layout form, as
dmog formatprints it. - formats
- Every format, by id.
- formats_
json formatsas the JSON arraydmog formatsprints, without its final line feed.- parsed_
formats - The ids of the formats whose documents are parsed, in the order
formatslists them: the formats a program’sgrammartakes, asdmog run --grammardoes. A format whose documents are read only as the tree its package makes of them, such as expr, is not among them, whichFormatInfodoes not say. - translate
- Translate what
inputgives intooutput, asTranslation::rundoes. - translate_
str - The translation of
input, asTranslation::run_stranswers it.