1 ;;;; pretty-printing of backquote expansions
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!IMPL")
14 (defun backq-unparse-expr (form splicing)
19 `((backq-comma-at ,form)))
21 `((backq-comma-dot ,form)))
24 (defun backq-unparse (form &optional splicing)
26 "Given a lisp form containing the magic functions BACKQ-LIST, BACKQ-LIST*,
27 BACKQ-APPEND, etc. produced by the backquote reader macro, will return a
28 corresponding backquote input form. In this form, `,' `,@' and `,.' are
29 represented by lists whose cars are BACKQ-COMMA, BACKQ-COMMA-AT, and
30 BACKQ-COMMA-DOT respectively, and whose cadrs are the form after the comma.
31 SPLICING indicates whether a comma-escape return should be modified for
32 splicing with other forms: a value of T or :NCONC meaning that an extra
33 level of parentheses should be added."
36 (backq-unparse-expr form splicing))
37 ((not (null (cdr (last form))))
38 ;; FIXME: Shouldn't this be an ERROR?
39 "### illegal dotted backquote form ###")
43 (mapcar #'backq-unparse (cdr form)))
45 (do ((tail (cdr form) (cdr tail))
48 (nconc (nreverse accum)
49 (backq-unparse (car tail) t)))
50 (push (backq-unparse (car tail)) accum)))
52 (mapcan #'(lambda (el) (backq-unparse el t))
55 (mapcan #'(lambda (el) (backq-unparse el :nconc))
58 (cons (backq-unparse (cadr form) nil)
59 (backq-unparse (caddr form) t)))
61 (coerce (backq-unparse (cadr form)) 'vector))
65 (backq-unparse-expr form splicing))))))
67 (defun pprint-backquote (stream form &rest noise)
68 (declare (ignore noise))
69 (write-char #\` stream)
70 (write (backq-unparse form) :stream stream))
72 (defun pprint-backq-comma (stream form &rest noise)
73 (declare (ignore noise))
76 (write-char #\, stream))
81 (write (cadr form) :stream stream))
83 ;;; This is called by !PPRINT-COLD-INIT, fairly late, because
84 ;;; SET-PPRINT-DISPATCH doesn't work until the compiler works.
86 ;;; FIXME: It might be cleaner to just make these be toplevel forms and
87 ;;; enforce the delay by putting this file late in the build sequence.
88 (defun !backq-pp-cold-init ()
89 (set-pprint-dispatch '(cons (eql backq-list)) #'pprint-backquote)
90 (set-pprint-dispatch '(cons (eql backq-list*)) #'pprint-backquote)
91 (set-pprint-dispatch '(cons (eql backq-append)) #'pprint-backquote)
92 (set-pprint-dispatch '(cons (eql backq-nconc)) #'pprint-backquote)
93 (set-pprint-dispatch '(cons (eql backq-cons)) #'pprint-backquote)
94 (set-pprint-dispatch '(cons (eql backq-vector)) #'pprint-backquote)
96 (set-pprint-dispatch '(cons (eql backq-comma)) #'pprint-backq-comma)
97 (set-pprint-dispatch '(cons (eql backq-comma-at)) #'pprint-backq-comma)
98 (set-pprint-dispatch '(cons (eql backq-comma-dot)) #'pprint-backq-comma))