module TOML

Overview

The TOML module allows parsing TOML documents through the usage of the tomlc99 C library

Parsing with TOML.parse

TOML.parse will return an Any, which is a convenient wrapper around all possible TOML types, making it easy to traverse a complex TOML structure but requires some casts from time to time, mostly via some method invocations.

require "ctoml-cr"

value = TOML.parse("x=[1, 2, 3]") # : TOML::Any

value[0]              # => 1
typeof(value[0])      # => TOML::Any
value[0].as_i         # => 1
typeof(value[0].as_i) # => Int32

value[0] + 1      # Error, because value[0] is TOML::Any
value[0].as_i + 1 # => 2

Documentation is an edited version of the JSON module from Crystal

Extended Modules

Defined in:

any.cr
ctoml-cr.cr
toml-test-json.cr

Constant Summary

PlaceholderLocation = Time::Location.new("None", zones: [PlaceholderZone])

When a timezone isn't explicitly specified this placeholder location is used

PlaceholderZone = Time::Location::Zone.new("None", 0, false)

Class Method Summary

Instance Method Summary

Class Method Detail

def self.parse(data : String) #

Parse a TOML document as a TOML::Any.


[View source]

Instance Method Detail

def build_test_json(toml_dict : Hash(String, TOML::Any)) #

[View source]