diff options
| author | Munyoki Kilyungi | 2026-02-09 17:48:39 +0300 |
|---|---|---|
| committer | Munyoki Kilyungi | 2026-02-09 17:49:01 +0300 |
| commit | 576ace2d3155411c42d483d0091efb3ca3386b17 (patch) | |
| tree | 5008e777a330d243e8f22f221f515e8f8bf69dbd /transform | |
| parent | 99d31d2be7bfc2e900db8fbd2c835ef7931360ba (diff) | |
| download | gn-transform-databases-576ace2d3155411c42d483d0091efb3ca3386b17.tar.gz | |
Fix bug with when terminating a short turtle pair.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'transform')
| -rw-r--r-- | transform/special-forms.scm | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/transform/special-forms.scm b/transform/special-forms.scm index 35dc2f3..425061d 100644 --- a/transform/special-forms.scm +++ b/transform/special-forms.scm @@ -23,44 +23,47 @@ emit-short-turtle define-transformer)) +(define (emittable-object? o) + (cond + ((null? o) #f) + ((not o) #f) + ((and (string? o) (string-blank? o)) #f) + (else #t))) + (define (emit-short-turtle subject po-alist) (let loop ((pairs po-alist) (first? #t)) (match pairs - ;; Skip pairs with blank string objects (((p . o) rest ...) - (if (and (string? o) (string-blank? o)) - (loop rest first?) ; ← skip entirely + (if (not (emittable-object? o)) + (loop rest first?) ; skip malformed or empty objects (begin - ;; subject only on first emitted line + ;; subject only once (when first? (format #t "~a " subject)) (when (not first?) - (format #t "\t")) ; indent following lines + (format #t "\t")) ;; emit predicate–object (match o ((? symbol?) (format #t "~a ~a" p (symbol->string o))) - ((or (? (lambda (el) - (and (string? el) - (string-match "^\\(.*\\)$" el)))) - (? (lambda (el) - (and (string? el) - (string-match "^\\[.*\\]$" el))))) - (format #t "~a ~s" p o)) + ((? string?) + (format #t "~a \"~a\"" p o)) (_ - (format #t "~a \"~a\"" p o))) + (format #t "~a ~s" p o))) - ;; separator - (if (null? rest) - (format #t " .~%") - (format #t " ;~%")) + ;; separator depends on *remaining emittable pairs* + (if (any (match-lambda + ((p . o) (emittable-object? o))) + rest) + (format #t " ;~%") + (format #t " .~%")) (loop rest #f)))) - (() #f)))) + (define (key->assoc-ref alist x) "Recursively translate (key k) forms in source X to (assoc-ref ALIST k) forms." |
