Initial Commit
[packages] / xemacs-packages / edebug / cl-specs.el
1 ;;; cl-specs.el --- Edebug specs for cl.el
2
3 ;; Copyright (C) 1993, 2003  Free Software Foundation, Inc.
4 ;; Copyright (C) 2002 Ben Wing.
5 ;; Author: Daniel LaLiberte <liberte@holonexus.org>
6 ;; Keywords: lisp, tools, maint
7
8 ;; LCD Archive Entry:
9 ;; cl-specs.el|Daniel LaLiberte|liberte@holonexus.org
10 ;; |Edebug specs for cl.el
11
12 ;; This file is part of XEmacs.
13
14 ;; XEmacs is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; XEmacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
26 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 ;; 02111-1307, USA.
28
29 ;;; Synched up with: GNU Emacs 21.3.
30
31 ;;; Commentary:
32
33 ;; These specs are to be used with edebug.el version 3.3 or later and
34 ;; cl.el version 2.03 or later, by Dave Gillespie <daveg@synaptics.com>.
35
36 ;; This file need not be byte-compiled, but it shouldn't hurt.
37
38 ;;; Code:
39
40 (provide 'cl-specs)
41 ;; Do the above provide before the following require.
42 ;; Otherwise if you load this before edebug if cl is already loaded
43 ;; an infinite loading loop would occur.
44 (require 'edebug)
45
46 ;; Blocks
47
48 (def-edebug-spec block (symbolp body))
49 (def-edebug-spec return (&optional form))
50 (def-edebug-spec return-from (symbolp &optional form))
51
52 ;; Loops
53
54 (def-edebug-spec case (form &rest (sexp body)))
55 (def-edebug-spec ecase case)
56 (def-edebug-spec do
57   ((&rest &or symbolp (symbolp &optional form form))
58    (form body)
59    cl-declarations body))
60 (def-edebug-spec do* do)
61 (def-edebug-spec dolist
62   ((symbolp form &optional form) cl-declarations body))
63 (def-edebug-spec dotimes dolist)
64 (def-edebug-spec do-symbols
65   ((symbolp &optional form form) cl-declarations body))
66 (def-edebug-spec do-all-symbols
67   ((symbolp &optional form) cl-declarations body))
68
69 ;; Multiple values
70
71 (def-edebug-spec multiple-value-list (form))
72 (def-edebug-spec multiple-value-call (function-form body))
73 (def-edebug-spec multiple-value-bind
74   ((&rest symbolp) form cl-declarations body))
75 (def-edebug-spec multiple-value-setq ((&rest symbolp) form))
76 (def-edebug-spec multiple-value-prog1 (form body))
77
78 ;; Bindings
79
80 (def-edebug-spec lexical-let let)
81 (def-edebug-spec lexical-let* let)
82
83 (def-edebug-spec psetq setq)
84 (def-edebug-spec progv (form form body))
85
86 (def-edebug-spec flet ((&rest (defun*)) cl-declarations body))
87 (def-edebug-spec labels flet)
88
89 (def-edebug-spec macrolet
90   ((&rest (&define name (&rest arg) cl-declarations-or-string def-body))
91    cl-declarations body))
92
93 (def-edebug-spec symbol-macrolet
94   ((&rest (symbol sexp)) cl-declarations body))
95
96 ;; XEmacs change: Should look like inner macro lists, not outer ones,
97 ;; because &environment is not allowed. --ben
98 (def-edebug-spec destructuring-bind
99   (&define cl-macro-list1 form cl-declarations def-body))
100
101 ;; Setf
102
103 (def-edebug-spec setf (&rest [place form])) ;; sexp is not specific enough
104 (def-edebug-spec psetf setf)
105
106 (def-edebug-spec letf  ;; *not* available in Common Lisp
107   ((&rest (gate place &optional form))
108    body))
109 (def-edebug-spec letf* letf)
110
111
112 (def-edebug-spec defsetf
113   (&define name
114            [&or [symbolp &optional stringp]
115                 [cl-lambda-list (symbolp)]]
116            cl-declarations-or-string def-body))
117
118 (def-edebug-spec define-setf-method
119   (&define name cl-lambda-list cl-declarations-or-string def-body))
120
121 (def-edebug-spec define-modify-macro
122   (&define name cl-lambda-list ;; should exclude &key
123            symbolp &optional stringp))
124
125 (def-edebug-spec callf (function* place &rest form))
126 (def-edebug-spec callf2 (function* form place &rest form))
127
128 ;; Other operations on places
129
130 (def-edebug-spec remf (place form))
131
132 (def-edebug-spec incf (place &optional form))
133 (def-edebug-spec decf incf)
134 (def-edebug-spec push (form place))     ; different for CL
135 (def-edebug-spec pushnew
136   (form place &rest
137         &or [[&or ":test" ":test-not" ":key"] function-form]
138         [keywordp form]))
139 (def-edebug-spec pop (place))           ; different for CL
140
141 (def-edebug-spec shiftf (&rest place))  ;; really [&rest place] form
142 (def-edebug-spec rotatef (&rest place))
143
144
145 ;; Functions with function args.  These are only useful if the
146 ;; function arg is quoted with ' instead of function.
147
148 (def-edebug-spec some (function-form form &rest form))
149 (def-edebug-spec every some)
150 (def-edebug-spec notany some)
151 (def-edebug-spec notevery some)
152
153 ;; Mapping
154
155 (def-edebug-spec map (form function-form form &rest form))
156 (def-edebug-spec maplist (function-form form &rest form))
157 (def-edebug-spec mapc maplist)
158 (def-edebug-spec mapl maplist)
159 (def-edebug-spec mapcan maplist)
160 (def-edebug-spec mapcon maplist)
161
162 ;; Sequences
163
164 (def-edebug-spec reduce (function-form form &rest form))
165
166 ;; Types and assertions
167
168 (def-edebug-spec cl-type-spec (sexp)) ;; not worth the trouble to specify, yet.
169
170 (def-edebug-spec deftype defmacro*)
171 (def-edebug-spec check-type (place cl-type-spec &optional stringp))
172 ;; (def-edebug-spec assert (form &optional form stringp &rest form))
173 (def-edebug-spec assert (form &rest form))
174 (def-edebug-spec typecase (form &rest ([&or cl-type-spec "otherwise"] body)))
175 (def-edebug-spec etypecase typecase)
176
177 (def-edebug-spec ignore-errors t)
178
179 ;; Time of Evaluation
180
181 (def-edebug-spec eval-when
182   ((&rest &or "compile" "load" "eval") body))
183 (def-edebug-spec load-time-value (form &optional &or "t" "nil"))
184
185 ;; Declarations
186
187 (def-edebug-spec cl-decl-spec
188   ((symbolp &rest sexp)))
189
190 (def-edebug-spec cl-declarations
191   (&rest ("declare" &rest cl-decl-spec)))
192
193 (def-edebug-spec cl-declarations-or-string
194   (&or stringp cl-declarations))
195
196 (def-edebug-spec declaim (&rest cl-decl-spec))
197 (def-edebug-spec declare (&rest cl-decl-spec))  ;; probably not needed.
198 (def-edebug-spec locally (cl-declarations &rest form))
199 (def-edebug-spec the (cl-type-spec form))
200
201 ;;======================================================
202 ;; Lambda things
203
204 (def-edebug-spec cl-lambda-list
205   (([&rest arg]
206     [&optional ["&optional" cl-&optional-arg &rest cl-&optional-arg]]
207     [&optional ["&rest" arg]]
208     [&optional ["&key" [cl-&key-arg &rest cl-&key-arg]
209                 &optional "&allow-other-keys"]]
210     [&optional ["&aux" &rest
211                 &or (symbolp &optional def-form) symbolp]]
212     )))
213
214 (def-edebug-spec cl-&optional-arg
215   (&or (arg &optional def-form arg) arg))
216
217 (def-edebug-spec cl-&key-arg
218   (&or ([&or (symbolp arg) arg] &optional def-form arg) arg))
219
220 ;; The lambda list for macros is different from that of normal lambdas.
221 ;; Note that &environment is only allowed as first or last items in the
222 ;; top level list.
223
224 ;; XEmacs change.  #### In fact, CLTL2 says &environment can occur anywhere
225 ;; in the list.  The list can also be dotted.  Yuck, &environment can occur
226 ;; only once, even though anywhere in the list -- how do I encode that? 
227 ;; Also had to add the &or and separate; otherwise dotted specs were
228 ;; causing errors.  --ben
229
230 (def-edebug-spec cl-macro-list
231   (&or
232    ([&optional "&environment" arg]
233     [&optional "&whole" arg]
234     [&optional "&environment" arg]
235     [&rest cl-macro-arg]
236     . [&or arg nil])
237
238    ([&optional "&environment" arg]
239     [&optional "&whole" arg]
240     [&optional "&environment" arg]
241     [&rest cl-macro-arg]
242     [&optional "&environment" arg]
243     [&optional ["&optional" &rest 
244                 &or (cl-macro-arg &optional def-form cl-macro-arg) arg]]
245     [&optional "&environment" arg]
246     [&optional [[&or "&rest" "&body"] cl-macro-arg]]
247     [&optional "&environment" arg]
248     [&optional ["&key" [&rest
249                         [&or ([&or (symbolp cl-macro-arg) arg]
250                               &optional def-form cl-macro-arg)
251                              arg]]
252                 &optional "&allow-other-keys"]]
253     [&optional "&environment" arg]
254     [&optional ["&aux" &rest
255                 &or (symbolp &optional def-form) symbolp]]
256     [&optional "&environment" arg]
257     )))
258
259 (def-edebug-spec cl-macro-arg
260   (&or arg cl-macro-list1))
261
262 (def-edebug-spec cl-macro-list1
263   (&or
264    ([&optional "&whole" arg]
265     [&rest cl-macro-arg]
266     . [&or arg nil])
267
268    ([&optional "&whole" arg]
269     [&rest cl-macro-arg]
270     [&optional ["&optional" &rest
271                 &or (cl-macro-arg &optional def-form cl-macro-arg) arg]]
272     [&optional [[&or "&rest" "&body"] cl-macro-arg]]
273     [&optional ["&key" [&rest
274                         [&or ([&or (symbolp cl-macro-arg) arg]
275                               &optional def-form cl-macro-arg)
276                              arg]]
277                 &optional "&allow-other-keys"]]
278     [&optional ["&aux" &rest
279                 &or (symbolp &optional def-form) symbolp]]
280     )))
281
282
283 (def-edebug-spec defun*
284   ;; Same as defun but use cl-lambda-list.
285   (&define [&or name
286                 ("setf" :name setf name)]
287            cl-lambda-list
288            cl-declarations-or-string
289            [&optional ("interactive" interactive)]
290            def-body))
291 (def-edebug-spec defsubst* defun*)
292
293 (def-edebug-spec defmacro*
294   (&define name cl-macro-list cl-declarations-or-string def-body))
295 (def-edebug-spec define-compiler-macro defmacro*)
296
297
298 (def-edebug-spec function*
299   (&or symbolp cl-lambda-expr))
300
301 (def-edebug-spec cl-lambda-expr
302   (&define ("lambda" cl-lambda-list
303             ;;cl-declarations-or-string
304             ;;[&optional ("interactive" interactive)]
305             def-body)))
306
307 ;; Redefine function-form to also match function*
308 (def-edebug-spec function-form
309   ;; form at the end could also handle "function",
310   ;; but recognize it specially to avoid wrapping function forms.
311   (&or ([&or "quote" "function"] &or symbolp lambda-expr)
312        ("function*" function*)
313        form))
314
315 ;;======================================================
316 ;; Structures
317 ;; (def-edebug-spec defstruct (&rest sexp)) would be sufficient, but...
318
319 ;; defstruct may contain forms that are evaluated when a structure is created.
320 (def-edebug-spec defstruct
321   (&define  ; makes top-level form not be wrapped
322    [&or symbolp
323         (gate
324          symbolp &rest
325                  (&or [":conc-name" &or stringp "nil"]
326                       [":constructor" symbolp &optional cl-lambda-list]
327                       [":copier" symbolp]
328                       [":predicate" symbolp]
329                       [":include" symbolp &rest sexp];; not finished
330                       ;; The following are not supported.
331                       ;; [":print-function" ...]
332                       ;; [":type" ...]
333                       ;; [":initial-offset" ...]
334                       ))]
335    [&optional stringp]
336    ;; All the above is for the following def-form.
337    &rest &or symbolp (symbolp def-form &optional ":read-only" sexp)))
338
339 ;;======================================================
340 ;; Loop
341
342 ;; The loop macro is very complex, and a full spec is found below.
343 ;; The following spec only minimally specifies that
344 ;; parenthesized forms are executable, but single variables used as
345 ;; expressions will be missed.  You may want to use this if the full
346 ;; spec causes problems for you.
347
348 (def-edebug-spec loop
349   (&rest &or symbolp form))
350
351 ;; Below is a complete spec for loop, in several parts that correspond
352 ;; to the syntax given in CLtL2.  The specs do more than specify where
353 ;; the forms are; it also specifies, as much as Edebug allows, all the
354 ;; syntactically legal loop clauses.  The disadvantage of this
355 ;; completeness is rigidity, but the "for ... being" clause allows
356 ;; arbitrary extensions of the form: [symbolp &rest &or symbolp form].
357
358 (def-edebug-spec loop
359   ([&optional ["named" symbolp]]
360    [&rest
361     &or
362     ["repeat" form]
363     loop-for-as
364     loop-with
365     loop-initial-final]
366    [&rest loop-clause]
367    ))
368
369 (def-edebug-spec loop-with
370   ("with" loop-var
371    loop-type-spec
372    [&optional ["=" form]]
373    &rest ["and" loop-var
374           loop-type-spec
375           [&optional ["=" form]]]))
376
377 (def-edebug-spec loop-for-as
378   ([&or "for" "as"] loop-for-as-subclause
379    &rest ["and" loop-for-as-subclause]))
380
381 (def-edebug-spec loop-for-as-subclause
382   (loop-var
383    loop-type-spec
384    &or
385    [[&or "in" "on" "in-ref" "across-ref"]
386     form &optional ["by" function-form]]
387
388    ["=" form &optional ["then" form]]
389    ["across" form]
390    ["being"
391     [&or "the" "each"]
392     &or
393     [[&or "element" "elements"]
394      [&or "of" "in" "of-ref"] form
395      &optional "using" ["index" symbolp]];; is this right?
396     [[&or "hash-key" "hash-keys"
397           "hash-value" "hash-values"]
398      [&or "of" "in"]
399      hash-table-p &optional ["using" ([&or "hash-value" "hash-values"
400                                            "hash-key" "hash-keys"] sexp)]]
401
402     [[&or "symbol" "present-symbol" "external-symbol"
403           "symbols" "present-symbols" "external-symbols"]
404      [&or "in" "of"] package-p]
405
406     ;; Extensions for Emacs Lisp, including Lucid Emacs.
407     [[&or "frame" "frames"
408           "screen" "screens"
409           "buffer" "buffers"]]
410
411     [[&or "window" "windows"]
412      [&or "of" "in"] form]
413
414     [[&or "overlay" "overlays"
415           "extent" "extents"]
416      [&or "of" "in"] form
417      &optional [[&or "from" "to"] form]]
418
419     [[&or "interval" "intervals"]
420      [&or "in" "of"] form
421      &optional [[&or "from" "to"] form]
422      ["property" form]]
423
424     [[&or "key-code" "key-codes"
425           "key-seq" "key-seqs"
426           "key-binding" "key-bindings"]
427      [&or "in" "of"] form
428      &optional ["using" ([&or "key-code" "key-codes"
429                               "key-seq" "key-seqs"
430                               "key-binding" "key-bindings"]
431                          sexp)]]
432     ;; For arbitrary extensions, recognize anything else.
433     [symbolp &rest &or symbolp form]
434     ]
435
436    ;; arithmetic - must be last since all parts are optional.
437    [[&optional [[&or "from" "downfrom" "upfrom"] form]]
438     [&optional [[&or "to" "downto" "upto" "below" "above"] form]]
439     [&optional ["by" form]]
440     ]))
441
442 (def-edebug-spec loop-initial-final
443   (&or ["initially"
444         ;; [&optional &or "do" "doing"]  ;; CLtL2 doesn't allow this.
445         &rest loop-non-atomic-expr]
446        ["finally" &or
447         [[&optional &or "do" "doing"] &rest loop-non-atomic-expr]
448         ["return" form]]))
449
450 (def-edebug-spec loop-and-clause
451   (loop-clause &rest ["and" loop-clause]))
452
453 (def-edebug-spec loop-clause
454   (&or
455    [[&or "while" "until" "always" "never" "thereis"] form]
456
457    [[&or "collect" "collecting"
458          "append" "appending"
459          "nconc" "nconcing"
460          "concat" "vconcat"] form
461          [&optional ["into" loop-var]]]
462
463    [[&or "count" "counting"
464          "sum" "summing"
465          "maximize" "maximizing"
466          "minimize" "minimizing"] form
467          [&optional ["into" loop-var]]
468          loop-type-spec]
469
470    [[&or "if" "when" "unless"]
471     form loop-and-clause
472     [&optional ["else" loop-and-clause]]
473     [&optional "end"]]
474
475    [[&or "do" "doing"] &rest loop-non-atomic-expr]
476
477    ["return" form]
478    loop-initial-final
479    ))
480
481 (def-edebug-spec loop-non-atomic-expr
482   ([&not atom] form))
483
484 (def-edebug-spec loop-var
485   ;; The symbolp must be last alternative to recognize e.g. (a b . c)
486   ;; loop-var =>
487   ;; (loop-var . [&or nil loop-var])
488   ;; (symbolp . [&or nil loop-var])
489   ;; (symbolp . loop-var)
490   ;; (symbolp . (symbolp . [&or nil loop-var]))
491   ;; (symbolp . (symbolp . loop-var))
492   ;; (symbolp . (symbolp . symbolp)) == (symbolp symbolp . symbolp)
493   (&or (loop-var . [&or nil loop-var]) [gate symbolp]))
494
495 (def-edebug-spec loop-type-spec
496   (&optional ["of-type" loop-d-type-spec]))
497
498 (def-edebug-spec loop-d-type-spec
499   (&or (loop-d-type-spec . [&or nil loop-d-type-spec]) cl-type-spec))
500
501 ;;; arch-tag: b29aa3c2-cf67-4af8-9ee1-318fea61b478
502 ;;; cl-specs.el ends here