From 9422d6660103494e6c79f9f3e1c8944de66c4901 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 11 Jun 2016 21:31:47 -0700 Subject: [PATCH] improve vertical positioning & paren shaping in `syntax->string` --- racket/collects/syntax/to-string.rkt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/racket/collects/syntax/to-string.rkt b/racket/collects/syntax/to-string.rkt index 855452084f..5254121fc0 100644 --- a/racket/collects/syntax/to-string.rkt +++ b/racket/collects/syntax/to-string.rkt @@ -14,7 +14,7 @@ (let ([c (syntax-column c)] [l (syntax-line c)]) (when (and l (l . > . line)) - (newline) + (for-each (λ (_) (newline)) (range (- l line))) (set! line l) (init-line!)) (when c @@ -55,10 +55,14 @@ ((loop init-line!) i))] [(pair? (syntax-e c)) (advance c init-line!) - (printf "(") + (define c-paren-shape (syntax-property c 'paren-shape)) + (printf "~a" (or c-paren-shape #\()) (set! col (+ col 1)) (map (loop init-line!) (syntax->list c)) - (printf ")") + (printf (case c-paren-shape + [(#\[) "]"] + [(#\{) "}"] + [else ")"])) (set! col (+ col 1))] [(vector? (syntax-e c)) (advance c init-line!)