1 ;;;; error-handling machinery for PARSE-DEFMACRO, separated from
2 ;;;; PARSE-DEFMACRO code itself 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
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 ;;; We save space in macro definitions by calling this function.
17 (defun arg-count-error (error-kind name arg lambda-list minimum maximum)
19 (sb!debug:*stack-top-hint* (nth-value 1 (find-caller-name-and-frame))))
20 (error 'arg-count-error
24 :lambda-list lambda-list
25 :minimum minimum :maximum maximum)))
27 (define-condition defmacro-lambda-list-bind-error (error)
28 ((kind :reader defmacro-lambda-list-bind-error-kind
30 (name :reader defmacro-lambda-list-bind-error-name
34 (defun print-defmacro-ll-bind-error-intro (condition stream)
36 "error while parsing arguments to ~A~@[ ~S~]:~%"
37 (defmacro-lambda-list-bind-error-kind condition)
38 (defmacro-lambda-list-bind-error-name condition)))
40 (define-condition defmacro-bogus-sublist-error
41 (defmacro-lambda-list-bind-error)
42 ((object :reader defmacro-bogus-sublist-error-object :initarg :object)
43 (lambda-list :reader defmacro-bogus-sublist-error-lambda-list
44 :initarg :lambda-list))
46 (lambda (condition stream)
47 (print-defmacro-ll-bind-error-intro condition stream)
49 "bogus sublist:~% ~S~%to satisfy lambda-list:~% ~:S~%"
50 (defmacro-bogus-sublist-error-object condition)
51 (defmacro-bogus-sublist-error-lambda-list condition)))))
53 (define-condition arg-count-error (defmacro-lambda-list-bind-error)
54 ((argument :reader arg-count-error-argument :initarg :argument)
55 (lambda-list :reader arg-count-error-lambda-list
56 :initarg :lambda-list)
57 (minimum :reader arg-count-error-minimum :initarg :minimum)
58 (maximum :reader arg-count-error-maximum :initarg :maximum))
60 (lambda (condition stream)
61 (print-defmacro-ll-bind-error-intro condition stream)
63 "invalid number of elements in:~% ~:S~%~
64 to satisfy lambda list:~% ~:S~%"
65 (arg-count-error-argument condition)
66 (arg-count-error-lambda-list condition))
67 (cond ((null (arg-count-error-maximum condition))
68 (format stream "at least ~W expected"
69 (arg-count-error-minimum condition)))
70 ((= (arg-count-error-minimum condition)
71 (arg-count-error-maximum condition))
72 (format stream "exactly ~W expected"
73 (arg-count-error-minimum condition)))
75 (format stream "between ~W and ~W expected"
76 (arg-count-error-minimum condition)
77 (arg-count-error-maximum condition))))
78 (format stream ", but ~W found"
79 (length (arg-count-error-argument condition))))))
81 (define-condition defmacro-ll-broken-key-list-error
82 (defmacro-lambda-list-bind-error)
83 ((problem :reader defmacro-ll-broken-key-list-error-problem
85 (info :reader defmacro-ll-broken-key-list-error-info :initarg :info))
86 (:report (lambda (condition stream)
87 (print-defmacro-ll-bind-error-intro condition stream)
89 ;; FIXME: These should probably just be three
90 ;; subclasses of the base class, so that we don't
91 ;; need to maintain the set of tags both here and
92 ;; implicitly wherever this macro is used.
94 (defmacro-ll-broken-key-list-error-problem condition)
96 "dotted keyword/value list: ~S")
98 "odd number of elements in keyword/value list: ~S")
100 "~{unknown keyword: ~S; expected one of ~{~S~^, ~}~}"))
101 (defmacro-ll-broken-key-list-error-info condition)))))