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.
15 ;;; Break a lambda-list into its component parts. We return eleven
17 ;;; 1. A list of the required args.
18 ;;; 2. A list of the optional arg specs.
19 ;;; 3. True if a rest arg was specified.
21 ;;; 5. A boolean indicating whether keywords args are present.
22 ;;; 6. A list of the keyword arg specs.
23 ;;; 7. True if &allow-other-keys was specified.
24 ;;; 8. A list of the &aux specifiers.
25 ;;; 9. True if a more arg was specified.
26 ;;; 10. The &more context var
27 ;;; 11. The &more count var
29 ;;; The top-level lambda-list syntax is checked for validity, but the
30 ;;; arg specifiers are just passed through untouched. If something is
31 ;;; wrong, we use Compiler-Error, aborting compilation to the last
33 (declaim (ftype (function (list)
34 (values list list boolean t boolean list boolean
37 (defun parse-lambda-list (list)
50 (declare (type (member :allow-other-keys :aux
52 :more-context :more-count
58 (if (and (symbolp arg)
59 (let ((name (symbol-name arg)))
60 (and (plusp (length name))
61 (char= (char name 0) #\&))))
64 (unless (eq state :required)
65 (compiler-error "misplaced &OPTIONAL in lambda list: ~S"
67 (setq state :optional))
69 (unless (member state '(:required :optional))
70 (compiler-error "misplaced &REST in lambda list: ~S" list))
73 (unless (member state '(:required :optional))
74 (compiler-error "misplaced &MORE in lambda list: ~S" list))
79 '(:required :optional :post-rest :post-more))
80 (compiler-error "misplaced &KEY in lambda list: ~S" list))
84 (unless (eq state ':key)
85 (compiler-error "misplaced &ALLOW-OTHER-KEYS in ~
89 state :allow-other-keys))
91 (when (member state '(:rest :more-context :more-count))
92 (compiler-error "misplaced &AUX in lambda list: ~S" list))
94 ;; FIXME: I don't think ANSI says this is an error. (It
95 ;; should certainly be good for a STYLE-WARNING,
98 (compiler-error "unknown &KEYWORD in lambda list: ~S" arg)))
100 (:required (required arg))
101 (:optional (optional arg))
107 (setq more-context arg
115 (compiler-error "found garbage in lambda list when expecting ~
119 (values (required) (optional) restp rest keyp (keys) allowp (aux)
120 morep more-context more-count))))