module TOML
Overview
TOML v1.0 parser and serializer for Crystal, with comment-and-format preservation across parse → modify → write round-trips.
Two entry points are exposed:
-
TOML.parse_to_hash(string)— drop-in replacement for thecrystal-community/TOML.crAPI. Returns a plainHash, fast, loses every comment and the original formatting. Use this when you only ever read. -
TOML.parse(string)— returns aTOML::DocumentAST that preserves comments, blank lines, and the original byte-level formatting. Use this when you need to modify a TOML file in place and re-serialize it without diffing the whole document.
See CRYSTAL-TOML-SPECS.adoc (sibling repo prod-crystal/) for
the full specification.
Defined in:
toml.crtoml/edit.cr
toml/hash_builder.cr
toml/key.cr
toml/lexer.cr
toml/lookup.cr
toml/node.cr
toml/parse_error.cr
toml/parser.cr
toml/test_format.cr
toml/token.cr
toml/value.cr
toml/value_decoder.cr
toml/version.cr
Constant Summary
-
SPEC_VERSION =
"1.0.0" -
TOML specification version implemented by this shard.
-
VERSION =
"0.1.0"
Class Method Summary
-
.parse(source : String) : Document
Parses a TOML v1.0 document into a
DocumentAST. -
.parse_to_hash(source : String) : Hash(String, Type)
Parses a TOML v1.0 document and returns a plain
Hash(String, TOML::Type), dropping comments and the original formatting.
Class Method Detail
Parses a TOML v1.0 document into a Document AST. The
returned document preserves comments, blank lines, key order
and the original byte-level formatting, so a round-trip
TOML.parse(s).to_toml == s for any unmodified s.
The parse runs a second semantic-validation pass after the
syntactic one (duplicate keys, table redefinitions, etc.); if
you want to skip that — e.g. to inspect a malformed AST during
debugging — use Parser.new(source).parse directly.
Raises TOML::ParseError on invalid input.
Parses a TOML v1.0 document and returns a plain
Hash(String, TOML::Type), dropping comments and the original
formatting. Drop-in replacement for the
crystal-community/TOML.cr API.
Raises TOML::ParseError on invalid input or duplicate keys.