Documentation
¶
Overview ¶
Package toml is a pure-Go (CGO-free) TOML v1.0.0 parser and generator for the Ruby value model, faithful to the toml-rb gem's semantics. Parse turns a TOML document into a Ruby Hash (an insertion-ordered *Map); Dump renders such a value back to a TOML string, so it is the deterministic, interpreter-independent core of toml-rb's TomlRB.parse / TomlRB.dump — without any Ruby runtime.
Ruby value model ¶
A parsed document is an [any] drawn from a small, fixed set of Go types so a host (such as go-embedded-ruby) can map its own object graph to and from this package:
TOML Go (Parse returns) Ruby (rbgo maps to) ---- ------------------ ------------------- string string String integer int64 Integer float / inf / nan float64 Float boolean bool true / false array []any Array table / inline table *Map (insertion order) Hash offset date-time OffsetDateTime Time local date-time LocalDateTime Time local date LocalDate Time (00:00, local) local time LocalTime Time (1970-01-01, local)
toml-rb collapses every TOML date/time onto Ruby's Time using the host's local zone for the offset-less variants; this package keeps the faithful TOML datetime model (an explicit local/offset distinction with no host-zone guessing) so the host applies its own zone exactly once when it materialises a Ruby Time. Dump accepts these shapes plus Go's time.Time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LocalDate ¶
type LocalDate struct {
Year, Month, Day int
}
LocalDate is a TOML local date (`YYYY-MM-DD`).
type LocalDateTime ¶
LocalDateTime is a TOML local date-time (RFC 3339 with no offset). The fields are wall-clock components with no zone; the host supplies the zone when it maps the value to a Ruby Time.
func (LocalDateTime) String ¶
func (d LocalDateTime) String() string
String renders a LocalDateTime in RFC 3339 (no offset).
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is an insertion-ordered Ruby Hash. Parse returns tables and inline tables as *Map so key order round-trips; Dump accepts *Map or a plain Go map (emitted in sorted key order for determinism).
func LoadFile ¶
LoadFile reads path and parses it as a TOML document, matching TomlRB.load_file / TOML.load_file.
func Parse ¶
Parse parses a TOML v1.0.0 document into a Ruby Hash (an insertion-ordered *Map), matching TomlRB.parse / TOML.parse. A syntax error returns a *ParseError; a duplicate key returns a *OverwriteError.
type OffsetDateTime ¶
OffsetDateTime is a TOML offset date-time (RFC 3339 with a `Z` or `±hh:mm` suffix). It is a thin alias over time.Time, which already carries the offset.
type OverwriteError ¶
type OverwriteError struct {
Key string
}
OverwriteError reports a key defined more than once — the condition toml-rb raises as TomlRB::ValueOverwriteError. Key is the offending key path component.
func (*OverwriteError) Error ¶
func (e *OverwriteError) Error() string
Error renders the toml-rb message verbatim.
type ParseError ¶
ParseError reports a TOML syntax error. Line and Col are 1-based positions of the offending byte; Offset is its 0-based index in the document.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
Error renders the message with its source position, mirroring the location detail TomlRB::ParseError carries.
