cl-specs.el 14 KB

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