about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--transform/special-forms.scm39
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."