fix: date-only timestamp parsing
This commit is contained in:
parent
e3400352bb
commit
c966b0e022
7 changed files with 435 additions and 450 deletions
28
Makefile
28
Makefile
|
@ -1,14 +1,14 @@
|
||||||
##
|
##
|
||||||
# Toml
|
# Toml
|
||||||
#
|
#
|
||||||
# @file
|
# @file
|
||||||
# @version 0.1
|
# @version 0.1
|
||||||
|
|
||||||
.PHONY: salmonella
|
.PHONY: salmonella
|
||||||
salmonella:
|
salmonella:
|
||||||
rm -rf report
|
rm -rf report
|
||||||
rm -f toml*.so
|
rm -f toml*.so
|
||||||
salmonella --keep-repo --repo-dir=./petri-dish; \
|
salmonella --keep-repo --repo-dir=./petri-dish; \
|
||||||
salmonella-html-report ./salmonella.log report
|
salmonella-html-report ./salmonella.log report
|
||||||
|
|
||||||
# end
|
# end
|
||||||
|
|
105
tests/run.scm
105
tests/run.scm
|
@ -1,67 +1,52 @@
|
||||||
(import (r7rs)
|
(import (r7rs)
|
||||||
(scheme base)
|
(test)
|
||||||
(scheme write)
|
|
||||||
(srfi 64)
|
|
||||||
(srfi 152)
|
|
||||||
(rfc3339)
|
(rfc3339)
|
||||||
(toml))
|
(toml))
|
||||||
|
|
||||||
(define (tap-test-runner)
|
(test-group "Basic"
|
||||||
(let ((runner (test-runner-null))
|
(let ((tdat (table-from-file "basic.toml")))
|
||||||
(testcounter 0))
|
(test "7 Key-Value-Pairs"
|
||||||
(display "TAP version 13\n")
|
7 (toml-count-key-vals tdat))
|
||||||
(test-runner-on-test-end! runner
|
(test "Field name is TOML"
|
||||||
(lambda (runner)
|
"TOML" (toml-string tdat "name"))
|
||||||
(set! testcounter (+ testcounter 1))
|
(test "Field language is Chicken Scheme"
|
||||||
(display
|
"Chicken Scheme" (toml-string tdat "language"))
|
||||||
(string-append
|
(test "has-bool is #t"
|
||||||
(if (test-passed? runner) "ok " "not ok ")
|
#t (toml-bool tdat "has-bool"))
|
||||||
(number->string testcounter) " - "
|
(test "int is 5"
|
||||||
(string-join (test-runner-group-path runner) " - ")
|
5 (toml-int tdat "int"))
|
||||||
" - " (test-runner-test-name runner)
|
(test "double is 10.8"
|
||||||
(if (eq? 'skip (test-result-kind runner)) "# SKIP" "")
|
10.8 (toml-double tdat "double"))
|
||||||
"\n"))))
|
(test "timestamp parsing"
|
||||||
(test-runner-on-final! runner
|
#(1979 05 27 07 32 00 0.0 0)
|
||||||
(lambda (runner)
|
(rfc3339->vector (toml-timestamp tdat "timestamp")))))
|
||||||
(display (string-append "1.." (number->string testcounter) "\n"))))
|
|
||||||
runner))
|
|
||||||
|
|
||||||
(test-runner-factory
|
(test-group "Table"
|
||||||
(lambda () (tap-test-runner)))
|
(let ((tdat (table-from-file "table.toml")))
|
||||||
|
(test "No top-level Key-Value-Pairs"
|
||||||
|
0 (toml-count-key-vals tdat))
|
||||||
|
(test "One top-level table"
|
||||||
|
1 (toml-count-tables tdat))
|
||||||
|
(let ((servertbl (toml-table tdat "server")))
|
||||||
|
(test "\"server\" table has 2 Key-Value-Pairs"
|
||||||
|
2 (toml-count-key-vals servertbl))
|
||||||
|
(test "host is www.example.com"
|
||||||
|
"www.example.com" (toml-string servertbl "host"))
|
||||||
|
(test "timestamp parsing"
|
||||||
|
#(2022 09 09 0 0 0 0.0 0)
|
||||||
|
(rfc3339->vector (toml-timestamp servertbl "timestamp"))))))
|
||||||
|
|
||||||
(test-begin "Basic")
|
(test-group "Array"
|
||||||
|
(let* ((tdat (table-from-file "table.toml"))
|
||||||
|
(tserv (toml-table tdat "server"))
|
||||||
|
(tarr (toml-array tserv "port")))
|
||||||
|
(test "There is one array"
|
||||||
|
1 (toml-count-arrays tserv))
|
||||||
|
(test "The array has three entries"
|
||||||
|
3 (toml-count-entries tarr))
|
||||||
|
(test "Element 0 is 8080"
|
||||||
|
8080 (toml-int tarr 0))
|
||||||
|
(test "Element 2 is 8282"
|
||||||
|
8282 (toml-int tarr 2))))
|
||||||
|
|
||||||
(let ((tdat (table-from-file "basic.toml")))
|
(test-exit)
|
||||||
(test-equal 2 (toml-count-key-vals tdat))
|
|
||||||
(test-equal "TOML" (toml-string tdat "name"))
|
|
||||||
(test-equal "Chicken Scheme" (toml-string tdat "language"))
|
|
||||||
(test-equal #t (toml-bool tdat "has-bool"))
|
|
||||||
(test-equal 5 (toml-int tdat "int"))
|
|
||||||
(test-equal 10.8 (toml-double tdat "double"))
|
|
||||||
(test-equal (rfc3339->string (vector->rfc3339 #(1979 05 27 07 32 00 0 0)))
|
|
||||||
(rfc3339->string (toml-timestamp tdat "timestamp"))))
|
|
||||||
|
|
||||||
(test-end "Basic")
|
|
||||||
|
|
||||||
(test-begin "Table")
|
|
||||||
|
|
||||||
(let ((tdat (table-from-file "table.toml")))
|
|
||||||
(test-equal 0 (toml-count-key-vals tdat))
|
|
||||||
(test-equal 1 (toml-count-tables tdat))
|
|
||||||
(let ((servertbl (toml-table tdat "server")))
|
|
||||||
(test-equal 1 (toml-count-key-vals servertbl))
|
|
||||||
(test-equal "www.example.com" (toml-string servertbl "host"))))
|
|
||||||
|
|
||||||
(test-end "Table")
|
|
||||||
|
|
||||||
(test-begin "Array")
|
|
||||||
|
|
||||||
(let* ((tdat (table-from-file "table.toml"))
|
|
||||||
(tserv (toml-table tdat "server"))
|
|
||||||
(tarr (toml-array tserv "port")))
|
|
||||||
(test-equal 1 (toml-count-arrays tserv))
|
|
||||||
(test-equal 3 (toml-count-entries tarr))
|
|
||||||
(test-equal 8080 (toml-int tarr 0))
|
|
||||||
(test-equal 8282 (toml-int tarr 2)))
|
|
||||||
|
|
||||||
(test-end "Array")
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
[server]
|
[server]
|
||||||
host = "www.example.com"
|
host = "www.example.com"
|
||||||
port = [ 8080, 8181, 8282 ]
|
port = [ 8080, 8181, 8282 ]
|
||||||
|
timestamp = 2022-09-09
|
||||||
|
|
473
toml-impl.scm
473
toml-impl.scm
|
@ -1,239 +1,234 @@
|
||||||
(import (chicken base)
|
(import (chicken base)
|
||||||
scheme
|
scheme
|
||||||
(scheme base)
|
(scheme base)
|
||||||
(chicken foreign)
|
(chicken foreign)
|
||||||
(chicken memory)
|
(chicken memory)
|
||||||
(chicken gc)
|
(chicken gc)
|
||||||
(chicken format)
|
(chicken format)
|
||||||
rfc3339
|
rfc3339
|
||||||
coops
|
coops
|
||||||
coops-primitive-objects)
|
coops-primitive-objects)
|
||||||
|
|
||||||
(foreign-declare "#include <toml.h>")
|
(foreign-declare "#include <toml.h>")
|
||||||
|
|
||||||
(define (zeropad n)
|
(define (zeropad n)
|
||||||
(if (< n 10)
|
(if (< n 10)
|
||||||
(sprintf "0~S" n)
|
(sprintf "0~S" n)
|
||||||
(sprintf "~S" n)))
|
(sprintf "~S" n)))
|
||||||
|
|
||||||
(define (set-toml-table-finalizer ttable)
|
(define (set-toml-table-finalizer ttable)
|
||||||
(set-finalizer! ttable
|
(set-finalizer! ttable
|
||||||
(lambda (obj)
|
(lambda (obj)
|
||||||
((foreign-lambda* void ((c-pointer ttp))
|
((foreign-lambda* void ((c-pointer ttp))
|
||||||
"toml_free(ttp);")
|
"toml_free(ttp);")
|
||||||
(ptr ttable)))))
|
(ptr ttable)))))
|
||||||
|
|
||||||
(define-class <TomlArray> ()
|
(define-class <TomlArray> ()
|
||||||
((ptr :accessor ptr :initform #f)))
|
((ptr :accessor ptr :initform #f)))
|
||||||
|
|
||||||
(define-class <TomlTable> ()
|
(define-class <TomlTable> ()
|
||||||
((ptr :accessor ptr :initform #f)))
|
((ptr :accessor ptr :initform #f)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(define-method (toml-self-key (tarr <TomlArray>))
|
(define-method (toml-self-key (tarr <TomlArray>))
|
||||||
((foreign-lambda* c-string ((c-pointer tarr))
|
((foreign-lambda* c-string ((c-pointer tarr))
|
||||||
"C_return(toml_array_key(tarr));")
|
"C_return(toml_array_key(tarr));")
|
||||||
(ptr tarr)))
|
(ptr tarr)))
|
||||||
|
|
||||||
(define-method (toml-count-entries (tarr <TomlArray>))
|
(define-method (toml-count-entries (tarr <TomlArray>))
|
||||||
((foreign-lambda* int ((c-pointer tarr))
|
((foreign-lambda* int ((c-pointer tarr))
|
||||||
"C_return(toml_array_nelem(tarr));")
|
"C_return(toml_array_nelem(tarr));")
|
||||||
(ptr tarr)))
|
(ptr tarr)))
|
||||||
|
|
||||||
(define-method (toml-string (tarr <TomlArray>) (index <integer>))
|
(define-method (toml-string (tarr <TomlArray>) (index <integer>))
|
||||||
((foreign-primitive ((c-pointer tarr)
|
((foreign-primitive ((c-pointer tarr)
|
||||||
(int index))
|
(int index))
|
||||||
"toml_datum_t datum = toml_string_at(tarr, index);"
|
"toml_datum_t datum = toml_string_at(tarr, index);"
|
||||||
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
|
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
|
||||||
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
|
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
|
||||||
"free(datum.u.s);"
|
"free(datum.u.s);"
|
||||||
"C_values(3, data);")
|
"C_values(3, data);")
|
||||||
(ptr tarr) index))
|
(ptr tarr) index))
|
||||||
|
|
||||||
(define-method (toml-bool (tarr <TomlArray>) (index <integer>))
|
(define-method (toml-bool (tarr <TomlArray>) (index <integer>))
|
||||||
((foreign-lambda* bool ((c-pointer tarr)
|
((foreign-lambda* bool ((c-pointer tarr)
|
||||||
(int index))
|
(int index))
|
||||||
"C_return(toml_bool_at(tarr, index).u.b);")
|
"C_return(toml_bool_at(tarr, index).u.b);")
|
||||||
(ptr tarr) index))
|
(ptr tarr) index))
|
||||||
|
|
||||||
(define-method (toml-int (tarr <TomlArray>) (index <integer>))
|
(define-method (toml-int (tarr <TomlArray>) (index <integer>))
|
||||||
((foreign-lambda* int ((c-pointer tarr)
|
((foreign-lambda* int ((c-pointer tarr)
|
||||||
(int index))
|
(int index))
|
||||||
"C_return(toml_int_at(tarr, index).u.i);")
|
"C_return(toml_int_at(tarr, index).u.i);")
|
||||||
(ptr tarr) index))
|
(ptr tarr) index))
|
||||||
|
|
||||||
(define-method (toml-double (tarr <TomlArray>) (index <integer>))
|
(define-method (toml-double (tarr <TomlArray>) (index <integer>))
|
||||||
((foreign-lambda* double ((c-pointer tarr)
|
((foreign-lambda* double ((c-pointer tarr)
|
||||||
(int index))
|
(int index))
|
||||||
"C_return(toml_double_at(tarr, index).u.d);")
|
"C_return(toml_double_at(tarr, index).u.d);")
|
||||||
(ptr tarr) index))
|
(ptr tarr) index))
|
||||||
|
|
||||||
(define-method (toml-timestamp (tarr <TomlArray>) (index <integer>))
|
(define-method (toml-timestamp (tarr <TomlArray>) (index <integer>))
|
||||||
(let*-values (((Y M D h m s millis z)
|
(let*-values (((Y M D h m s millis z)
|
||||||
((foreign-primitive ((c-pointer tarr)
|
((foreign-primitive ((c-pointer tarr)
|
||||||
(int index))
|
(int index))
|
||||||
"toml_datum_t datum = toml_timestamp_at(tarr, index);"
|
"toml_datum_t datum = toml_timestamp_at(tarr, index);"
|
||||||
"toml_timestamp_t* stamp = datum.u.ts;"
|
"toml_timestamp_t* stamp = datum.u.ts;"
|
||||||
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z)));"
|
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z ?: \"Z\")));"
|
||||||
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
||||||
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
||||||
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
||||||
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
|
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
|
||||||
"C_string2(&s, stamp->z ?: \"Z\") } ;"
|
"C_string2(&s, stamp->z ?: \"Z\") } ;"
|
||||||
"free(datum.u.ts);"
|
"free(datum.u.ts);"
|
||||||
"C_values(10, data);")
|
"C_values(10, data);")
|
||||||
(ptr tarr) index))
|
(ptr tarr) index))
|
||||||
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
|
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
|
||||||
Y (zeropad M) (zeropad D)
|
Y (zeropad M) (zeropad D)
|
||||||
(zeropad h) (zeropad m) (zeropad s)
|
(zeropad h) (zeropad m) (zeropad s)
|
||||||
millis z)))
|
millis z)))
|
||||||
(string->rfc3339 rfcstr)))
|
(string->rfc3339 rfcstr)))
|
||||||
|
|
||||||
(define-method (toml-array (tarr <TomlArray>) (index <integer>))
|
(define-method (toml-array (tarr <TomlArray>) (index <integer>))
|
||||||
(make <TomlArray> 'ptr
|
(make <TomlArray> 'ptr
|
||||||
((foreign-lambda* c-pointer ((c-pointer tarr)
|
((foreign-lambda* c-pointer ((c-pointer tarr)
|
||||||
(int index))
|
(int index))
|
||||||
"C_return(toml_array_at(tarr, index));")
|
"C_return(toml_array_at(tarr, index));")
|
||||||
(ptr tarr) index)))
|
(ptr tarr) index)))
|
||||||
|
|
||||||
(define-method (toml-table (tarr <TomlArray>) (index <integer>))
|
(define-method (toml-table (tarr <TomlArray>) (index <integer>))
|
||||||
(make <TomlTable> 'ptr
|
(make <TomlTable> 'ptr
|
||||||
((foreign-lambda* c-pointer ((c-pointer tarr)
|
((foreign-lambda* c-pointer ((c-pointer tarr)
|
||||||
(int index))
|
(int index))
|
||||||
"C_return(toml_table_at(tarr, index));")
|
"C_return(toml_table_at(tarr, index));")
|
||||||
(ptr tarr) index)))
|
(ptr tarr) index)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(define (table-from-file filename)
|
||||||
|
(let ((ttp ((foreign-lambda* c-pointer ((c-string fname))
|
||||||
|
"FILE* fp = fopen(fname, \"r\");"
|
||||||
|
"char errbuf[200];"
|
||||||
|
"toml_table_t* conf = toml_parse_file(fp, errbuf, sizeof(errbuf));"
|
||||||
(define (table-from-file filename)
|
"fclose(fp);"
|
||||||
(let ((ttp ((foreign-lambda* c-pointer ((c-string fname))
|
"C_return(conf);")
|
||||||
"FILE* fp = fopen(fname, \"r\");"
|
filename)))
|
||||||
"char errbuf[200];"
|
(when (not (eq? ttp 0))
|
||||||
"toml_table_t* conf = toml_parse_file(fp, errbuf, sizeof(errbuf));"
|
(let ((tomltable (make <TomlTable> 'ptr ttp)))
|
||||||
"fclose(fp);"
|
(set-toml-table-finalizer tomltable)
|
||||||
"C_return(conf);")
|
tomltable))))
|
||||||
filename)))
|
|
||||||
(when (not (eq? ttp 0))
|
(define (table-from-string str)
|
||||||
(let ((tomltable (make <TomlTable> 'ptr ttp)))
|
(let ((ttp ((foreign-lambda* c-pointer ((c-string confdata))
|
||||||
(set-toml-table-finalizer tomltable)
|
"char errbuf[200];"
|
||||||
tomltable))))
|
"toml_table_t* conf = toml_parse(confdata, errbuf, sizeof(errbuf));"
|
||||||
|
"C_return(conf);")
|
||||||
(define (table-from-string str)
|
str)))
|
||||||
(let ((ttp ((foreign-lambda* c-pointer ((c-string confdata))
|
(when (not (eq? ttp 0))
|
||||||
"char errbuf[200];"
|
(let ((tomltable (make <TomlTable> 'ptr ttp)))
|
||||||
"toml_table_t* conf = toml_parse(confdata, errbuf, sizeof(errbuf));"
|
(set-toml-table-finalizer tomltable)
|
||||||
"C_return(conf);")
|
tomltable))))
|
||||||
str)))
|
|
||||||
(when (not (eq? ttp 0))
|
(define (set-toml-datum-string-finalizer tdatum)
|
||||||
(let ((tomltable (make <TomlTable> 'ptr ttp)))
|
(set-finalizer! tdatum
|
||||||
(set-toml-table-finalizer tomltable)
|
(lambda (obj)
|
||||||
tomltable))))
|
((foreign-lambda* void ((c-pointer tdat))
|
||||||
|
"free(tdat);")
|
||||||
(define (set-toml-datum-string-finalizer tdatum)
|
(ptr tdatum)))))
|
||||||
(set-finalizer! tdatum
|
|
||||||
(lambda (obj)
|
(define-method (toml-self-key (ttbl <TomlTable>))
|
||||||
((foreign-lambda* void ((c-pointer tdat))
|
((foreign-lambda* c-string ((c-pointer ttbl))
|
||||||
"free(tdat);")
|
"C_return(toml_table_key(ttbl));")
|
||||||
(ptr tdatum)))))
|
(ptr ttbl)))
|
||||||
|
|
||||||
(define-method (toml-self-key (ttbl <TomlTable>))
|
(define-method (toml-key-exists? (ttbl <TomlTable>) (key <string>))
|
||||||
((foreign-lambda* c-string ((c-pointer ttbl))
|
(= 1
|
||||||
"C_return(toml_table_key(ttbl));")
|
((foreign-lambda* int ((c-pointer ttbl)
|
||||||
(ptr ttbl)))
|
(c-string key))
|
||||||
|
"C_return(toml_key_exists(ttbl, key));")
|
||||||
(define-method (toml-key-exists? (ttbl <TomlTable>) (key <string>))
|
(ptr ttbl) key)))
|
||||||
(= 1
|
|
||||||
((foreign-lambda* int ((c-pointer ttbl)
|
(define-method (toml-count-key-vals (ttbl <TomlTable>))
|
||||||
(c-string key))
|
((foreign-lambda* int ((c-pointer ttbl))
|
||||||
"C_return(toml_key_exists(ttbl, key));")
|
"C_return(toml_table_nkval(ttbl));")
|
||||||
(ptr ttbl) key)))
|
(ptr ttbl)))
|
||||||
|
|
||||||
(define-method (toml-count-key-vals (ttbl <TomlTable>))
|
(define-method (toml-count-arrays (ttbl <TomlTable>))
|
||||||
((foreign-lambda* int ((c-pointer ttbl))
|
((foreign-lambda* int ((c-pointer ttbl))
|
||||||
"C_return(toml_table_nkval(ttbl));")
|
"C_return(toml_table_narr(ttbl));")
|
||||||
(ptr ttbl)))
|
(ptr ttbl)))
|
||||||
|
|
||||||
(define-method (toml-count-arrays (ttbl <TomlTable>))
|
(define-method (toml-count-tables (ttbl <TomlTable>))
|
||||||
((foreign-lambda* int ((c-pointer ttbl))
|
((foreign-lambda* int ((c-pointer ttbl))
|
||||||
"C_return(toml_table_narr(ttbl));")
|
"C_return(toml_table_ntab(ttbl));")
|
||||||
(ptr ttbl)))
|
(ptr ttbl)))
|
||||||
|
|
||||||
(define-method (toml-count-tables (ttbl <TomlTable>))
|
(define-method (toml-key-at (ttbl <TomlTable>) (index <integer>))
|
||||||
((foreign-lambda* int ((c-pointer ttbl))
|
((foreign-lambda* c-string ((c-pointer ttbl)
|
||||||
"C_return(toml_table_ntab(ttbl));")
|
(int index))
|
||||||
(ptr ttbl)))
|
"C_return(toml_key_in(ttbl, index));")
|
||||||
|
(ptr ttbl) index))
|
||||||
(define-method (toml-key-at (ttbl <TomlTable>) (index <integer>))
|
|
||||||
((foreign-lambda* c-string ((c-pointer ttbl)
|
(define-method (toml-string (ttbl <TomlTable>) (key <string>))
|
||||||
(int index))
|
((foreign-primitive ((c-pointer ttbl)
|
||||||
"C_return(toml_key_in(ttbl, index));")
|
(c-string key))
|
||||||
(ptr ttbl) index))
|
"toml_datum_t datum = toml_string_in(ttbl, key);"
|
||||||
|
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
|
||||||
(define-method (toml-string (ttbl <TomlTable>) (key <string>))
|
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
|
||||||
((foreign-primitive ((c-pointer ttbl)
|
"free(datum.u.s);"
|
||||||
(c-string key))
|
"C_values(3, data);")
|
||||||
"toml_datum_t datum = toml_string_in(ttbl, key);"
|
(ptr ttbl) key))
|
||||||
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(datum.u.s)));"
|
|
||||||
"C_word data[3] = { C_SCHEME_UNDEFINED, C_k, C_string2(&s, datum.u.s) };"
|
(define-method (toml-bool (ttbl <TomlTable>) (key <string>))
|
||||||
"free(datum.u.s);"
|
((foreign-lambda* bool ((c-pointer ttbl)
|
||||||
"C_values(3, data);")
|
(c-string key))
|
||||||
(ptr ttbl) key))
|
"C_return(toml_bool_in(ttbl, key).u.b);")
|
||||||
|
(ptr ttbl) key))
|
||||||
(define-method (toml-bool (ttbl <TomlTable>) (key <string>))
|
|
||||||
((foreign-lambda* bool ((c-pointer ttbl)
|
(define-method (toml-int (ttbl <TomlTable>) (key <string>))
|
||||||
(c-string key))
|
((foreign-lambda* int ((c-pointer ttbl)
|
||||||
"C_return(toml_bool_in(ttbl, key).u.b);")
|
(c-string key))
|
||||||
(ptr ttbl) key))
|
"C_return(toml_int_in(ttbl, key).u.i);")
|
||||||
|
(ptr ttbl) key))
|
||||||
(define-method (toml-int (ttbl <TomlTable>) (key <string>))
|
|
||||||
((foreign-lambda* int ((c-pointer ttbl)
|
(define-method (toml-double (ttbl <TomlTable>) (key <string>))
|
||||||
(c-string key))
|
((foreign-lambda* double ((c-pointer ttbl)
|
||||||
"C_return(toml_int_in(ttbl, key).u.i);")
|
(c-string key))
|
||||||
(ptr ttbl) key))
|
"C_return(toml_double_in(ttbl, key).u.d);")
|
||||||
|
(ptr ttbl) key))
|
||||||
(define-method (toml-double (ttbl <TomlTable>) (key <string>))
|
|
||||||
((foreign-lambda* double ((c-pointer ttbl)
|
(define-method (toml-timestamp (ttbl <TomlTable>) (key <string>))
|
||||||
(c-string key))
|
(let*-values (((Y M D h m s millis z)
|
||||||
"C_return(toml_double_in(ttbl, key).u.d);")
|
((foreign-primitive ((c-pointer ttbl)
|
||||||
(ptr ttbl) key))
|
(c-string key))
|
||||||
|
"toml_datum_t datum = toml_timestamp_in(ttbl, key);"
|
||||||
(define-method (toml-timestamp (ttbl <TomlTable>) (key <string>))
|
"toml_timestamp_t* stamp = datum.u.ts;"
|
||||||
(let*-values (((Y M D h m s millis z)
|
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z ?: \"Z\")));"
|
||||||
((foreign-primitive ((c-pointer ttbl)
|
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
||||||
(c-string key))
|
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
||||||
"toml_datum_t datum = toml_timestamp_in(ttbl, key);"
|
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
||||||
"toml_timestamp_t* stamp = datum.u.ts;"
|
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
|
||||||
"C_word* s = C_alloc(C_SIZEOF_STRING(strlen(stamp->z)));"
|
"C_string2(&s, stamp->z ?: \"Z\") } ;"
|
||||||
"C_word data[10] = { C_SCHEME_UNDEFINED, C_k, "
|
"free(datum.u.ts);"
|
||||||
"C_fix(stamp->year ? *stamp->year : 0), C_fix(stamp->month ? *stamp->month : 0), C_fix(stamp->day ? *stamp->day : 0), "
|
"C_values(10, data);")
|
||||||
"C_fix(stamp->hour ? *stamp->hour : 0), C_fix(stamp->minute ? *stamp->minute : 0),"
|
(ptr ttbl) key))
|
||||||
"C_fix(stamp->second ? *stamp->second : 0), C_fix(stamp->millisec ? *stamp->second : 0), "
|
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
|
||||||
"C_string2(&s, stamp->z ?: \"Z\") } ;"
|
Y (zeropad M) (zeropad D)
|
||||||
"free(datum.u.ts);"
|
(zeropad h) (zeropad m) (zeropad s)
|
||||||
"C_values(10, data);")
|
millis z)))
|
||||||
(ptr ttbl) key))
|
(string->rfc3339 rfcstr)))
|
||||||
((rfcstr) (sprintf "~A-~A-~AT~A:~A:~A.~A~A"
|
|
||||||
Y (zeropad M) (zeropad D)
|
(define-method (toml-array (ttbl <TomlTable>) (key <string>))
|
||||||
(zeropad h) (zeropad m) (zeropad s)
|
(make <TomlArray> 'ptr
|
||||||
millis z)))
|
((foreign-lambda* c-pointer ((c-pointer ttbl)
|
||||||
(string->rfc3339 rfcstr)))
|
(c-string key))
|
||||||
|
"C_return(toml_array_in(ttbl, key));")
|
||||||
(define-method (toml-array (ttbl <TomlTable>) (key <string>))
|
(ptr ttbl) key)))
|
||||||
(make <TomlArray> 'ptr
|
|
||||||
((foreign-lambda* c-pointer ((c-pointer ttbl)
|
(define-method (toml-table (ttbl <TomlTable>) (key <string>))
|
||||||
(c-string key))
|
(make <TomlTable> 'ptr
|
||||||
"C_return(toml_array_in(ttbl, key));")
|
((foreign-lambda* c-pointer ((c-pointer ttbl)
|
||||||
(ptr ttbl) key)))
|
(c-string key))
|
||||||
|
"C_return(toml_table_in(ttbl, key));")
|
||||||
(define-method (toml-table (ttbl <TomlTable>) (key <string>))
|
(ptr ttbl) key)))
|
||||||
(make <TomlTable> 'ptr
|
|
||||||
((foreign-lambda* c-pointer ((c-pointer ttbl)
|
|
||||||
(c-string key))
|
|
||||||
"C_return(toml_table_in(ttbl, key));")
|
|
||||||
(ptr ttbl) key)))
|
|
||||||
|
|
32
toml.egg
32
toml.egg
|
@ -1,16 +1,16 @@
|
||||||
;; -*- mode: scheme -*-
|
;; -*- mode: scheme -*-
|
||||||
((author "Daniel Ziltener")
|
((author "Daniel Ziltener")
|
||||||
(synopsis "A Chicken binding to read TOML configuration files")
|
(synopsis "A Chicken binding to read TOML configuration files")
|
||||||
(category parsing)
|
(category parsing)
|
||||||
(license "MIT")
|
(license "MIT")
|
||||||
(version "0.6")
|
(version "0.6")
|
||||||
(dependencies r7rs rfc3339 coops)
|
(dependencies r7rs rfc3339 coops)
|
||||||
(test-dependencies srfi-64 srfi-152)
|
(test-dependencies test)
|
||||||
|
|
||||||
(components
|
(components
|
||||||
(c-object tomlc99/toml
|
(c-object tomlc99/toml
|
||||||
(source "tomlc99/toml.c"))
|
(source "tomlc99/toml.c"))
|
||||||
(extension toml
|
(extension toml
|
||||||
(objects tomlc99/toml)
|
(objects tomlc99/toml)
|
||||||
(csc-options "-X" "r7rs" "-R" "r7rs" "-K" "prefix" "-sJ"
|
(csc-options "-X" "r7rs" "-R" "r7rs" "-K" "prefix" "-sJ"
|
||||||
"-Itomlc99"))))
|
"-Itomlc99"))))
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
(repo git "https://gitea.lyrion.ch/zilti/toml.git")
|
;; -*- Scheme -*-
|
||||||
(uri targz "https://gitea.lyrion.ch/zilti/toml/archive/{egg-release}.tar.gz")
|
(repo git "https://gitea.lyrion.ch/zilti/toml.git")
|
||||||
(release "0.6")
|
(uri targz "https://gitea.lyrion.ch/zilti/toml/archive/{egg-release}.tar.gz")
|
||||||
|
(release "0.6")
|
||||||
|
|
239
toml.wiki
239
toml.wiki
|
@ -1,118 +1,121 @@
|
||||||
[[tags: egg]]
|
[[tags: egg]]
|
||||||
[[toc:]]
|
[[toc:]]
|
||||||
== TOML
|
== TOML
|
||||||
A Chicken wrapper for the TOML configuration language
|
A Chicken wrapper for the TOML configuration language
|
||||||
|
|
||||||
=== Requirements
|
=== Requirements
|
||||||
|
|
||||||
[[/eggref/5/r7rs|r7rs]]
|
[[/eggref/5/r7rs|r7rs]]
|
||||||
[[/eggref/5/rfc3339|rfc3339]]
|
[[/eggref/5/rfc3339|rfc3339]]
|
||||||
[[/eggref/5/coops|coops]]
|
[[/eggref/5/coops|coops]]
|
||||||
|
|
||||||
=== Usage
|
=== Usage
|
||||||
|
|
||||||
<enscript language=scheme>
|
<enscript language=scheme>
|
||||||
(import toml)
|
(import toml)
|
||||||
</enscript>
|
</enscript>
|
||||||
|
|
||||||
=== Loading TOML configuration
|
=== Loading TOML configuration
|
||||||
|
|
||||||
<syntax>(table-from-file FILENAME) --> <TomlTable></syntax>
|
<syntax>(table-from-file FILENAME) --> <TomlTable></syntax>
|
||||||
|
|
||||||
Loads {{FILENAME}} contents as a TOML configuration.
|
Loads {{FILENAME}} contents as a TOML configuration.
|
||||||
|
|
||||||
<syntax>(table-from-string STRING) --> <TomlTable></syntax>
|
<syntax>(table-from-string STRING) --> <TomlTable></syntax>
|
||||||
|
|
||||||
Loads the contents of {{STRING}} as TOML configuration.
|
Loads the contents of {{STRING}} as TOML configuration.
|
||||||
|
|
||||||
=== Tables
|
=== Tables
|
||||||
|
|
||||||
<syntax>(toml-self-key TOMLTABLE) --> string</syntax>
|
<syntax>(toml-self-key TOMLTABLE) --> string</syntax>
|
||||||
|
|
||||||
Returns the key, if any, to which {{TOMLTABLE}} is assigned.
|
Returns the key, if any, to which {{TOMLTABLE}} is assigned.
|
||||||
|
|
||||||
<syntax>(toml-key-exists? TOMLTABLE KEY) --> bool</syntax>
|
<syntax>(toml-key-exists? TOMLTABLE KEY) --> bool</syntax>
|
||||||
|
|
||||||
Checks if {{KEY}} exists in {{TOMLTABLE}}.
|
Checks if {{KEY}} exists in {{TOMLTABLE}}.
|
||||||
|
|
||||||
<syntax>(toml-count-key-vals TOMLTABLE) --> int</syntax>
|
<syntax>(toml-count-key-vals TOMLTABLE) --> int</syntax>
|
||||||
<syntax>(toml-count-arrays TOMLTABLE) --> int</syntax>
|
<syntax>(toml-count-arrays TOMLTABLE) --> int</syntax>
|
||||||
<syntax>(toml-count-tables TOMLTABLE) --> int</syntax>
|
<syntax>(toml-count-tables TOMLTABLE) --> int</syntax>
|
||||||
|
|
||||||
Returns the number of key-value entries, arrays, or tables respectively in {{TOMLTABLE}}.
|
Returns the number of key-value entries, arrays, or tables respectively in {{TOMLTABLE}}.
|
||||||
|
|
||||||
<syntax>(toml-key-at TOMLTABLE INDEX) --> string</syntax>
|
<syntax>(toml-key-at TOMLTABLE INDEX) --> string</syntax>
|
||||||
|
|
||||||
Returns the table key at position {{INDEX}} in {{TOMLTABLE}}.
|
Returns the table key at position {{INDEX}} in {{TOMLTABLE}}.
|
||||||
|
|
||||||
<syntax>(toml-string TOMLTABLE KEY) --> string</syntax>
|
<syntax>(toml-string TOMLTABLE KEY) --> string</syntax>
|
||||||
<syntax>(toml-bool TOMLTABLE KEY) --> bool</syntax>
|
<syntax>(toml-bool TOMLTABLE KEY) --> bool</syntax>
|
||||||
<syntax>(toml-int TOMLTABLE KEY) --> int</syntax>
|
<syntax>(toml-int TOMLTABLE KEY) --> int</syntax>
|
||||||
<syntax>(toml-double TOMLTABLE KEY) --> double</syntax>
|
<syntax>(toml-double TOMLTABLE KEY) --> double</syntax>
|
||||||
<syntax>(toml-timestamp TOMLTABLE KEY) --> rfc3339</syntax>
|
<syntax>(toml-timestamp TOMLTABLE KEY) --> rfc3339</syntax>
|
||||||
<syntax>(toml-array TOMLTABLE KEY) --> <TomlArray></syntax>
|
<syntax>(toml-array TOMLTABLE KEY) --> <TomlArray></syntax>
|
||||||
<syntax>(toml-table TOMLTABLE KEY) --> <TomlTable></syntax>
|
<syntax>(toml-table TOMLTABLE KEY) --> <TomlTable></syntax>
|
||||||
|
|
||||||
Returns the element of the given type in {{TOMLTABLE}} at {{KEY}}.
|
Returns the element of the given type in {{TOMLTABLE}} at {{KEY}}.
|
||||||
|
|
||||||
=== Arrays
|
=== Arrays
|
||||||
|
|
||||||
<syntax>(toml-self-key TOMLARRAY) --> string</syntax>
|
<syntax>(toml-self-key TOMLARRAY) --> string</syntax>
|
||||||
|
|
||||||
Returns the key, if any, to which {{TOMLARRAY}} is assigned.
|
Returns the key, if any, to which {{TOMLARRAY}} is assigned.
|
||||||
|
|
||||||
<syntax>(toml-count-entries TOMLARRAY) --> int</syntax>
|
<syntax>(toml-count-entries TOMLARRAY) --> int</syntax>
|
||||||
|
|
||||||
Returns the number of entries in {{TOMLARRAY}}.
|
Returns the number of entries in {{TOMLARRAY}}.
|
||||||
|
|
||||||
<syntax>(toml-string TOMLARRAY KEY) --> string</syntax>
|
<syntax>(toml-string TOMLARRAY KEY) --> string</syntax>
|
||||||
<syntax>(toml-bool TOMLARRAY KEY) --> bool</syntax>
|
<syntax>(toml-bool TOMLARRAY KEY) --> bool</syntax>
|
||||||
<syntax>(toml-int TOMLARRAY KEY) --> int</syntax>
|
<syntax>(toml-int TOMLARRAY KEY) --> int</syntax>
|
||||||
<syntax>(toml-double TOMLARRAY KEY) --> double</syntax>
|
<syntax>(toml-double TOMLARRAY KEY) --> double</syntax>
|
||||||
<syntax>(toml-timestamp TOMLARRAY KEY) --> rfc3339</syntax>
|
<syntax>(toml-timestamp TOMLARRAY KEY) --> rfc3339</syntax>
|
||||||
<syntax>(toml-array TOMLARRAY KEY) --> <TomlArray></syntax>
|
<syntax>(toml-array TOMLARRAY KEY) --> <TomlArray></syntax>
|
||||||
<syntax>(toml-table TOMLARRAY KEY) --> <TomlTable></syntax>
|
<syntax>(toml-table TOMLARRAY KEY) --> <TomlTable></syntax>
|
||||||
|
|
||||||
Returns the element of the given type in {{TOMLARRAY}} at {{KEY}}.
|
Returns the element of the given type in {{TOMLARRAY}} at {{KEY}}.
|
||||||
|
|
||||||
== About this egg
|
== About this egg
|
||||||
|
|
||||||
=== Authors
|
=== Authors
|
||||||
Daniel Ziltener
|
Daniel Ziltener
|
||||||
CK Tan
|
CK Tan
|
||||||
|
|
||||||
=== Repository
|
=== Repository
|
||||||
|
|
||||||
The repository of the Chicken wrapper can be found at [[https://gitea.lyrion.ch/zilti/toml|https://gitea.lyrion.ch/zilti/toml]].
|
The repository of the Chicken wrapper can be found at [[https://gitea.lyrion.ch/zilti/toml|https://gitea.lyrion.ch/zilti/toml]].
|
||||||
|
|
||||||
The repository of the C implementation being wrapped can be found at [[https://github.com/cktan/tomlc99|https://github.com/cktan/tomlc99]].
|
The repository of the C implementation being wrapped can be found at [[https://github.com/cktan/tomlc99|https://github.com/cktan/tomlc99]].
|
||||||
|
|
||||||
=== Version History
|
=== Version History
|
||||||
; 0.6 : first version of the wrapper
|
|
||||||
|
; 0.7 : fixed an issue with timestamp parsing
|
||||||
=== License
|
|
||||||
MIT License
|
; 0.6 : first version of the wrapper
|
||||||
|
|
||||||
Copyright (c) Daniel Ziltener
|
=== License
|
||||||
https://gitea.lyrion.ch/zilti/toml
|
MIT License
|
||||||
|
|
||||||
Copyright (c) CK Tan
|
Copyright (c) Daniel Ziltener
|
||||||
https://github.com/cktan/tomlc99
|
https://gitea.lyrion.ch/zilti/toml
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Copyright (c) CK Tan
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
https://github.com/cktan/tomlc99
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
furnished to do so, subject to the following conditions:
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
The above copyright notice and this permission notice shall be included in all
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
copies or substantial portions of the Software.
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
The above copyright notice and this permission notice shall be included in all
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
copies or substantial portions of the Software.
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
SOFTWARE.
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
Loading…
Reference in a new issue