Remove some test noise. A drop in the ocean unfortunately.
[sbcl.git] / src / code / parse-defmacro-errors.lisp
bloba16b7b7f4224cba59101a9685c1500c3081309a0
1 ;;;; error-handling machinery for MAKE-MACRO-LAMBDA separated from
2 ;;;; that code because the happy path can be handled
3 ;;;; earlier in the bootstrap sequence than DEFINE-CONDITION can be
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
14 (in-package "SB!KERNEL")
16 (define-condition defmacro-lambda-list-bind-error (error)
17 ((kind :reader defmacro-lambda-list-bind-error-kind
18 :initarg :kind)
19 (name :reader defmacro-lambda-list-bind-error-name
20 :initarg :name
21 :initform nil)))
23 ;;; shared logic for REPORTing variants of DEFMACRO-LAMBDA-LIST-BIND-ERROR:
24 ;;; Set up appropriate prettying and indentation on STREAM, print some
25 ;;; boilerplate related to CONDITION (an instance of
26 ;;; DEFMACRO-LAMBDA-LIST-BIND-ERROR), then execute BODY.
27 (defmacro !printing-defmacro-lambda-list-bind-error ((condition stream)
28 &body body)
29 `(%printing-defmacro-lambda-list-bind-error ,condition
30 ,stream
31 (lambda (,stream)
32 (declare (type stream ,stream))
33 ,@body)))
34 (defun %printing-defmacro-lambda-list-bind-error (condition stream fun)
35 (declare (type stream stream) (type function fun))
36 (pprint-logical-block (stream nil)
37 (format stream
38 "error while parsing arguments to ~A~@[ ~S~]:~2I~:@_"
39 (defmacro-lambda-list-bind-error-kind condition)
40 (defmacro-lambda-list-bind-error-name condition))
41 (pprint-logical-block (stream nil)
42 (funcall fun stream))))
44 (define-condition arg-count-error (defmacro-lambda-list-bind-error)
45 ((args :reader arg-count-error-args :initarg :args)
46 (lambda-list :reader arg-count-error-lambda-list
47 :initarg :lambda-list)
48 (minimum :reader arg-count-error-minimum :initarg :minimum)
49 (maximum :reader arg-count-error-maximum :initarg :maximum))
50 (:report
51 (lambda (condition stream)
52 (!printing-defmacro-lambda-list-bind-error (condition stream)
53 (let ((min (arg-count-error-minimum condition))
54 (max (arg-count-error-maximum condition))
55 (actual (arg-count-error-args condition)))
56 (format stream
57 "invalid number of elements in ~2I~_~:S ~
58 ~I~_to satisfy lambda list ~2I~_~:S: ~I~_"
59 actual (arg-count-error-lambda-list condition))
60 (format stream
61 (cond ((null max) "at least ~W expected")
62 ((= min max) "exactly ~W expected")
63 (t "between ~W and ~W expected"))
64 min max)
65 (cond ((and (atom actual) actual)
66 (format stream ", but got a non-list"))
67 ((cdr (last actual))
68 (format stream ", but got an improper list"))
70 (format stream ", but got ~d" (length actual)))))))))
72 (define-condition defmacro-lambda-list-broken-key-list-error
73 (defmacro-lambda-list-bind-error)
74 ((problem :reader defmacro-lambda-list-broken-key-list-error-problem
75 :initarg :problem)
76 (info :reader defmacro-lambda-list-broken-key-list-error-info
77 :initarg :info))
78 (:report (lambda (condition stream)
79 (!printing-defmacro-lambda-list-bind-error (condition stream)
80 (format stream
81 ;; FIXME: These should probably just be three
82 ;; subclasses of the base class, so that we don't
83 ;; need to maintain the set of tags both here and
84 ;; implicitly wherever this macro is used. (This
85 ;; might get easier once CLOS is initialized in
86 ;; cold init.)
87 (ecase
88 (defmacro-lambda-list-broken-key-list-error-problem
89 condition)
90 (:dotted-list
91 "dotted keyword/value list: ~S")
92 (:odd-length
93 "odd number of elements in keyword/value list: ~S")
94 (:unknown-keyword
95 ;; Todo: print the keyword portion of the actual args
96 ;; "unknown keyword foo in (:A 1 :B ...);
97 ;; expected one of ..."
98 "~{unknown keyword: ~S; expected one of ~
99 ~{~S~^, ~}~}"))
100 (defmacro-lambda-list-broken-key-list-error-info
101 condition))))))