Skip to main content

Crate tomlsmith

Crate tomlsmith 

Source
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§

DateTimeValue
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.
DiagnosticCode
A stable machine-readable diagnostic identifier.
Document
An immutable TOML source snapshot and its derived syntax, semantics, diagnostics, and spans.
FormatOptions
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.
SemanticDocument
The declaration-preserving semantic view of a parsed snapshot.
SemanticTable
An insertion-ordered map of decoded table entries.
SyntaxNode
A snapshot-scoped lossless syntax node.
SyntaxToken
A snapshot-scoped lossless source token.
TextEdit
A replacement over the original snapshot’s UTF-8 byte offsets.
TextRange
A UTF-8 byte range in a TOML document.

Enums§

ChangeError
Why a source update could not produce a new snapshot.
DateTimeKind
A TOML date/time value category.
DeclarationKind
The source statement that introduced a declaration.
FormatOutcome
The result of guarded full-document formatting.
HighlightKind
A source-level semantic classification suitable for editor highlighting.
LineEnding
How formatted output chooses newline bytes.
Resolution
The result of resolving one fully qualified decoded key path.
SemanticValue
A decoded TOML value or an error-tolerant invalid placeholder.
Severity
The impact of a diagnostic on document validity.
SyntaxElement
Either a child syntax node or a child source token.
SyntaxKind
A lossless syntax node or token category.
TextChange
A source update applied to an immutable Document snapshot.
TomlVersion
The published TOML language specification used to parse and validate a snapshot.