Skip to main content

flm_core/dump/
mod.rs

1//! Tools for inspecting and testing what the library holds in memory: parsed
2//! and processed trees, computed tables, and diagnostics.
3//!
4//! The library's own tests, the tests of a program or extension crate built on
5//! it, and the `flm dump` command of the `flm` program all use this module. It
6//! is ordinary public interface rather than test-only code: no cargo feature
7//! switches it on, so a program writes its test fixtures against the same
8//! functions the library's tests use.
9//!
10//! The module renders what the library holds in two different forms, and keeps
11//! them apart:
12//!
13//! - **The projection** ([`project`]) is a one-way rendering of a tree, a node,
14//!   a [table](crate::core::data::table::Table) or a
15//!   [diagnostic](crate::guide::concepts_overview#diagnostics) as a techy
16//!   serialized value ([`SerialValue`](crate::techy::serialize::SerialValue),
17//!   techy's format-independent data model),
18//!   in a vocabulary this library owns and keeps stable (`elem`, `chars`,
19//!   `args`, `children`, and so on; spans as `line:col` on request). It is what
20//!   tests compare and what `flm dump --view compact` prints. It never shows a
21//!   parsing state, and it cannot be read back into a tree.
22//! - **The wire form** ([`session`]) is techy's serialization of a parse, which
23//!   [`crate::lang::serialize`] implements for FLM. It is lossless and verbose,
24//!   and it can be read back into in-memory objects with their sharing and
25//!   identity intact. `flm dump --view wire` prints it as JSON, one segment
26//!   (the unit of output a session emits) per line ([`json::segment_line`]).
27//!
28//! A program that writes such data as JSON opens its output with a header,
29//! [`Meta`]: the kind of output, the version of FLM that wrote it, and the
30//! version of the kind's format.
31//!
32//! # Map
33//!
34//! - [`project`] — the projection: [`Projector`], [`ProjectOptions`], the
35//!   free functions [`project_tree`], [`project_node`], [`project_diagnostics`]
36//!   and the others, and [`TableProjection`], through which every table
37//!   projects itself.
38//! - [`golden`] — golden files: a test's expected output kept in a file,
39//!   compared with [`assert_text_golden`] or [`assert_json_golden`] and
40//!   rewritten when the environment variable [`UPDATE_GOLDEN`] is `1`.
41//! - [`diag`] — assertions on diagnostics by identifier and data, never by
42//!   message: [`expect`], [`expect_none`] and the narrowing steps of
43//!   [`DiagExpect`].
44//! - [`json`] — the JSON text of serialized values and of wire segments:
45//!   [`to_json`], [`to_json_pretty`], [`from_json`], [`from_serde`],
46//!   [`segment_line`], [`segment_from_line`].
47//! - [`meta`] — the header that opens a JSON output written about FLM (its
48//!   kind, the version of FLM that wrote it, the version of its format):
49//!   [`Meta`].
50//! - [`session`] — the serialization sessions over a built language
51//!   ([`writer`], [`reader`], [`reader_with`]) and the reading and writing of
52//!   fragments and trees through them ([`write_fragment`], [`read_fragment`],
53//!   [`write_tree`], [`read_tree`]).
54//!
55//! Every public item of the submodules is re-exported here.
56//!
57//! [`golden`] is the only part of `flm-core` that reads or writes files; no
58//! stage, rule or entry point of the processing touches the file system.
59
60pub mod diag;
61pub mod golden;
62pub mod json;
63pub mod meta;
64pub mod project;
65pub mod session;
66
67pub use diag::{DiagExpect, ExpectDiag, expect, expect_none};
68pub use golden::{
69    GoldenError, GoldenMode, UPDATE_GOLDEN, assert_json_golden, assert_text_golden,
70    check_json_golden, check_text_golden,
71};
72pub use json::{
73    JsonError, from_json, from_serde, segment_from_line, segment_line, to_json, to_json_pretty,
74};
75pub use meta::Meta;
76pub use project::{
77    ProjectOptions, Projector, TableProjection, TreeSource, node_ref_value, project_diagnostic,
78    project_diagnostics, project_node, project_nodes, project_payload, project_table,
79    project_tree, tree_ref_value,
80};
81pub use session::{
82    AmbiguousElement, ElementResolver, ElementTable, FALLBACK_GATE_IDENTIFIER, FRAGMENT_IDENTIFIER,
83    FRAGMENTS_TABLE, FragmentIndex, FragmentSerdeDriver, PRESENTATION_IDENTIFIER, PayloadReader,
84    PayloadReaders, ReadEnvironment, SYNTHESIZED_IDENTIFIER, WriteEnvironment, fragments_table,
85    known_providers, read_fragment, read_tree, reader, reader_with, register, write_fragment,
86    write_tree, writer,
87};