Commits

Anonymous committed bc7532d

Add newline at eof

  • Participants
  • Parent commits e7659ad

Comments (0)

Files changed (1)

File lowdown-impl.scm

     (result (list el content))))
 
 (define end-of-input
-  (none-of item))
+  (preceded-by (none-of item) (result #\newline)))
 
 (define space-chars
   (char-set #\space #\tab))
               (sequence new-line))
           (sequence (one-or-more item) end-of-input)))
 
+(define (tabs->spaces str)
+  (irregex-replace/all
+   '(seq (submatch (* (~ #\tab))) #\tab)
+   str
+   (lambda (m)
+     (let* ((prefix (irregex-match-substring m 1))
+            (size   (- 4 (modulo (string-length prefix) 4))))
+       (string-append prefix (make-string size #\space))))))
+
 (define line
   (sequence* ((line (as-string raw-line)))
-    (result (irregex-replace/all
-             '(seq (submatch (* (~ #\tab))) #\tab)
-             line
-             (lambda (m)
-               (let ((prefix (irregex-match-substring m 1)))
-                 (string-append
-                  prefix
-                  (make-string (- 4 (modulo (string-length prefix) 4)) #\space))))))))
+    (result (tabs->spaces line))))
 
 ;; Indent =            "\t" | "    "