TOML
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.
Constants
TOML specification version implemented by this shard.
Lue au compile-time depuis shard.yml via le macro read_file.
Cf. note mémoire feedback_shard_version_macro.md (mémoire ALOLI).
Class methods
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.
Nested types
- TOML::ArrayOfTablesLine
- TOML::ArrayValue
- TOML::BlankLine
- TOML::BooleanValue
- TOML::CommentLine
- TOML::Document
- TOML::FloatValue
- TOML::HashBuilder
- TOML::InlineTableValue
- TOML::IntegerValue
- TOML::Key
- TOML::KeyPart
- TOML::KeyValueLine
- TOML::Lexer
- TOML::LocalDateTimeValue
- TOML::LocalDateValue
- TOML::LocalTimeValue
- TOML::Node
- TOML::OffsetDateTimeValue
- TOML::ParseError
- TOML::Parser
- TOML::StringValue
- TOML::TableHeaderLine
- TOML::TestFormat
- TOML::Token
- TOML::TokenKind
- TOML::Type
- TOML::Value
- TOML::ValueDecoder