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:

See CRYSTAL-TOML-SPECS.adoc (sibling repo prod-crystal/) for the full specification.

Defined in:

toml.cr
toml/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

Class Method Detail

def self.parse(source : String) : Document #

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.


[View source]
def self.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. Drop-in replacement for the crystal-community/TOML.cr API.

Raises TOML::ParseError on invalid input or duplicate keys.


[View source]