1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
12 ;;; Break a lambda-list into its component parts. We return eleven
14 ;;; 1. A list of the required args.
15 ;;; 2. A list of the optional arg specs.
16 ;;; 3. True if a rest arg was specified.
18 ;;; 5. A boolean indicating whether keywords args are present.
19 ;;; 6. A list of the keyword arg specs.
20 ;;; 7. True if &allow-other-keys was specified.
21 ;;; 8. A list of the &aux specifiers.
22 ;;; 9. True if a more arg was specified.
23 ;;; 10. The &more context var
24 ;;; 11. The &more count var
26 ;;; The top-level lambda-list syntax is checked for validity, but the
27 ;;; arg specifiers are just passed through untouched. If something is
28 ;;; wrong, we use Compiler-Error, aborting compilation to the last
30 (declaim (ftype (function (list)
31 (values list list boolean t boolean list boolean
34 (defun parse-lambda-list (list)
47 (declare (type (member :allow-other-keys :aux
49 :more-context :more-count
55 (if (and (symbolp arg)
56 (let ((name (symbol-name arg)))
57 (and (plusp (length name))
58 (char= (char name 0) #\&))))
61 (unless (eq state :required)
62 (compiler-error "misplaced &OPTIONAL in lambda list: ~S"
64 (setq state :optional))
66 (unless (member state '(:required :optional))
67 (compiler-error "misplaced &REST in lambda list: ~S" list))
70 (unless (member state '(:required :optional))
71 (compiler-error "misplaced &MORE in lambda list: ~S" list))
76 '(:required :optional :post-rest :post-more))
77 (compiler-error "misplaced &KEY in lambda list: ~S" list))
81 (unless (eq state ':key)
82 (compiler-error "misplaced &ALLOW-OTHER-KEYS in ~
86 state :allow-other-keys))
88 (when (member state '(:rest :more-context :more-count))
89 (compiler-error "misplaced &AUX in lambda list: ~S" list))
91 ;; FIXME: I don't think ANSI says this is an error. (It
92 ;; should certainly be good for a STYLE-WARNING,
95 (compiler-error "unknown &KEYWORD in lambda list: ~S" arg)))
97 (:required (required arg))
98 (:optional (optional arg))
104 (setq more-context arg
112 (compiler-error "found garbage in lambda list when expecting ~
116 (values (required) (optional) restp rest keyp (keys) allowp (aux)
117 morep more-context more-count))))