annotate lisp/edebug/cl-read.el-19.15-b1 @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;; Customizable, Common Lisp like reader for Emacs Lisp.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993 by Guido Bosch <Guido.Bosch@loria.fr>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; This file is written in GNU Emacs Lisp, but not (yet) part of GNU Emacs.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
6
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 ;; The software contained in this file is free software; you can
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8 ;; redistribute it and/or modify it under the terms of the GNU General
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; Public License as published by the Free Software Foundation; either
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10 ;; version 2, or (at your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15 ;; GNU General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; Please send bugs and comments to the author.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; <DISCLAIMER>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25 ;; This program is still under development. Neither the author nor
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26 ;; his employer accepts responsibility to anyone for the consequences of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27 ;; using it or for whether it serves any particular purpose or works
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 ;; at all.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31 ;; Introduction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;; ------------
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34 ;; This package replaces the standard Emacs Lisp reader (implemented
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 ;; as a set of built-in Lisp function in C) by a flexible and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 ;; customizable Common Lisp like one (implemented entirely in Emacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 ;; Lisp). During reading of Emacs Lisp source files, it is about 40%
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 ;; slower than the built-in reader, but there is no difference in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39 ;; loading byte compiled files - they dont contain any syntactic sugar
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 ;; and are loaded with the built in subroutine `load'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 ;; The user level functions for defining read tables, character and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 ;; dispatch macros are implemented according to the Commom Lisp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 ;; specification by Steel's (2nd edition), but the read macro functions
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 ;; themselves are implemented in a slightly different way, because the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 ;; basic character reading is done in an Emacs buffer, and not by
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 ;; using the primitive functions `read-char' and `unread-char', as real
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 ;; CL does. To get 100% compatibility with CL, the above functions
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 ;; (or their equivalents) must be implemented as subroutines.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 ;; Another difference with real CL reading is that basic tokens (symbols
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 ;; numbers, strings, and a few more) are still read by the original
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 ;; built-in reader. This is necessary to get reasonable performance.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54 ;; As a consquence, the read syntax of basic tokens can't be
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 ;; customized.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 ;; Most of the built-in reader syntax has been replaced by lisp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58 ;; character macros: parentheses and brackets, simple and double
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59 ;; quotes, semicolon comments and the dot. In addition to that, the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 ;; following new syntax features are provided:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62 ;; Backquote-Comma-Atsign Macro: `(,el ,@list)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 ;; (the clumsy Emacs Lisp syntax (` ((, el) (,@ list))) is also
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 ;; supported, but with one restriction: the blank behind the quote
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 ;; characters is mandatory when using the old syntax. The cl reader
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 ;; needs it as a landmark to distinguish between old and new syntax.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68 ;; An example:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 ;; With blanks, both readers read the same:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 ;; (` (, (head)) (,@ (tail))) -std-read-> (` (, (head)) (,@ (tail)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 ;; (` (, (head)) (,@ (tail))) -cl-read-> (` (, (head)) (,@ (tail)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74 ;; Without blanks, the form is interpreted differently by the two readers:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 ;; (`(,(head)) (,@(tail))) -std-read-> (` (, (head)) (,@ (tail)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 ;; (`(,(head)) (,@(tail))) -cl-read-> ((` ((, ((head)))) ((,@ ((tail)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 ;; Dispatch Character Macro" `#'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 ;; #'<function> function quoting
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 ;; #\<charcter> character syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83 ;; #.<form> read time evaluation
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84 ;; #p<path>, #P<path> paths
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 ;; #+<feature>, #-<feature> conditional reading
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 ;; #<n>=, #<n># tags for shared structure reading
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 ;; Other read macros can be added easily (see the definition of the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 ;; above ones in this file, using the functions `set-macro-character'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 ;; and `set-dispatch-macro-character')
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 ;; The Cl reader is mostly downward compatile, (exception: backquote
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 ;; comma macro, see above). E.g., this file, which is written entirely
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 ;; in the standard Emacs Lisp syntax, can be read and compiled with the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 ;; cl-reader activated (see Examples below).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 ;; This also works with package.el for Common Lisp packages.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 ;; Requirements
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 ;; ------------
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 ;; The package runs on Emacs 18 and Emacs 19 (FSF and Lucid) It is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 ;; built on top of Dave Gillespie's cl.el package (version 2.02 or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 ;; later). The old one (from Ceazar Quiroz, still shiped with some
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 ;; Emacs 19 disributions) will not do.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 ;; Usage
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 ;; -----
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 ;; The package is implemented as a kind of minor mode to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 ;; emacs-lisp-mode. As most of the Emacs Lisp files are still written
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 ;; in the standard Emacs Lisp syntax, the cl reader is only activated
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 ;; on elisp files whose property lines contain the following entry:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 ;; -*- Read-Syntax: Common-Lisp -*-
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 ;; Note that both property name ("Read-Syntax") and value
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 ;; ("Common-Lisp") are not case sensitive. There can also be other
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 ;; properties in this line:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 ;; -*- Mode: Emacs-Lisp; Read-Syntax: Common-Lisp -*-
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 ;; Installation
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 ;; ------------
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 ;; Save this file in a directory where Emacs will find it, then
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 ;; byte compile it (M-x byte-compile-file).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 ;; A permanent installation of the package can be done in two ways:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 ;; 1.) If you want to have the package always loaded, put this in your
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 ;; .emacs, or in just the files that require it:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 ;; (require 'cl-read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 ;; 2.) To load the cl-read package automatically when visiting an elisp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 ;; file that needs it, it has to be installed using the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 ;; emacs-lisp-mode-hook. In this case, put the following function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 ;; definition and add-hook form in your .emacs:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 ;; (defun cl-reader-autoinstall-function ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 ;; "Activates the Common Lisp style reader for emacs-lisp-mode buffers,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 ;; if the property line has a local variable setting like this:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142 ;; \;\; -*- Read-Syntax: Common-Lisp -*-"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 ;; (or (boundp 'local-variable-hack-done)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 ;; (let (local-variable-hack-done
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 ;; (case-fold-search t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147 ;; (hack-local-variables-prop-line 't)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 ;; (cond
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 ;; ((and (boundp 'read-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 ;; read-syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 ;; (string-match "^common-lisp$" (symbol-name read-syntax)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 ;; (require 'cl-read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 ;; (make-local-variable 'cl-read-active)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 ;; (setq cl-read-active 't))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 ;; (add-hook 'emacs-lisp-mode-hook 'cl-reader-autoinstall-function)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 ;; The `cl-reader-autoinstall-function' function tests for the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159 ;; presence of the correct Read-Syntax property in the first line of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 ;; the file and loads the cl-read package if necessary. cl-read
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 ;; replaces the following standard elisp functions:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
162 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
163 ;; - read
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164 ;; - read-from-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 ;; - eval-current-buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
166 ;; - eval-buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
167 ;; - eval-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
168 ;; - eval-expression (to call reader explicitly)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
169 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
170 ;; There may be other built-in functions that need to be replaced
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
171 ;; (e.g. load). The behavior of the new reader function depends on
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
172 ;; the value of the buffer local variable `cl-read-active': if it is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
173 ;; nil, they just call the original functions, otherwise they call the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
174 ;; cl reader. If the cl reader is active in a buffer, this is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
175 ;; indicated in the modeline by the string "CL" (minor mode like).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
176 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
177
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
178 ;; Examples:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
179 ;; ---------
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
180 ;; After having installed the package as described above, the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
181 ;; following forms can be evaluated (M-C-x) with the cl reader being
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
182 ;; active. (make sure that the mode line displays "(Emacs-Lisp CL)")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
183 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
184 ;; (setq whitespaces '(#\space #\newline #\tab))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
185 ;; (setq more-whitespaces `(#\page ,@whitespaces #\linefeed))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
186 ;; (setq whitespace-strings (mapcar #'char-to-string more-whitespaces))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
187 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
188 ;; (setq shared-struct '(#1=[hello world] #1# #1#))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
189 ;; (progn (setq cirlist '#1=(a b . #1#)) 't)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
190 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
191 ;; This file, though written in standard Emacs Lisp syntax, can also be
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
192 ;; compiled with the cl reader active: Type M-x byte-compile-file
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
193
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
194 ;; TO DO List:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
195 ;; -----------
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
196 ;; - Provide a replacement for load so that uncompiled cl syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
197 ;; source file can be loaded, too. For now prohibit loading un-bytecompiled.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
198 ;; - Do we really need the (require 'cl) dependency? Yes.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
199 ;; - More read macros: #S for structs, #A for array, #X for hex, #nR for radix
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
200 ;; - Refine the error signaling mechanism.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
201 ;; - invalid-cl-read-syntax is now defined. what else?
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
202
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
203
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
204 ; Change History
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
205 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
206 ; $Log: cl-read.el-19.15-b1,v $
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
207 ; Revision 1.1.1.1 1996/12/18 03:54:31 steve
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
208 ; XEmacs 19.15-b3
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
209 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
210 ; Revision 1.19 94/03/21 19:59:24 liberte
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
211 ; Add invalid-cl-read-syntax error symbol.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
212 ; Add reader::read-sexp and reader::read-sexp-func to allow customization
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
213 ; based on the results of reading.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
214 ; Remove more dependencies on cl-package.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
215 ; Remove reader::eval-current-buffer, eval-buffer, and eval-region,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
216 ; and use elisp-eval-region package instead.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
217 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
218 ; Revision 1.18 94/03/04 23:42:24 liberte
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
219 ; Fix typos in comments.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
220 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
221 ; Revision 1.17 93/11/24 12:04:09 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
222 ; cl-packages dependency removed. `reader::read-constituent' and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
223 ; corresponding variables moved to cl-packages.el.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
224 ; Multi-line comment #| ... |# dispatch character read macro added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
225 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
226 ; Revision 1.16 1993/11/23 10:21:02 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
227 ; Patches from Daniel LaLiberte integrated.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
228 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
229 ; Revision 1.15 1993/11/18 21:21:10 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
230 ; `reader::symbol-regexp1' modified.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
231 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
232 ; Revision 1.14 1993/11/17 19:06:32 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
233 ; More characters added to `reader::symbol-characters'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
234 ; `reader::read-constituent' modified.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
235 ; defpackage form added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
236 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
237 ; Revision 1.13 1993/11/16 13:06:41 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
238 ; - Symbol reading for CL package convention implemented.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
239 ; Variables `reader::symbol-characters', `reader::symbol-regexp1' and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
240 ; `reader::symbol-regexp2' and functions `reader::lookup-symbol' and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
241 ; `reader::read-constituent' added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
242 ; - Prefix for internal symbols is now "reader::" (Common Lisp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
243 ; compatible).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
244 ; - Dispatch character macro #: for reading uninterned symbols added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
245 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
246 ; Revision 1.12 1993/11/07 19:29:07 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
247 ; Minor bug fix.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
248 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
249 ; Revision 1.11 1993/11/07 19:23:59 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
250 ; Comment added. Character read macro #\<char> rewritten. Now reads
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
251 ; e.g. #\meta-control-x. Needs to be checked.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
252 ; fix in `reader::restore-shared-structure'. `cl-reader-autoinstall-function' improved.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
253 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
254 ; Revision 1.10 1993/11/06 18:35:35 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
255 ; Included Daniel LaLiberte's Patches.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
256 ; Efficiency of `reader::restore-shared-structure' improved.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
257 ; Implementation notes for shared structure reading added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
258 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
259 ; Revision 1.9 1993/09/08 07:44:54 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
260 ; Comment modified.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
261 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
262 ; Revision 1.8 1993/08/10 13:43:34 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
263 ; Hook function `cl-reader-autoinstall-function' for automatic installation added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
264 ; Buffer local variable `cl-read-active' added: together with the above
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
265 ; hook it allows the file specific activation of the cl reader.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
266 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
267 ; Revision 1.7 1993/08/10 10:35:21 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
268 ; Functions `read*' and `read-from-string*' renamed into `reader::read'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
269 ; and `reader::read-from-string'. Whitespace character skipping after
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
270 ; recursive reader calls removed (Emacs 19 should not need this).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
271 ; Functions `cl-reader-install' and `cl-reader-uninstall' updated.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
272 ; Introduction text and function comments added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
273 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
274 ; Revision 1.6 1993/08/09 15:36:05 bosch Function `read*' now nearly
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
275 ; elisp compatible (no functions as streams, yet -- I don't think I
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
276 ; will ever implement this, it would be far too slow). Elisp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
277 ; compatible function `read-from-string*' added. Replacements for
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
278 ; `eval-current-buffer', `eval-buffer' and `eval-region' added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
279 ; Renamed feature `cl-dg' in `cl', as Dave Gillespie's cl.el package
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
280 ; is rather stable now. Function `cl-reader-install' and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
281 ; `cl-reader-uninstall' modified.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
282 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
283 ; Revision 1.5 1993/08/09 10:23:35 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
284 ; Functions `copy-readtable' and `set-syntax-from-character' added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
285 ; Variable `reader::internal-standard-readtable' added. Standard
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
286 ; readtable initialization modified. Whitespace skipping placed back
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
287 ; inside the read loop.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
288 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
289 ; Revision 1.4 1993/05/14 13:00:48 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
290 ; Included patches from Daniel LaLiberte.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
291 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
292 ; Revision 1.3 1993/05/11 09:57:39 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
293 ; `read*' renamed in `reader::read-from-buffer'. `read*' now can read
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
294 ; from strings.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
295 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
296 ; Revision 1.2 1993/05/09 16:30:50 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
297 ; (require 'cl-read) added.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
298 ; Calling of `{before,after}-read-hook' modified.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
299 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
300 ; Revision 1.1 1993/03/29 19:37:21 bosch
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
301 ; Initial revision
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
302 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
303 ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
304
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
305 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
306 (require 'cl)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
307
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
308 (provide 'cl-read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
309 ;; load before compiling
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
310 (require 'cl-read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
311
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
312 ;; bootstrapping with cl-packages
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
313 ;; defpackage and in-package are ignored until cl-read is installed.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
314 '(defpackage reader
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
315 (:nicknames "rd")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
316 (:use el)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
317 (:export
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
318 cl-read-active
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
319 copy-readtable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
320 set-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
321 get-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
322 set-syntax-from-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
323 make-dispatch-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
324 set-dispatch-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
325 get-dispatch-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
326 before-read-hook
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
327 after-read-hook
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
328 cl-reader-install
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
329 cl-reader-uninstall
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
330 read-syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
331 cl-reader-autoinstall-function))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
332
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
333 '(in-package reader)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
334
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
335
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
336 (autoload 'compiled-function-p "bytecomp")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
337
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
338 ;; This makes cl-read behave as a kind of minor mode:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
339
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
340 (make-variable-buffer-local 'cl-read-active)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
341 (defvar cl-read-active nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
342 "Buffer local variable that enables Common Lisp style syntax reading.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
343 (setq-default cl-read-active nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
344
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
345 (or (assq 'cl-read-active minor-mode-alist)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
346 (setq minor-mode-alist
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
347 (cons '(cl-read-active " CL") minor-mode-alist)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
348
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
349 ;; Define a new error symbol: invalid-cl-read-syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
350 ;; XEmacs change
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
351 (define-error 'invalid-cl-read-syntax "Invalid CL read syntax"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
352 'invalid-read-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
353
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
354 (defun reader::error (msg &rest args)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
355 (signal 'invalid-cl-read-syntax (list (apply 'format msg args))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
356
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
357
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
358 ;; The readtable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
359
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
360 (defvar reader::readtable-size 256
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
361 "The size of a readtable."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
362 ;; Actually, the readtable is a vector of size (1+
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
363 ;; reader::readtable-size), because the last element contains the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
364 ;; symbol `readtable', used for defining `readtablep.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
365 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
366
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
367 ;; An entry of the readtable must have one of the following forms:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
368 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
369 ;; 1. A symbol, one of {illegal, constituent, whitespace}. It means
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
370 ;; the character's reader class.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
371 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
372 ;; 2. A function (i.e., a symbol with a function definition, a byte
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
373 ;; compiled function or an uncompiled lambda expression). It means the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
374 ;; character is a macro character.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
375 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
376 ;; 3. A vector of length `reader::readtable-size'. Elements of this vector
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
377 ;; may be `nil' or a function (see 2.). It means the charater is a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
378 ;; dispatch character, and the vector its dispatch fucntion table.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
379
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
380 (defvar *readtable*)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
381 (defvar reader::internal-standard-readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
382
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
383 (defun* copy-readtable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
384 (&optional (from-readtable *readtable*)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
385 (to-readtable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
386 (make-vector (1+ reader::readtable-size) 'illegal)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
387 "Return a copy of FROM-READTABLE \(default: *readtable*\). If the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
388 FROM-READTABLE argument is provided as `nil', make a copy of a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
389 standard \(CL-like\) readtable. If TO-READTABLE is provided, modify and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
390 return it, otherwise create a new readtable object."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
391
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
392 (if (null from-readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
393 (setq from-readtable reader::internal-standard-readtable))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
394
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
395 (loop for i to reader::readtable-size
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
396 as from-syntax = (aref from-readtable i)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
397 do (setf (aref to-readtable i)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
398 (if (vectorp from-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
399 (copy-sequence from-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
400 from-syntax))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
401 finally return to-readtable))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
402
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
403
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
404 (defmacro reader::get-readtable-entry (char readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
405 (` (aref (, readtable) (, char))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
406
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
407 (defun set-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
408 (char function &optional readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
409 "Makes CHAR to be a macro character with FUNCTION as handler.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
410 When CHAR is seen by reader::read-from-buffer, it calls FUNCTION.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
411 Returns always t. Optional argument READTABLE is the readtable to set
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
412 the macro character in (default: *readtable*)."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
413 (or readtable (setq readtable *readtable*))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
414 (or (reader::functionp function)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
415 (reader::error "Not valid character macro function: %s" function))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
416 (setf (reader::get-readtable-entry char readtable) function)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
417 t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
418
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
419
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
420 (put 'set-macro-character 'edebug-form-spec
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
421 '(&define sexp function-form &optional sexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
422 (put 'set-macro-character 'lisp-indent-function 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
423
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
424 (defun get-macro-character (char &optional readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
425 "Return the function associated with the character CHAR.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
426 Optional READTABLE defaults to *readtable*. If char isn't a macro
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
427 character in READTABLE, return nil."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
428 (or readtable (setq readtable *readtable*))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
429 (let ((entry (reader::get-readtable-entry char readtable)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
430 (if (reader::functionp entry)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
431 entry)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
432
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
433 (defun set-syntax-from-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
434 (to-char from-char &optional to-readtable from-readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
435 "Make the syntax of TO-CHAR be the same as the syntax of FROM-CHAR.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
436 Optional TO-READTABLE and FROM-READTABLE are the corresponding tables
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
437 to use. TO-READTABLE defaults to the current readtable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
438 \(*readtable*\), and FROM-READTABLE to nil, meaning to use the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
439 syntaxes from the standard Lisp Readtable."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
440 (or to-readtable (setq to-readtable *readtable*))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
441 (or from-readtable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
442 (setq from-readtable reader::internal-standard-readtable))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
443 (let ((from-syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
444 (reader::get-readtable-entry from-char from-readtable)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
445 (if (vectorp from-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
446 ;; dispatch macro character table
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
447 (setq from-syntax (copy-sequence from-syntax)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
448 (setf (reader::get-readtable-entry to-char to-readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
449 from-syntax))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
450 t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
451
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
452
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
453 ;; Dispatch macro character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
454 (defun make-dispatch-macro-character (char &optional readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
455 "Let CHAR be a dispatch macro character in READTABLE (default: *readtable*)."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
456 (or readtable (setq readtable *readtable*))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
457 (setf (reader::get-readtable-entry char readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
458 ;; create a dispatch character table
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
459 (make-vector reader::readtable-size nil)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
460
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
461
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
462 (defun set-dispatch-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
463 (disp-char sub-char function &optional readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
464 "Make reading CHAR1 followed by CHAR2 be handled by FUNCTION.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
465 Optional argument READTABLE (default: *readtable*). CHAR1 must first be
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
466 made a dispatch char with `make-dispatch-macro-character'."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
467 (or readtable (setq readtable *readtable*))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
468 (let ((disp-table (reader::get-readtable-entry disp-char readtable)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
469 ;; check whether disp-char is a valid dispatch character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
470 (or (vectorp disp-table)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
471 (reader::error "`%c' not a dispatch macro character." disp-char))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
472 ;; check whether function is a valid function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
473 (or (reader::functionp function)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
474 (reader::error "Not valid dispatch character macro function: %s"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
475 function))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
476 (setf (aref disp-table sub-char) function)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
477
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
478 (put 'set-dispatch-macro-character 'edebug-form-spec
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
479 '(&define sexp sexp function-form &optional sexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
480 (put 'set-dispatch-macro-character 'lisp-indent-function 2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
481
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
482
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
483 (defun get-dispatch-macro-character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
484 (disp-char sub-char &optional readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
485 "Return the macro character function for SUB-CHAR unser DISP-CHAR.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
486 Optional READTABLE defaults to *readtable*.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
487 Returns nil if there is no such function."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
488 (or readtable (setq readtable *readtable*))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
489 (let ((disp-table (reader::get-readtable-entry disp-char readtable)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
490 (and (vectorp disp-table)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
491 (reader::functionp (aref disp-table sub-char))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
492 (aref disp-table sub-char))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
493
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
494
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
495 (defun reader::functionp (function)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
496 ;; Check whether FUNCTION is a valid function object to be used
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
497 ;; as (dispatch) macro character function.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
498 (or (and (symbolp function) (fboundp function))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
499 (compiled-function-p function)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
500 (and (consp function) (eq (first function) 'lambda))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
501
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
502
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
503 ;; The basic reader loop
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
504
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
505 ;; shared and circular structure reading
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
506 (defvar reader::shared-structure-references nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
507 (defvar reader::shared-structure-labels nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
508
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
509 (defun reader::read-sexp-func (point func)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
510 ;; This function is called to read a sexp at POINT by calling FUNC.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
511 ;; reader::read-sexp-func is here to be advised, e.g. by Edebug,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
512 ;; to do something before or after reading.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
513 (funcall func))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
514
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
515 (defmacro reader::read-sexp (point &rest body)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
516 ;; Called to return a sexp starting at POINT. BODY creates the sexp result
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
517 ;; and should leave point after the sexp. The body is wrapped in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
518 ;; a lambda expression and passed to reader::read-sexp-func.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
519 (` (reader::read-sexp-func (, point) (function (lambda () (,@ body))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
520
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
521 (put 'reader::read-sexp 'edebug-form-spec '(form body))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
522 (put 'reader::read-sexp 'lisp-indent-function 2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
523 (put 'reader::read-sexp 'lisp-indent-hook 1) ;; Emacs 18
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
524
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
525
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
526 (defconst before-read-hook nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
527 (defconst after-read-hook nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
528
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
529 ;; Set the hooks to `read-char' in order to step through the reader. e.g.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
530 ;; (add-hook 'before-read-hook '(lambda () (message "before") (read-char)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
531 ;; (add-hook 'after-read-hook '(lambda () (message "after") (read-char)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
532
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
533 (defmacro reader::encapsulate-recursive-call (reader-call)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
534 ;; Encapsulate READER-CALL, a form that contains a recursive call to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
535 ;; the reader, for usage inside the main reader loop. The macro
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
536 ;; wraps two hooks around READER-CALL: `before-read-hook' and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
537 ;; `after-read-hook'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
538 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
539 ;; If READER-CALL returns normally, the macro exits immediately from
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
540 ;; the surrounding loop with the value of READER-CALL as result. If
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
541 ;; it exits non-locally (with tag `reader-ignore'), it just returns
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
542 ;; the value of READER-CALL, in which case the surrounding reader
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
543 ;; loop continues its execution.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
544 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
545 ;; In both cases, `before-read-hook' and `after-read-hook' are
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
546 ;; called before and after executing READER-CALL.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
547 ;; Are there any other uses for these hooks? Edebug doesn't need them.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
548 (` (prog2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
549 (run-hooks 'before-read-hook)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
550 ;; this catch allows to ignore the return, in the case that
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
551 ;; reader::read-from-buffer should continue looping (e.g.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
552 ;; skipping over comments)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
553 (catch 'reader-ignore
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
554 ;; this only works inside a block (e.g., in a loop):
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
555 ;; go outside
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
556 (return
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
557 (prog1
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
558 (, reader-call)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
559 ;; this occurrence of the after hook fires if the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
560 ;; reader-call returns normally ...
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
561 (run-hooks 'after-read-hook))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
562 ;; ... and that one if it was thrown to the tag 'reader-ignore
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
563 (run-hooks 'after-read-hook))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
564
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
565 (put 'reader::encapsulate-recursive-call 'edebug-form-spec '(form))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
566 (put 'reader::encapsulate-recursive-call 'lisp-indent-function 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
567
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
568 (defun reader::read-from-buffer (&optional stream reader::recursive-p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
569 (or (bufferp stream)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
570 (reader::error "Sorry, can only read on buffers"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
571 (if (not reader::recursive-p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
572 ;; set up environment for shared structure reading
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
573 (let (reader::shared-structure-references
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
574 reader::shared-structure-labels
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
575 tmp-sexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
576 ;; the reader returns an unshared sexpr, possibly containing
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
577 ;; symbolic references
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
578 (setq tmp-sexp (reader::read-from-buffer stream 't))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
579 (if ;; sexpr actually contained shared structures
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
580 reader::shared-structure-references
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
581 (reader::restore-shared-structure tmp-sexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
582 ;; it did not, so don't bother about restoring
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
583 tmp-sexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
584
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
585 (loop for char = (following-char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
586 for entry = (reader::get-readtable-entry char *readtable*)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
587 if (eobp) do (reader::error "End of file during reading")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
588 do
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
589 (cond
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
590
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
591 ((eq entry 'illegal)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
592 (reader::error "`%c' has illegal character syntax" char))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
593
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
594 ;; skipping whitespace characters must be done inside this
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
595 ;; loop as character macro subroutines may return without
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
596 ;; leaving the loop using (throw 'reader-ignore ...)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
597 ((eq entry 'whitespace)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
598 (forward-char 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
599 ;; skip all whitespace
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
600 (while (eq 'whitespace
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
601 (reader::get-readtable-entry
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
602 (following-char) *readtable*))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
603 (forward-char 1)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
604
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
605 ;; for every token starting with a constituent character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
606 ;; call the built-in reader (symbols, numbers, strings,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
607 ;; characters with ?<char> syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
608 ((eq entry 'constituent)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
609 (reader::encapsulate-recursive-call
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
610 (reader::read-constituent stream)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
611
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
612 ((vectorp entry)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
613 ;; Dispatch macro character. The dispatch macro character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
614 ;; function is contained in the vector `entry', at the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
615 ;; place indicated by <sub-char>, the first non-digit
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
616 ;; character following the <disp-char>:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
617 ;; <disp-char><digit>*<sub-char>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
618 (reader::encapsulate-recursive-call
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
619 (loop initially do (forward-char 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
620 for sub-char = (prog1 (following-char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
621 (forward-char 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
622 while (memq sub-char
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
623 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
624 collect sub-char into digit-args
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
625 finally
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
626 (return
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
627 (funcall
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
628 ;; no test is done here whether a non-nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
629 ;; contents is a correct dispatch character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
630 ;; function to apply.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
631 (or (aref entry sub-char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
632 (reader::error
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
633 "Undefined subsequent dispatch character `%c'"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
634 sub-char))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
635 stream
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
636 sub-char
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
637 (string-to-int
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
638 (apply 'concat
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
639 (mapcar
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
640 'char-to-string digit-args))))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
641
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
642 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
643 ;; must be a macro character. In this case, `entry' is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
644 ;; the function to be called
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
645 (reader::encapsulate-recursive-call
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
646 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
647 (forward-char 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
648 (funcall entry stream char))))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
649
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
650
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
651 ;; Constituent reader fix for Emacs 18
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
652 (if (string-match "^19" emacs-version)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
653 (defun reader::read-constituent (stream)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
654 (reader::read-sexp (point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
655 (reader::original-read stream)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
656
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
657 (defun reader::read-constituent (stream)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
658 (reader::read-sexp (point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
659 (prog1 (reader::original-read stream)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
660 ;; For Emacs 18, backing up is necessary because the `read' function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
661 ;; reads one character too far after reading a symbol or number.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
662 ;; This doesnt apply to reading chars (e.g. ?n).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
663 ;; This still loses for escaped chars.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
664 (if (not (eq (reader::get-readtable-entry
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
665 (preceding-char) *readtable*) 'constituent))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
666 (forward-char -1))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
667
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
668
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
669 ;; Make the default current CL readtable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
670
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
671 (defconst *readtable*
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
672 (loop with raw-readtable =
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
673 (make-vector (1+ reader::readtable-size) 'illegal)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
674 initially do (setf (aref raw-readtable reader::readtable-size)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
675 'readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
676 for entry in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
677 '((constituent ?! ?@ ?$ ?% ?& ?* ?_ ?- ?+ ?= ?/ ?\\ ?0 ?1 ?2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
678 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?: ?~ ?> ?< ?a ?b
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
679 ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
680 ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z ?A ?B ?C ?D
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
681 ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
682 ?S ?T ?U ?V ?W ?X ?Y ?Z)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
683 (whitespace ? ?\t ?\n ?\r ?\f)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
684
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
685 ;; The following CL character classes are only useful for
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
686 ;; token parsing. We don't need them, as token parsing is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
687 ;; left to the built-in reader.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
688 ;; (single-escape ?\\)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
689 ;; (multiple-escape ?|)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
690 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
691 do
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
692 (loop for char in (rest entry)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
693 do (setf (reader::get-readtable-entry char raw-readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
694 (first entry)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
695 finally return raw-readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
696 "The current readtable.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
697
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
698
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
699 ;; Variables used non-locally in the standard readmacros
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
700 (defvar reader::context)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
701 (defvar reader::stack)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
702 (defvar reader::recursive-p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
703
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
704
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
705 ;;;; Read macro character definitions
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
706
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
707 ;;; Hint for modifying, testing and debugging new read macros: All the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
708 ;;; read macros and dispatch character macros below are defined in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
709 ;;; the `*readtable*'. Modifications or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
710 ;;; instrumenting with edebug are effective immediately without having to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
711 ;;; copy the internal readtable to the standard *readtable*. However,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
712 ;;; if you wish to modify reader::internal-standard-readtable, then
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
713 ;;; you must recopy *readtable*.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
714
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
715 ;; Chars and strings
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
716
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
717 ;; This is defined to distinguish chars from constituents
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
718 ;; since chars are read by the standard reader without reading too far.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
719 (set-macro-character ?\?
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
720 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
721 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
722 (forward-char -1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
723 (reader::read-sexp (point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
724 (reader::original-read stream)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
725
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
726 ;; ?\M-\C-a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
727
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
728 ;; This is defined to distinguish strings from constituents
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
729 ;; since backing up after reading a string is simpler.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
730 (set-macro-character ?\"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
731 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
732 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
733 (forward-char -1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
734 (reader::read-sexp (point)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
735 (prog1 (reader::original-read stream)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
736 ;; This is not needed with Emacs 19, but it is OK. See above.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
737 (if (/= (preceding-char) ?\")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
738 (forward-char -1)))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
739
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
740 ;; Lists and dotted pairs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
741 (set-macro-character ?\(
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
742 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
743 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
744 (reader::read-sexp (1- (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
745 (catch 'read-list
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
746 (let ((reader::context 'list) reader::stack )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
747 ;; read list elements up to a `.'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
748 (catch 'dotted-pair
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
749 (while t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
750 (setq reader::stack (cons (reader::read-from-buffer stream 't)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
751 reader::stack))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
752 ;; In dotted pair. Read one more element
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
753 (setq reader::stack (cons (reader::read-from-buffer stream 't)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
754 reader::stack)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
755 ;; signal it to the closing paren
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
756 reader::context 'dotted-pair)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
757 ;; Next char *must* be the closing paren that throws read-list
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
758 (reader::read-from-buffer stream 't)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
759 ;; otherwise an error is signalled
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
760 (reader::error "Illegal dotted pair read syntax")))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
761
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
762 (set-macro-character ?\)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
763 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
764 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
765 (cond ((eq reader::context 'list)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
766 (throw 'read-list (nreverse reader::stack)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
767 ((eq reader::context 'dotted-pair)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
768 (throw 'read-list (nconc (nreverse (cdr reader::stack))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
769 (car reader::stack))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
770 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
771 (reader::error "`)' doesn't end a list"))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
772
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
773 (set-macro-character ?\.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
774 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
775 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
776 (and (eq reader::context 'dotted-pair)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
777 (reader::error "No more than one `.' allowed in list"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
778 (throw 'dotted-pair nil))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
779
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
780 ;; '(#\a . #\b)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
781 ;; '(a . (b . c))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
782
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
783 ;; Vectors: [a b]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
784 (set-macro-character ?\[
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
785 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
786 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
787 (reader::read-sexp (1- (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
788 (let ((reader::context 'vector))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
789 (catch 'read-vector
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
790 (let ((reader::context 'vector)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
791 reader::stack)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
792 (while t (push (reader::read-from-buffer stream 't)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
793 reader::stack)))))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
794
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
795 (set-macro-character ?\]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
796 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
797 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
798 (if (eq reader::context 'vector)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
799 (throw 'read-vector (apply 'vector (nreverse reader::stack)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
800 (reader::error "`]' doesn't end a vector")))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
801
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
802 ;; Quote and backquote/comma macro
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
803 (set-macro-character ?\'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
804 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
805 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
806 (reader::read-sexp (1- (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
807 (list (reader::read-sexp (point) 'quote)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
808 (reader::read-from-buffer stream 't))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
809
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
810 (set-macro-character ?\`
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
811 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
812 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
813 (if (= (following-char) ?\ )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
814 ;; old backquote syntax. This is ambigous, because
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
815 ;; (`(sexp)) is a valid form in both syntaxes, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
816 ;; unfortunately not the same.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
817 ;; old syntax: read -> (` (sexp))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
818 ;; new syntax: read -> ((` (sexp)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
819 (reader::read-sexp (1- (point)) '\`)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
820 (reader::read-sexp (1- (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
821 (list (reader::read-sexp (point) '\`)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
822 (reader::read-from-buffer stream 't)))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
823
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
824 (set-macro-character ?\,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
825 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
826 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
827 (cond ((eq (following-char) ?\ )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
828 ;; old syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
829 (reader::read-sexp (point) '\,))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
830 ((eq (following-char) ?\@)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
831 (forward-char 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
832 (cond ((eq (following-char) ?\ )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
833 (reader::read-sexp (point) '\,\@))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
834 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
835 (reader::read-sexp (- (point) 2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
836 (list
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
837 (reader::read-sexp (point) '\,\@)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
838 (reader::read-from-buffer stream 't))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
839 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
840 (reader::read-sexp (1- (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
841 (list
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
842 (reader::read-sexp (1- (point)) '\,)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
843 (reader::read-from-buffer stream 't))))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
844
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
845 ;; 'a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
846 ;; '(a b c)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
847 ;; (let ((a 10) (b '(20 30))) `(,a ,@b c))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
848 ;; the old syntax is also supported:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
849 ;; (let ((a 10) (b '(20 30))) (` ((, a) (,@ b) c)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
850
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
851 ;; Single line character comment: ;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
852 (set-macro-character ?\;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
853 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
854 (lambda (stream char)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
855 (skip-chars-forward "^\n\r")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
856 (throw 'reader-ignore nil))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
857
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
858
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
859
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
860 ;; Dispatch character character #
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
861 (make-dispatch-macro-character ?\#)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
862
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
863 (defsubst reader::check-0-infix (n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
864 (or (= n 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
865 (reader::error "Numeric infix argument not allowed: %d" n)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
866
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
867
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
868 (defalias 'search-forward-regexp 're-search-forward)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
869
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
870 ;; nested multi-line comments #| ... |#
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
871 (set-dispatch-macro-character ?\# ?\|
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
872 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
873 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
874 (reader::check-0-infix n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
875 (let ((counter 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
876 (while (search-forward-regexp "#|\\||#" nil t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
877 (if (string-equal
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
878 (buffer-substring
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
879 (match-beginning 0) (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
880 "|#")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
881 (cond ((> counter 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
882 (decf counter))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
883 ((= counter 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
884 ;; stop here
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
885 (goto-char (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
886 (throw 'reader-ignore nil))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
887 ('t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
888 (reader::error "Unmatching closing multicomment")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
889 (incf counter)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
890 (reader::error "Unmatching opening multicomment")))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
891
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
892 ;; From cl-packages.el
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
893 (defconst reader::symbol-characters "[A-Za-z0-9-_!@$%^&*+=|~{}<>/]")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
894 (defconst reader::symbol-regexp2
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
895 (format "\\(%s+\\)" reader::symbol-characters))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
896
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
897 (set-dispatch-macro-character ?\# ?\:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
898 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
899 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
900 (reader::check-0-infix n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
901 (or (looking-at reader::symbol-regexp2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
902 (reader::error "Invalid symbol read syntax"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
903 (goto-char (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
904 (make-symbol
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
905 (buffer-substring (match-beginning 0) (match-end 0))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
906
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
907 ;; Function quoting: #'<function>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
908 (set-dispatch-macro-character ?\# ?\'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
909 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
910 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
911 (reader::check-0-infix n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
912 ;; Probably should test if cl is required by current buffer.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
913 ;; Currently, cl will always be a feature because cl-read requires it.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
914 (reader::read-sexp (- (point) 2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
915 (list
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
916 (reader::read-sexp (point) (if (featurep 'cl) 'function* 'function))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
917 (reader::read-from-buffer stream 't))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
918
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
919 ;; Character syntax: #\<char>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
920 ;; Not yet implemented: #\Control-a #\M-C-a etc.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
921 ;; This definition is not used - the next one is more general.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
922 '(set-dispatch-macro-character ?# ?\\
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
923 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
924 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
925 (reader::check-0-infix n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
926 (let ((next (following-char))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
927 name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
928 (if (not (and (<= ?a next) (<= next ?z)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
929 (progn (forward-char 1) next)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
930 (setq next (reader::read-from-buffer stream t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
931 (cond ((symbolp next) (setq name (symbol-name next)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
932 ((integerp next) (setq name (int-to-string next))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
933 (if (= 1 (length name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
934 (string-to-char name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
935 (case next
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
936 (linefeed ?\n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
937 (newline ?\r)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
938 (space ?\ )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
939 (rubout ?\b)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
940 (page ?\f)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
941 (tab ?\t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
942 (return ?\C-m)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
943 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
944 (reader::error "Unknown character specification `%s'"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
945 next))))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
946 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
947
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
948 (defvar reader::special-character-name-table
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
949 '(("linefeed" . ?\n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
950 ("newline" . ?\r)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
951 ("space" . ?\ )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
952 ("rubout" . ?\b)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
953 ("page" . ?\f)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
954 ("tab" . ?\t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
955 ("return" . ?\C-m)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
956
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
957 (set-dispatch-macro-character ?# ?\\
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
958 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
959 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
960 (reader::check-0-infix n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
961 (forward-char -1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
962 ;; We should read in a special package to avoid creating symbols.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
963 (let ((symbol (reader::read-from-buffer stream t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
964 (case-fold-search t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
965 name modifier character char-base)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
966 (setq name (symbol-name symbol))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
967 (if (string-match "^\\(meta-\\|m-\\|control-\\|c-\\)+" name)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
968 (setq modifier (substring name
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
969 (match-beginning 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
970 (match-end 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
971 character (substring name (match-end 1)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
972 (setq character name))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
973 (setq char-base
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
974 (cond ((= (length character) 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
975 (string-to-char character))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
976 ('t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
977 (cdr (assoc character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
978 reader::special-character-name-table)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
979 (or char-base
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
980 (reader::error
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
981 "Unknown character specification `%s'" character))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
982
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
983 (and modifier
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
984 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
985 (and (string-match "control-\\|c-" modifier)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
986 (decf char-base 32))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
987 (and (string-match "meta-\\|m-" modifier)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
988 (incf char-base 128))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
989 char-base))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
990
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
991 ;; '(#\meta-space #\tab #\# #\> #\< #\a #\A #\return #\space)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
992 ;; (eq #\m-tab ?\M-\t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
993 ;; (eq #\c-m-x #\m-c-x)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
994 ;; (eq #\Meta-Control-return #\M-C-return)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
995 ;; (eq #\m-m-c-c-x #\m-c-x)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
996 ;; #\C-space #\C-@ ?\C-@
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
997
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
998
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
999
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1000 ;; Read and load time evaluation: #.<form>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1001 ;; Not yet implemented: #,<form>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1002 (set-dispatch-macro-character ?\# ?\.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1003 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1004 (lambda (reader::stream reader::char reader::n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1005 (reader::check-0-infix reader::n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1006 ;; This eval will see all internal vars of reader,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1007 ;; e.g. stream, reader::recursive-p. Anything that might be bound.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1008 ;; We must use `read' here rather than read-from-buffer with 'recursive-p
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1009 ;; because the expression must not have unresolved #n#s in it anyway.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1010 ;; Otherwise the top-level expression must be completely read before
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1011 ;; any embedded evaluation(s) occur(s). CLtL2 does not specify this.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1012 ;; Also, call `read' so that it may be customized, by e.g. Edebug
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1013 (eval (read reader::stream)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1014 ;; '(#.(current-buffer) #.(get-buffer "*scratch*"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1015
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1016 ;; Path names (kind of): #p<string>, #P<string>,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1017 (set-dispatch-macro-character ?\# ?\P
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1018 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1019 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1020 (reader::check-0-infix n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1021 (let ((string (reader::read-from-buffer stream 't)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1022 (or (stringp string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1023 (reader::error "Pathname must be a string: %s" string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1024 (expand-file-name string)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1025
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1026 (set-dispatch-macro-character ?\# ?\p
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1027 (get-dispatch-macro-character ?\# ?\P))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1028
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1029 ;; #P"~/.emacs"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1030 ;; #p"~root/home"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1031
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1032 ;; Feature reading: #+<feature>, #-<feature>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1033 ;; Not yet implemented: #+<boolean expression>, #-<boolean expression>
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1034
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1035
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1036 (defsubst reader::read-feature (stream char n flag)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1037 (reader::check-0-infix n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1038 (let (;; Use the original reader to only read the feature.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1039 ;; This is not exactly correct without *read-suppress*.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1040 ;; Also Emacs 18 read goes one too far,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1041 ;; so we assume there is a space after the feature.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1042 (feature (reader::original-read stream))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1043 (object (reader::read-from-buffer stream 't)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1044 (if (eq (featurep feature) flag)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1045 object
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1046 ;; Ignore it.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1047 (throw 'reader-ignore nil))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1048
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1049 (set-dispatch-macro-character ?\# ?\+
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1050 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1051 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1052 (reader::read-feature stream char n t))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1053
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1054 (set-dispatch-macro-character ?\# ?\-
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1055 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1056 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1057 (reader::read-feature stream char n nil))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1058
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1059 ;; (#+cl loop #+cl do #-cl while #-cl t (body))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1060
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1061
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1062
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1063
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1064 ;; Shared structure reading: #<n>=, #<n>#
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1065
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1066 ;; Reading of sexpression with shared and circular structure read
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1067 ;; syntax is done in two steps:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1068 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1069 ;; 1. Create an sexpr with unshared structures, just as the ordinary
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1070 ;; read macros do, with two exceptions:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1071 ;; - each label (#<n>=) creates, as a side effect, a symbolic
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1072 ;; reference for the sexpr that follows it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1073 ;; - each reference (#<n>#) is replaced by the corresponding
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1074 ;; symbolic reference.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1075 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1076 ;; 2. This non-cyclic and unshared lisp structure is given to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1077 ;; function `reader::restore-shared-structure' (see
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1078 ;; `reader::read-from-buffer'), which simply replaces
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1079 ;; destructively all symbolic references by the lisp structures the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1080 ;; references point at.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1081 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1082 ;; A symbolic reference is an uninterned symbol whose name is obtained
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1083 ;; from the label/reference number using the function `int-to-string':
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1084 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1085 ;; There are two non-locally used variables (bound in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1086 ;; `reader::read-from-buffer') which control shared structure reading:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1087 ;; `reader::shared-structure-labels':
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1088 ;; A list of integers that correspond to the label numbers <n> in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1089 ;; the string currently read. This is used to avoid multiple
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1090 ;; definitions of the same label.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1091 ;; `reader::shared-structure-references':
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1092 ;; The list of symbolic references that will be used as temporary
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1093 ;; placeholders for the shared objects introduced by a reference
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1094 ;; with the same number identification.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1095
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1096 (set-dispatch-macro-character ?\# ?\=
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1097 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1098 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1099 (and (= n 0) (reader::error "0 not allowed as label"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1100 ;; check for multiple definition of the same label
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1101 (if (memq n reader::shared-structure-labels)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1102 (reader::error "Label defined twice")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1103 (push n reader::shared-structure-labels))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1104 ;; create an uninterned symbol as symbolic reference for the label
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1105 (let* ((string (int-to-string n))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1106 (ref (or (find string reader::shared-structure-references
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1107 :test 'string=)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1108 (first
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1109 (push (make-symbol string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1110 reader::shared-structure-references)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1111 ;; the link between the symbolic reference and the lisp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1112 ;; structure it points at is done using the symbol value cell
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1113 ;; of the reference symbol.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1114 (setf (symbol-value ref)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1115 ;; this is also the return value
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1116 (reader::read-from-buffer stream 't))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1117
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1118
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1119 (set-dispatch-macro-character ?\# ?\#
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1120 (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1121 (lambda (stream char n)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1122 (and (= n 0) (reader::error "0 not allowed as label"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1123 ;; use the non-local variable `reader::recursive-p' (from the reader
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1124 ;; main loop) to detect labels at the top level of an sexpr.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1125 (if (not reader::recursive-p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1126 (reader::error "References at top level not allowed"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1127 (let* ((string (int-to-string n))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1128 (ref (or (find string reader::shared-structure-references
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1129 :test 'string=)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1130 (first
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1131 (push (make-symbol string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1132 reader::shared-structure-references)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1133 ;; the value of reading a #n# form is a reference symbol
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1134 ;; whose symbol value is or will be the shared structure.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1135 ;; `reader::restore-shared-structure' then replaces the symbol by
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1136 ;; its value.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1137 ref))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1138
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1139 (defun reader::restore-shared-structure (obj)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1140 ;; traverses recursively OBJ and replaces all symbolic references by
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1141 ;; the objects they point at. Remember that a symbolic reference is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1142 ;; an uninterned symbol whose value is the object it points at.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1143 (cond
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1144 ((consp obj)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1145 (loop for rest on obj
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1146 as lastcdr = rest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1147 do
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1148 (if;; substructure is a symbolic reference
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1149 (memq (car rest) reader::shared-structure-references)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1150 ;; replace it by its symbol value, i.e. the associated object
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1151 (setf (car rest) (symbol-value (car rest)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1152 (reader::restore-shared-structure (car rest)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1153 finally
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1154 (if (memq (cdr lastcdr) reader::shared-structure-references)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1155 (setf (cdr lastcdr) (symbol-value (cdr lastcdr)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1156 (reader::restore-shared-structure (cdr lastcdr)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1157 ((vectorp obj)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1158 (loop for i below (length obj)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1159 do
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1160 (if;; substructure is a symbolic reference
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1161 (memq (aref obj i) reader::shared-structure-references)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1162 ;; replace it by its symbol value, i.e. the associated object
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1163 (setf (aref obj i) (symbol-value (aref obj i)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1164 (reader::restore-shared-structure (aref obj i))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1165 obj)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1166
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1167
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1168 ;; #1=(a b #3=[#2=c])
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1169 ;; (#1=[#\return #\a] #1# #1#)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1170 ;; (#1=[a b c] #1# #1#)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1171 ;; #1=(a b . #1#)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1172
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1173 ;; Creation and initialization of an internal standard readtable.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1174 ;; Do this after all the macros and dispatch chars above have been defined.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1175
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1176 (defconst reader::internal-standard-readtable (copy-readtable)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1177 "The original (CL-like) standard readtable. If you ever modify this
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1178 readtable, you won't be able to recover a standard readtable using
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1179 \(copy-readtable nil\)")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1180
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1181
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1182 ;; Replace built-in functions that call the built-in reader
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1183 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1184 ;; The following functions are replaced here:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1185 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1186 ;; read by reader::read
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1187 ;; read-from-string by reader::read-from-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1188 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1189 ;; eval-expression by reader::eval-expression
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1190 ;; Why replace eval-expression? Not needed for Lucid Emacs since the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1191 ;; reader for arguments is also written in Lisp, and so may be overridden.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1192 ;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1193 ;; eval-current-buffer by reader::eval-current-buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1194 ;; eval-buffer by reader::eval-buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1195 ;; original-eval-region by reader::original-eval-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1196
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1197
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1198 ;; Temporary read buffer used for reading from strings
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1199 (defconst reader::tmp-buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1200 (get-buffer-create " *CL Read*"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1201
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1202 ;; Save a pointer to the original read function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1203 (or (fboundp 'reader::original-read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1204 (fset 'reader::original-read (symbol-function 'read)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1205
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1206 (defun reader::read (&optional stream reader::recursive-p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1207 "Read one Lisp expression as text from STREAM, return as Lisp object.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1208 If STREAM is nil, use the value of `standard-input' \(which see\).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1209 STREAM or the value of `standard-input' may be:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1210 a buffer \(read from point and advance it\)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1211 a marker \(read from where it points and advance it\)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1212 a string \(takes text from string, starting at the beginning\)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1213 t \(read text line using minibuffer and use it\).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1214
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1215 This is the cl-read replacement of the standard elisp function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1216 `read'. The only incompatibility is that functions as stream arguments
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1217 are not supported."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1218 (if (not cl-read-active)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1219 (reader::original-read stream)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1220 (if (null stream) ; read from standard-input
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1221 (setq stream standard-input))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1222
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1223 (if (eq stream 't) ; read from minibuffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1224 (setq stream (read-from-minibuffer "Common Lisp Expression: ")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1225
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1226 (cond
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1227
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1228 ((bufferp stream) ; read from buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1229 (reader::read-from-buffer stream reader::recursive-p))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1230
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1231 ((markerp stream) ; read from marker
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1232 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1233 (set-buffer (marker-buffer stream))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1234 (goto-char (marker-position stream))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1235 (reader::read-from-buffer (current-buffer) reader::recursive-p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1236
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1237 ((stringp stream) ; read from string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1238 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1239 (set-buffer reader::tmp-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1240 (auto-save-mode -1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1241 (erase-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1242 (insert stream)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1243 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1244 (reader::read-from-buffer reader::tmp-buffer reader::recursive-p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1245 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1246 (reader::error "Not a valid stream: %s" stream)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1247
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1248 ;; read-from-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1249 ;; save a pointer to the original `read-from-string' function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1250 (or (fboundp 'reader::original-read-from-string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1251 (fset 'reader::original-read-from-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1252 (symbol-function 'read-from-string)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1253
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1254 (defun reader::read-from-string (string &optional start end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1255 "Read one Lisp expression which is represented as text by STRING.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1256 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1257 START and END optionally delimit a substring of STRING from which to read;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1258 they default to 0 and (length STRING) respectively.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1259
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1260 This is the cl-read replacement of the standard elisp function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1261 `read-from-string'. It uses the reader macros in *readtable* if
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1262 `cl-read-active' is non-nil in the current buffer."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1263
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1264 ;; Does it really make sense to have read-from-string depend on
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1265 ;; what the current buffer happens to be? Yes, so code that
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1266 ;; has nothing to do with cl-read uses original reader.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1267 (if (not cl-read-active)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1268 (reader::original-read-from-string string start end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1269 (or start (setq start 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1270 (or end (setq end (length string)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1271 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1272 (set-buffer reader::tmp-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1273 (auto-save-mode -1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1274 (erase-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1275 (insert (substring string 0 end))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1276 (goto-char (1+ start))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1277 (cons
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1278 (reader::read-from-buffer reader::tmp-buffer nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1279 (1- (point))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1280
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1281 ;; (read-from-string "abc (car 'a) bc" 4)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1282 ;; (reader::read-from-string "abc (car 'a) bc" 4)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1283 ;; (read-from-string "abc (car 'a) bc" 2 11)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1284 ;; (reader::read-from-string "abc (car 'a) bc" 2 11)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1285 ;; (reader::read-from-string "`(car ,first ,@rest)")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1286 ;; (read-from-string ";`(car ,first ,@rest)")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1287 ;; (reader::read-from-string ";`(car ,first ,@rest)")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1288
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1289 ;; We should replace eval-expression, too, so that it reads (and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1290 ;; evals) in the current buffer. Alternatively, this could be fixed
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1291 ;; in C. In Lemacs 19.6 and later, this function is already written
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1292 ;; in lisp, and based on more primitive read functions we already
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1293 ;; replaced. The reading happens during the interactive parameter
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1294 ;; retrieval, which is written in lisp, too. So this replacement of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1295 ;; eval-expresssion is only required fro (FSF) Emacs 18 (and 19?).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1296
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1297 (or (fboundp 'reader::original-eval-expression)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1298 (fset 'reader::original-eval-expression
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1299 (symbol-function 'eval-expression)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1300
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1301 (defun reader::eval-expression (reader::expression)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1302 "Evaluate EXPRESSION and print value in minibuffer.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1303 Value is also consed on to front of variable `values'."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1304 (interactive
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1305 (list
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1306 (car (read-from-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1307 (read-from-minibuffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1308 "Eval: " nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1309 ;;read-expression-map ;; not for emacs 18
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1310 nil ;; use default map
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1311 nil ;; don't do read with minibuffer current.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1312 ;; 'edebug-expression-history ;; not for emacs 18
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1313 )))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1314 (setq values (cons (eval reader::expression) values))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1315 (prin1 (car values) t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1316
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1317 (require 'eval-reg "eval-reg")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1318 (require 'advice)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1319
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1320
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1321 ;; installing/uninstalling the cl reader
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1322 ;; These two should always be used in pairs, or just install once and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1323 ;; never uninstall.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1324 (defun cl-reader-install ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1325 (interactive)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1326 (fset 'read 'reader::read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1327 (fset 'read-from-string 'reader::read-from-string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1328 (fset 'eval-expression 'reader::eval-expression)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1329 (elisp-eval-region-install))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1330
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1331 (defun cl-reader-uninstall ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1332 (interactive)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1333 (fset 'read
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1334 (symbol-function 'reader::original-read))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1335 (fset 'read-from-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1336 (symbol-function 'reader::original-read-from-string))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1337 (fset 'eval-expression
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1338 (symbol-function 'reader::original-eval-expression))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1339 (elisp-eval-region-uninstall))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1340
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1341 ;; Globally installing the cl-read replacement functions is safe, even
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1342 ;; for buffers without cl read syntax. The buffer local variable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1343 ;; `cl-read-active' controls whether the replacement funtions of this
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1344 ;; package or the original ones are actually called.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1345 (cl-reader-install)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1346 (cl-reader-uninstall)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1347
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1348 ;; Advise the redefined eval-region
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1349 (defadvice eval-region (around cl-read activate)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1350 "Use the reader::read instead of the original read if cl-read-active."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1351 (with-elisp-eval-region (not cl-read-active)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1352 (ad-do-it)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1353 ;;(ad-unadvise 'eval-region)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1354
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1355
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1356 (add-hook 'emacs-lisp-mode-hook 'cl-reader-autoinstall-function)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1357
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1358 '(defvar read-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1359
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1360 '(defun cl-reader-autoinstall-function ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1361 "Activates the Common Lisp style reader for emacs-lisp-mode buffers,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1362 if the property line has a local variable setting like this:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1363 \;\; -*- Read-Syntax: Common-Lisp -*-"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1364 ;; this is a hack to avoid recursion in the case that the prop line
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1365 ;; containes "Mode: emacs-lisp" entry
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1366 (or (boundp 'local-variable-hack-done)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1367 (let (local-variable-hack-done
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1368 (case-fold-search t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1369 ;; Usually `hack-local-variables-prop-line' is called only after
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1370 ;; installation of the major mode. But we need to know about the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1371 ;; local variables before that, so we call the local variable hack
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1372 ;; explicitly here:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1373 (hack-local-variables-prop-line 't)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1374 ;; But hack-local-variables-prop-line not defined in emacs 18.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1375 (cond
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1376 ((and (boundp 'read-syntax)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1377 read-syntax
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1378 (string-match "^common-lisp$" (symbol-name read-syntax)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1379 (require 'cl-read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1380 (make-local-variable 'cl-read-active)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1381 (setq cl-read-active 't))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1382
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1383 ;; Emacs 18 doesnt have hack-local-variables-prop-line. So use this instead.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1384 (defun cl-reader-autoinstall-function ()
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1385 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1386 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1387 (let ((case-fold-search t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1388 (cond ((re-search-forward
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1389 "read-syntax: *common-lisp"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1390 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1391 (end-of-line)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1392 (point))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1393 t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1394 (require 'cl-read)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1395 (make-local-variable 'cl-read-active)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1396 (setq cl-read-active t))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1397
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1398
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1399 (run-hooks 'cl-read-load-hooks)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1400 ;; end cl-read.el