import: hackage: Make it resilient to missing final newline.

* guix/import/cabal.scm (peek-next-line-indent): Check for missing final
  newline.
This commit is contained in:
Federico Beffa 2015-11-11 15:31:46 +01:00
parent 9be54eb1b1
commit 876fd23ab6

View file

@ -227,19 +227,24 @@ (define (peek-next-line-indent port)
"This function can be called when the next character on PORT is #\newline "This function can be called when the next character on PORT is #\newline
and returns the indentation of the line starting after the #\newline and returns the indentation of the line starting after the #\newline
character. Discard (and consume) empty and comment lines." character. Discard (and consume) empty and comment lines."
(let ((initial-newline (string (read-char port)))) (if (eof-object? (peek-char port))
(let loop ((char (peek-char port)) ;; If the file is missing the #\newline on the last line, add it and act
(word "")) ;; as if it were there. This is needed for proper operation of
(cond ((eqv? char #\newline) (read-char port) ;; indentation based block recognition (based on port-column).
(loop (peek-char port) "")) (begin (unread-char #\newline port) (read-char port) 0)
((or (eqv? char #\space) (eqv? char #\tab)) (let ((initial-newline (string (read-char port))))
(let ((c (read-char port))) (let loop ((char (peek-char port))
(loop (peek-char port) (string-append word (string c))))) (word ""))
((comment-line port char) (loop (peek-char port) "")) (cond ((eqv? char #\newline) (read-char port)
(else (loop (peek-char port) ""))
(let ((len (string-length word))) ((or (eqv? char #\space) (eqv? char #\tab))
(unread-string (string-append initial-newline word) port) (let ((c (read-char port)))
len)))))) (loop (peek-char port) (string-append word (string c)))))
((comment-line port char) (loop (peek-char port) ""))
(else
(let ((len (string-length word)))
(unread-string (string-append initial-newline word) port)
len)))))))
(define* (read-value port value min-indent #:optional (separator " ")) (define* (read-value port value min-indent #:optional (separator " "))
"The next character on PORT must be #\newline. Append to VALUE the "The next character on PORT must be #\newline. Append to VALUE the