TOML module for Guile
Go to file
hylo bed74c5c1a fix: export scm->toml 2022-12-30 18:11:03 +01:00
test feat(encoder): float 2022-12-30 17:53:13 +01:00
toml fix(encoder): build empty inline tree 2022-12-30 17:53:13 +01:00
README.org docs: update readme 2022-12-30 17:53:13 +01:00
decoder.scm docs: update readme 2022-12-30 17:53:13 +01:00
toml.scm fix: export scm->toml 2022-12-30 18:11:03 +01:00

README.org

Readme

guile-toml

TOML for Guile. v1.0 compliant. (TODO: encoder)

Installation

For now: add this folder to GUILE_LOAD_PATH

Usage

When parsing and building TOML documents, guile-toml follows guile-json as close as possible. TOML types correspon to Guile types according to the following table:

TOML Guile
string string [0]
key-value pair alist
array vector
integer/float real
true #t
false #f
datetime SRFI-19 date [1]
nan +nan.0
±inf ±inf.0

To start using guile-toml: (use-modules (toml))

[0]: TOML's default behaviour for invalid UTF-8 is to fail, whereas Guile's default behavior is to replace invalid UTF-8 with <20>. If you prefer TOML's behavior, use (set-port-conversion-strategy! (current-input-port) 'error).

[1]: TOML's time-local is parsed same as a datetime-local on the date of 1970-01-01.

Reading TOML documents

  • (toml->scm str) Reads a TOML document from the given string.

Building TOML documents

  • (scm->toml native #:optional port) Not implemented yet.

Examples

  • Basic toml->scm usage:
> (toml->scm "[a]\n b.c = \"hi world\"")
(("a" ("b" ("c" . "hi world"))))
  • Read a TOML file and parse it (example from toml.io):

    > (use-modules (toml) (ice-9 textual-ports))
    > (toml->scm (call-with-input-file "example.toml" get-string-all))
    
    (("servers"
     ("beta" ("role" . "backend") ("ip" . "10.0.0.2"))
     ("alpha"
      ("role" . "frontend")
      ("ip" . "10.0.0.1")))
    ("database"
     ("temp_targets" ("case" . 72.0) ("cpu" . 79.5))
     ("data" . #(#("delta" "phi") #(3.14)))
     ("ports" . #(8000 8001 8002))
     ("enabled" . #t))
    ("owner"
     ("dob"
      .
      #<date nanosecond: 0 second: 0 minute: 32 hour: 7 day: 27 month: 5 year: 1979 zone-offset: -28800>)
     ("name" . "Tom Preston-Werner"))
    ("title" . "TOML Example"))