[中文版本]
TOML in chez-scheme; v1.0.0 compliant (TOML v1.0.0 repository)
- Compliant with TOML v1.0.0.
- Parser: parse TOML text stream into scheme association list.
- Writer: parse toml-data in hashtable or alist form into TOML text stream.
- Convert toml association list to chez builtin object (hash-table, vector and date)
- Useful API for reference, set and display toml-data
(Chez Scheme (v9.5.8) is required)
chez-toml is a single-file library,
./src/toml.sls
is the source code,
./src/toml.so
is its compiled file.
Each of them is enough to use chez-toml.
By following steps, you can easily run the test case.
git clone https://github.com/Yunoinsky/chez-toml # clone this repository
cd chez-toml
scheme --script ./test/test.ss
By copying toml.sls
or toml.so
to the corresponding project, we can
use chez-toml in other projects.
You can also choose to install it globally.
Here is one way to do this.
- Create lib directory: ~~/Library/chezscheme/~.
- Copy
toml.so
ortoml.sls
to this directory. - append ~~/Library/chezscheme/~ to the environment variable
CHEZSCHEMELIBDIRS
. - Then, we can use
(import (toml))
to import this library directly.
Take the following toml file as an example.
# ./test/school.toml
[student]
[student.LiHua]
name = "李华 Li Hua"
birthday = 1997-05-16
grade = 2
[[student.LiHua.courses]]
name = "Calculus"
teacher-id = "200701021"
score = 3
[[student.LiHua.courses]]
name = "Linear Algebra"
teacher-id = "201303011"
score = 4
(load "./src/toml.so") ;; this line can be commented
;; out if installed globally
(import (toml))
- (toml-load text-port)
- Load toml-data from a text-port, return an assoc list.
- (toml-display data)
- Formatively display loaded toml-data.
(define fp (open-input-file "./test/school.toml"))
(define data (toml-load fp))
(toml-display data)
- (to-builtin data)
- Convert assoc list toml-data to built-in types.
(define data-ht (to-builtin data))
(toml-display data-ht)
- (toml-ref data path)
- Index toml-data by key path.
- (toml-set! data path value)
- Set tom-data by key path
(pretty-print
(toml-ref data
'(student LiHua birthday)))
(toml-set! data
'(student LiHua grade)
3)
(toml-display data)
- (toml-dump data text-port)
- Output toml data to text port in TOML format.
(toml-dump data
(current-output-port))