feat(encoder): array-tables (wip)
This commit is contained in:
parent
5ff69c5982
commit
7eddf96f5d
|
@ -25,12 +25,35 @@
|
||||||
(when newline?
|
(when newline?
|
||||||
(newline port)))
|
(newline port)))
|
||||||
|
|
||||||
(define* (build-object-pair p port #:key (newline? #t) (inline? #f))
|
(define (toml-build-array-table-header keys port)
|
||||||
;; (put-string port (car p))
|
(put-string port "[[")
|
||||||
|
(build-keys keys port)
|
||||||
|
(put-string port "]]"))
|
||||||
|
|
||||||
|
(define* (toml-build-array-table scm port #:optional (current-table '()))
|
||||||
|
(define header (car scm))
|
||||||
|
(define keys (append current-table (list header)))
|
||||||
|
(define entries (vector->list (cdr scm)))
|
||||||
|
(let loop ((entries entries))
|
||||||
|
(unless (null? entries)
|
||||||
|
(toml-build-array-table-header keys port)
|
||||||
|
(build-newline port #t)
|
||||||
|
(toml-build (car entries) port keys)
|
||||||
|
(loop (cdr entries)))))
|
||||||
|
|
||||||
|
(define (array-table? v)
|
||||||
|
;; (log-exprs v)
|
||||||
|
(and (vector? v) (not (any (value?) (vector->list v)))))
|
||||||
|
|
||||||
|
(define* (build-object-pair p port #:optional (current-table '())#:key (newline? #t) (inline? #f))
|
||||||
|
(if (array-table? (cdr p))
|
||||||
|
(toml-build-array-table p port current-table)
|
||||||
|
(build-keyval p port #:newline? newline? #:inline? inline?)))
|
||||||
|
|
||||||
|
(define* (build-keyval p port #:key (newline? #t) (inline? #f))
|
||||||
(build-key (car p) port)
|
(build-key (car p) port)
|
||||||
(put-string port " = ")
|
(put-string port " = ")
|
||||||
(toml-build (cdr p) port #:newline? newline? #:inline? inline?))
|
(toml-build (cdr p) port #:newline? newline? #:inline? inline?))
|
||||||
|
|
||||||
;; (define (escape-special c))
|
;; (define (escape-special c))
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,7 +97,7 @@
|
||||||
(receive (keyvals tables)
|
(receive (keyvals tables)
|
||||||
(partition value-pair? pairs)
|
(partition value-pair? pairs)
|
||||||
(for-each (lambda (kv)
|
(for-each (lambda (kv)
|
||||||
(build-object-pair kv port))
|
(build-object-pair kv port current-table))
|
||||||
keyvals)
|
keyvals)
|
||||||
(for-each (lambda (t)
|
(for-each (lambda (t)
|
||||||
(build-table t port current-table))
|
(build-table t port current-table))
|
||||||
|
@ -131,13 +154,17 @@
|
||||||
|
|
||||||
(define* (toml-build scm port #:optional (current-table '())
|
(define* (toml-build scm port #:optional (current-table '())
|
||||||
#:key (newline? #t) (inline? #f))
|
#:key (newline? #t) (inline? #f))
|
||||||
|
;; (log-exprs scm)
|
||||||
(cond
|
(cond
|
||||||
;; ((eq? scm null) (toml-build-null port))
|
;; ((eq? scm null) (toml-build-null port))
|
||||||
;; ((boolean? scm) (toml-build-boolean scm port))
|
;; ((boolean? scm) (toml-build-boolean scm port))
|
||||||
;; ((toml-number? scm) (toml-build-number scm port))
|
;; ((toml-number? scm) (toml-build-number scm port))
|
||||||
;; ((symbol? scm) (toml-build-string (symbol->string scm) port))
|
;; ((symbol? scm) (toml-build-string (symbol->string scm) port))
|
||||||
|
((null? scm) '())
|
||||||
(((value?) scm)
|
(((value?) scm)
|
||||||
((toml-build-value) scm port #:newline? newline? #:inline? inline?))
|
((toml-build-value) scm port #:newline? newline? #:inline? inline?))
|
||||||
|
((array-table? (and (list? scm) (cdr scm)))
|
||||||
|
(toml-build-array-table scm port))
|
||||||
((or (pair? scm) (null? scm))
|
((or (pair? scm) (null? scm))
|
||||||
(if inline?
|
(if inline?
|
||||||
(toml-build-inline-tree scm port)
|
(toml-build-inline-tree scm port)
|
||||||
|
|
Loading…
Reference in New Issue