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 (/show0 "parse-lambda-list.lisp 12")
14 ;;; Break a lambda list into its component parts. We return eleven
16 ;;; 1. a list of the required args;
17 ;;; 2. a list of the optional arg specs;
18 ;;; 3. true if a rest arg was specified;
20 ;;; 5. true if &KEY args are present;
21 ;;; 6. a list of the &KEY arg specs;
22 ;;; 7. true if &ALLOW-OTHER-KEYS was specified.;
23 ;;; 8. a list of the &AUX specifiers;
24 ;;; 9. true if a &MORE arg was specified;
25 ;;; 10. the &MORE context var;
26 ;;; 11. the &MORE count var.
28 ;;; The top-level lambda list syntax is checked for validity, but the
29 ;;; arg specifiers are just passed through untouched. If something is
30 ;;; wrong, we use COMPILER-ERROR, aborting compilation to the last
32 (declaim (ftype (function (list)
33 (values list list boolean t boolean list boolean
36 (defun parse-lambda-list (list)
49 (declare (type (member :allow-other-keys :aux
51 :more-context :more-count
57 (if (and (symbolp arg)
58 (let ((name (symbol-name arg)))
59 (and (plusp (length name))
60 (char= (char name 0) #\&))))
63 (unless (eq state :required)
64 (compiler-error "misplaced &OPTIONAL in lambda list: ~S"
66 (setq state :optional))
68 (unless (member state '(:required :optional))
69 (compiler-error "misplaced &REST in lambda list: ~S" list))
72 (unless (member state '(:required :optional))
73 (compiler-error "misplaced &MORE in lambda list: ~S" list))
78 '(:required :optional :post-rest :post-more))
79 (compiler-error "misplaced &KEY in lambda list: ~S" list))
83 (unless (eq state ':key)
84 (compiler-error "misplaced &ALLOW-OTHER-KEYS in ~
88 state :allow-other-keys))
90 (when (member state '(:rest :more-context :more-count))
91 (compiler-error "misplaced &AUX in lambda list: ~S" list))
93 ;; FIXME: I don't think ANSI says this is an error. (It
94 ;; should certainly be good for a STYLE-WARNING,
97 (compiler-error "unknown &KEYWORD in lambda list: ~S" arg)))
99 (:required (required arg))
100 (:optional (optional arg))
106 (setq more-context arg
114 (compiler-error "found garbage in lambda list when expecting ~
118 (values (required) (optional) restp rest keyp (keys) allowp (aux)
119 morep more-context more-count))))
121 (/show0 "parse-lambda-list.lisp end of file")