mirror of
https://git.savannah.gnu.org/git/guix.git
synced 2025-01-18 21:46:35 +01:00
read-print: Correctly handle comments that follow a list head.
Fixes <https://issues.guix.gnu.org/61013>. Reported by Maxim Cournoyer <maxim.cournoyer@gmail.com>. * guix/read-print.scm (pretty-print-with-comments)[starts-with-line-comment?]: New procedure. Use it when printing a list. * tests/read-print.scm: Add two tests.
This commit is contained in:
parent
11f6bdc547
commit
0a37921d85
2 changed files with 17 additions and 1 deletions
|
@ -529,6 +529,12 @@ (define (list-of-lists? head tail)
|
||||||
(pair? tail)))
|
(pair? tail)))
|
||||||
(_ #f)))
|
(_ #f)))
|
||||||
|
|
||||||
|
(define (starts-with-line-comment? lst)
|
||||||
|
;; Return true if LST starts with a line comment.
|
||||||
|
(match lst
|
||||||
|
((x . _) (and (comment? x) (not (comment-margin? x))))
|
||||||
|
(_ #f)))
|
||||||
|
|
||||||
(let loop ((indent indent)
|
(let loop ((indent indent)
|
||||||
(column indent)
|
(column indent)
|
||||||
(delimited? #t) ;true if comes after a delimiter
|
(delimited? #t) ;true if comes after a delimiter
|
||||||
|
@ -710,7 +716,8 @@ (define new-column
|
||||||
(+ indent 1)
|
(+ indent 1)
|
||||||
(+ column (if delimited? 1 2))))
|
(+ column (if delimited? 1 2))))
|
||||||
(newline? (or (newline-form? head context)
|
(newline? (or (newline-form? head context)
|
||||||
(list-of-lists? head tail))) ;'let' bindings
|
(list-of-lists? head tail) ;'let' bindings
|
||||||
|
(starts-with-line-comment? tail)))
|
||||||
(context (cons head context)))
|
(context (cons head context)))
|
||||||
(if overflow?
|
(if overflow?
|
||||||
(begin
|
(begin
|
||||||
|
|
|
@ -210,6 +210,15 @@ (define-syntax-rule (test-pretty-print/sequence str args ...)
|
||||||
\"abcdefghijklmnopqrstuvwxyz\")"
|
\"abcdefghijklmnopqrstuvwxyz\")"
|
||||||
#:max-width 33)
|
#:max-width 33)
|
||||||
|
|
||||||
|
(test-pretty-print "\
|
||||||
|
(list ;margin comment
|
||||||
|
a b c)")
|
||||||
|
|
||||||
|
(test-pretty-print "\
|
||||||
|
(list
|
||||||
|
;; This is a line comment immediately following the list head.
|
||||||
|
#:test-flags #~(list \"-m\" \"not external and not samples\"))")
|
||||||
|
|
||||||
(test-pretty-print "\
|
(test-pretty-print "\
|
||||||
(modify-phases %standard-phases
|
(modify-phases %standard-phases
|
||||||
(replace 'build
|
(replace 'build
|
||||||
|
|
Loading…
Reference in a new issue