Expand description
Lossless, error-tolerant TOML parsing, validation, semantics, highlighting, and formatting.
Document is the main entry point. It owns an immutable source snapshot and all products
derived from that snapshot. Choose the TOML language version explicitly in reusable tools;
Document::parse is a convenience that currently selects TOML 1.1.
use tomlsmith::{Document, FormatOutcome, TomlVersion};
let document = Document::parse_as("name=\"TomlSmith\"\n", TomlVersion::V1_1);
assert!(document.diagnostics().is_empty());
assert_eq!(document.semantics().declarations().len(), 1);
match document.format() {
FormatOutcome::Changed { text, .. } => assert_eq!(&*text, "name = \"TomlSmith\"\n"),
outcome => panic!("expected a formatting change, got {outcome:?}"),
}Formatting is guarded: snapshots with parse, version, or semantic errors produce
FormatOutcome::Refused instead of rewritten text. Syntax handles are snapshot-scoped and
expose TomlSmith’s own SyntaxKind rather than the private tree implementation.
Structs§
- Date
Time Value - A validated TOML date/time retaining source spelling and protocol-normalized spelling.
- Declaration
- One source declaration retained even when its key is ambiguous or conflicting.
- Diagnostic
- A parser, version, or semantic finding tied to a UTF-8 byte range.
- Diagnostic
Code - A stable machine-readable diagnostic identifier.
- Document
- An immutable TOML source snapshot and its derived syntax, semantics, diagnostics, and spans.
- Format
Options - Layout and language-version settings for guarded formatting.
- Highlight
- A semantic highlight category attached to a UTF-8 source byte range.
- KeyPath
- A decoded sequence of TOML key segments.
- Revision
- A monotonically increasing identifier for snapshots derived through
Document::with_changes. - Semantic
Document - The declaration-preserving semantic view of a parsed snapshot.
- Semantic
Table - An insertion-ordered map of decoded table entries.
- Syntax
Node - A snapshot-scoped lossless syntax node.
- Syntax
Token - A snapshot-scoped lossless source token.
- Text
Edit - A replacement over the original snapshot’s UTF-8 byte offsets.
- Text
Range - A UTF-8 byte range in a TOML document.
Enums§
- Change
Error - Why a source update could not produce a new snapshot.
- Date
Time Kind - A TOML date/time value category.
- Declaration
Kind - The source statement that introduced a declaration.
- Format
Outcome - The result of guarded full-document formatting.
- Highlight
Kind - A source-level semantic classification suitable for editor highlighting.
- Line
Ending - How formatted output chooses newline bytes.
- Resolution
- The result of resolving one fully qualified decoded key path.
- Semantic
Value - A decoded TOML value or an error-tolerant invalid placeholder.
- Severity
- The impact of a diagnostic on document validity.
- Syntax
Element - Either a child syntax node or a child source token.
- Syntax
Kind - A lossless syntax node or token category.
- Text
Change - A source update applied to an immutable
Documentsnapshot. - Toml
Version - The published TOML language specification used to parse and validate a snapshot.