tramlines_core/lib.rs
1//! tramlines-core: the part of tramlines that every format of document
2//! shares.
3//!
4//! The core grammar, the vocabulary a schema is written in, and the
5//! layers a format grammar and a host extension add to it; the shapes,
6//! types and formats a rule matches text with; the frontmatter and the
7//! lifecycle of a document; and the [`Finding`] a failure is reported as.
8//! A format crate, such as tramlines-md, adds what its documents hold.
9//!
10//! A host program uses a format crate, which re-exports what it needs from
11//! here. This crate alone reads a formats file and matches lines against
12//! its formats:
13//!
14//! ```
15//! use tramlines_core::grammar::{FormatMatch, FormatRegistry, RegexCache, load_core_grammar};
16//!
17//! let grammar = load_core_grammar()?;
18//! let formats = "registry:\n item:\n template: '${name:word} x${n:int}'\n example: Milk x2\n";
19//! let registry = FormatRegistry::from_text(formats, &[], &grammar, &RegexCache::new())?;
20//! let item = registry.get("item").expect("the file defines `item`");
21//! assert!(matches!(item.check("Bread x1"), FormatMatch::Ok(_)));
22//! assert!(matches!(item.check("Bread"), FormatMatch::Fail(_)));
23//! # Ok::<(), tramlines_core::Error>(())
24//! ```
25
26#![warn(missing_docs)]
27
28mod error;
29mod finding;
30pub mod frontmatter;
31pub mod grammar;
32mod path;
33pub mod text;
34pub mod yaml;
35
36pub use error::{Error, Result};
37pub use finding::{Finding, Locator, Problem, Severity};
38pub use path::{RepoPath, RepoRoot};
39pub use yaml::{Spanned, Yaml, YamlError};