1 | /* |
---|
2 | * FaslReader.java |
---|
3 | * |
---|
4 | * Copyright (C) 2005 Peter Graves |
---|
5 | * $Id: FaslReader.java 12710 2010-05-19 22:27:21Z ehuelsmann $ |
---|
6 | * |
---|
7 | * This program is free software; you can redistribute it and/or |
---|
8 | * modify it under the terms of the GNU General Public License |
---|
9 | * as published by the Free Software Foundation; either version 2 |
---|
10 | * of the License, or (at your option) any later version. |
---|
11 | * |
---|
12 | * This program is distributed in the hope that it will be useful, |
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | * GNU General Public License for more details. |
---|
16 | * |
---|
17 | * You should have received a copy of the GNU General Public License |
---|
18 | * along with this program; if not, write to the Free Software |
---|
19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
20 | * |
---|
21 | * As a special exception, the copyright holders of this library give you |
---|
22 | * permission to link this library with independent modules to produce an |
---|
23 | * executable, regardless of the license terms of these independent |
---|
24 | * modules, and to copy and distribute the resulting executable under |
---|
25 | * terms of your choice, provided that you also meet, for each linked |
---|
26 | * independent module, the terms and conditions of the license of that |
---|
27 | * module. An independent module is a module which is not derived from |
---|
28 | * or based on this library. If you modify this library, you may extend |
---|
29 | * this exception to your version of the library, but you are not |
---|
30 | * obligated to do so. If you do not wish to do so, delete this |
---|
31 | * exception statement from your version. |
---|
32 | */ |
---|
33 | |
---|
34 | package org.armedbear.lisp; |
---|
35 | |
---|
36 | import static org.armedbear.lisp.Lisp.*; |
---|
37 | |
---|
38 | public final class FaslReader |
---|
39 | { |
---|
40 | // ### fasl-read-string |
---|
41 | public static final ReaderMacroFunction FASL_READ_STRING = |
---|
42 | new ReaderMacroFunction("fasl-read-string", PACKAGE_SYS, false, |
---|
43 | "stream character") |
---|
44 | { |
---|
45 | @Override |
---|
46 | public LispObject execute(Stream stream, char terminator) |
---|
47 | |
---|
48 | { |
---|
49 | return stream.readString(terminator, Stream.faslReadtable); |
---|
50 | } |
---|
51 | }; |
---|
52 | |
---|
53 | // ### fasl-read-list |
---|
54 | public static final ReaderMacroFunction FASL_READ_LIST = |
---|
55 | new ReaderMacroFunction("fasl-read-list", PACKAGE_SYS, false, |
---|
56 | "stream character") |
---|
57 | { |
---|
58 | @Override |
---|
59 | public LispObject execute(Stream stream, char ignored) |
---|
60 | |
---|
61 | { |
---|
62 | return stream.readList(false, Stream.faslReadtable); |
---|
63 | } |
---|
64 | }; |
---|
65 | |
---|
66 | // ### fasl-read-quote |
---|
67 | public static final ReaderMacroFunction FASL_READ_QUOTE = |
---|
68 | new ReaderMacroFunction("fasl-read-quote", PACKAGE_SYS, false, |
---|
69 | "stream character") |
---|
70 | { |
---|
71 | @Override |
---|
72 | public LispObject execute(Stream stream, char ignored) |
---|
73 | |
---|
74 | { |
---|
75 | return new Cons(Symbol.QUOTE, |
---|
76 | new Cons(stream.read(true, NIL, true, |
---|
77 | LispThread.currentThread(), |
---|
78 | Stream.faslReadtable))); |
---|
79 | } |
---|
80 | }; |
---|
81 | |
---|
82 | // ### fasl-read-dispatch-char |
---|
83 | public static final ReaderMacroFunction FASL_READ_DISPATCH_CHAR = |
---|
84 | new ReaderMacroFunction("fasl-read-dispatch-char", PACKAGE_SYS, false, |
---|
85 | "stream character") |
---|
86 | { |
---|
87 | @Override |
---|
88 | public LispObject execute(Stream stream, char c) |
---|
89 | |
---|
90 | { |
---|
91 | return stream.readDispatchChar(c, Stream.faslReadtable); |
---|
92 | } |
---|
93 | }; |
---|
94 | |
---|
95 | // ### fasl-sharp-left-paren |
---|
96 | public static final DispatchMacroFunction FASL_SHARP_LEFT_PAREN = |
---|
97 | new DispatchMacroFunction("fasl-sharp-left-paren", PACKAGE_SYS, false, |
---|
98 | "stream sub-char numarg") |
---|
99 | { |
---|
100 | @Override |
---|
101 | public LispObject execute(Stream stream, char c, int n) |
---|
102 | |
---|
103 | { |
---|
104 | return stream.readSharpLeftParen(c, n, Stream.faslReadtable); |
---|
105 | } |
---|
106 | }; |
---|
107 | |
---|
108 | // ### fasl-sharp-star |
---|
109 | public static final DispatchMacroFunction FASL_SHARP_STAR = |
---|
110 | new DispatchMacroFunction("fasl-sharp-star", PACKAGE_SYS, false, |
---|
111 | "stream sub-char numarg") |
---|
112 | { |
---|
113 | @Override |
---|
114 | public LispObject execute(Stream stream, char ignored, int n) |
---|
115 | |
---|
116 | { |
---|
117 | return stream.readSharpStar(ignored, n, Stream.faslReadtable); |
---|
118 | } |
---|
119 | }; |
---|
120 | |
---|
121 | // ### fasl-sharp-dot |
---|
122 | public static final DispatchMacroFunction FASL_SHARP_DOT = |
---|
123 | new DispatchMacroFunction("fasl-sharp-dot", PACKAGE_SYS, false, |
---|
124 | "stream sub-char numarg") |
---|
125 | { |
---|
126 | @Override |
---|
127 | public LispObject execute(Stream stream, char c, int n) |
---|
128 | |
---|
129 | { |
---|
130 | return stream.readSharpDot(c, n, Stream.faslReadtable); |
---|
131 | } |
---|
132 | }; |
---|
133 | |
---|
134 | // ### fasl-sharp-colon |
---|
135 | public static final DispatchMacroFunction FASL_SHARP_COLON = |
---|
136 | new DispatchMacroFunction("fasl-sharp-colon", PACKAGE_SYS, false, |
---|
137 | "stream sub-char numarg") |
---|
138 | { |
---|
139 | @Override |
---|
140 | public LispObject execute(Stream stream, char c, int n) |
---|
141 | |
---|
142 | { |
---|
143 | LispThread thread = LispThread.currentThread(); |
---|
144 | return stream.readSymbol(FaslReadtable.getInstance()); |
---|
145 | } |
---|
146 | }; |
---|
147 | |
---|
148 | // ### fasl-sharp-a |
---|
149 | public static final DispatchMacroFunction FASL_SHARP_A = |
---|
150 | new DispatchMacroFunction("fasl-sharp-a", PACKAGE_SYS, false, |
---|
151 | "stream sub-char numarg") |
---|
152 | { |
---|
153 | @Override |
---|
154 | public LispObject execute(Stream stream, char c, int n) |
---|
155 | |
---|
156 | { |
---|
157 | return stream.readArray(n, Stream.faslReadtable); |
---|
158 | } |
---|
159 | }; |
---|
160 | |
---|
161 | // ### fasl-sharp-b |
---|
162 | public static final DispatchMacroFunction FASL_SHARP_B = |
---|
163 | new DispatchMacroFunction("fasl-sharp-b", PACKAGE_SYS, false, |
---|
164 | "stream sub-char numarg") |
---|
165 | { |
---|
166 | @Override |
---|
167 | public LispObject execute(Stream stream, char c, int n) |
---|
168 | |
---|
169 | { |
---|
170 | return stream.readRadix(2, Stream.faslReadtable); |
---|
171 | } |
---|
172 | }; |
---|
173 | |
---|
174 | // ### fasl-sharp-c |
---|
175 | public static final DispatchMacroFunction FASL_SHARP_C = |
---|
176 | new DispatchMacroFunction("fasl-sharp-c", PACKAGE_SYS, false, |
---|
177 | "stream sub-char numarg") |
---|
178 | { |
---|
179 | @Override |
---|
180 | public LispObject execute(Stream stream, char c, int n) |
---|
181 | |
---|
182 | { |
---|
183 | return stream.readComplex(Stream.faslReadtable); |
---|
184 | } |
---|
185 | }; |
---|
186 | |
---|
187 | // ### fasl-sharp-o |
---|
188 | public static final DispatchMacroFunction FASL_SHARP_O = |
---|
189 | new DispatchMacroFunction("fasl-sharp-o", PACKAGE_SYS, false, |
---|
190 | "stream sub-char numarg") |
---|
191 | { |
---|
192 | @Override |
---|
193 | public LispObject execute(Stream stream, char c, int n) |
---|
194 | |
---|
195 | { |
---|
196 | return stream.readRadix(8, Stream.faslReadtable); |
---|
197 | } |
---|
198 | }; |
---|
199 | |
---|
200 | // ### fasl-sharp-p |
---|
201 | public static final DispatchMacroFunction FASL_SHARP_P = |
---|
202 | new DispatchMacroFunction("fasl-sharp-p", PACKAGE_SYS, false, |
---|
203 | "stream sub-char numarg") |
---|
204 | { |
---|
205 | @Override |
---|
206 | public LispObject execute(Stream stream, char c, int n) |
---|
207 | |
---|
208 | { |
---|
209 | return stream.readPathname(Stream.faslReadtable); |
---|
210 | } |
---|
211 | }; |
---|
212 | |
---|
213 | // ### fasl-sharp-r |
---|
214 | public static final DispatchMacroFunction FASL_SHARP_R = |
---|
215 | new DispatchMacroFunction("fasl-sharp-r", PACKAGE_SYS, false, |
---|
216 | "stream sub-char numarg") |
---|
217 | { |
---|
218 | @Override |
---|
219 | public LispObject execute(Stream stream, char c, int n) |
---|
220 | |
---|
221 | { |
---|
222 | return stream.readRadix(n, Stream.faslReadtable); |
---|
223 | } |
---|
224 | }; |
---|
225 | |
---|
226 | // ### fasl-sharp-s |
---|
227 | public static final DispatchMacroFunction FASL_SHARP_S = |
---|
228 | new DispatchMacroFunction("fasl-sharp-s", PACKAGE_SYS, false, |
---|
229 | "stream sub-char numarg") |
---|
230 | { |
---|
231 | @Override |
---|
232 | public LispObject execute(Stream stream, char c, int n) |
---|
233 | |
---|
234 | { |
---|
235 | return stream.readStructure(Stream.faslReadtable); |
---|
236 | } |
---|
237 | }; |
---|
238 | |
---|
239 | // ### fasl-sharp-x |
---|
240 | public static final DispatchMacroFunction FASL_SHARP_X = |
---|
241 | new DispatchMacroFunction("fasl-sharp-x", PACKAGE_SYS, false, |
---|
242 | "stream sub-char numarg") |
---|
243 | { |
---|
244 | @Override |
---|
245 | public LispObject execute(Stream stream, char c, int n) |
---|
246 | |
---|
247 | { |
---|
248 | return stream.readRadix(16, Stream.faslReadtable); |
---|
249 | } |
---|
250 | }; |
---|
251 | |
---|
252 | // ### fasl-sharp-quote |
---|
253 | public static final DispatchMacroFunction FASL_SHARP_QUOTE = |
---|
254 | new DispatchMacroFunction("fasl-sharp-quote", PACKAGE_SYS, false, |
---|
255 | "stream sub-char numarg") |
---|
256 | { |
---|
257 | @Override |
---|
258 | public LispObject execute(Stream stream, char c, int n) |
---|
259 | |
---|
260 | { |
---|
261 | return new Cons(Symbol.FUNCTION, |
---|
262 | new Cons(stream.read(true, NIL, true, |
---|
263 | LispThread.currentThread(), |
---|
264 | Stream.faslReadtable))); |
---|
265 | } |
---|
266 | }; |
---|
267 | |
---|
268 | // ### fasl-sharp-backslash |
---|
269 | public static final DispatchMacroFunction FASL_SHARP_BACKSLASH = |
---|
270 | new DispatchMacroFunction("fasl-sharp-backslash", PACKAGE_SYS, false, |
---|
271 | "stream sub-char numarg") |
---|
272 | { |
---|
273 | @Override |
---|
274 | public LispObject execute(Stream stream, char c, int n) |
---|
275 | { |
---|
276 | return stream.readCharacterLiteral(FaslReadtable.getInstance(), |
---|
277 | LispThread.currentThread()); |
---|
278 | } |
---|
279 | }; |
---|
280 | |
---|
281 | // ### fasl-sharp-question-mark |
---|
282 | public static final DispatchMacroFunction FASL_SHARP_QUESTION_MARK = |
---|
283 | new DispatchMacroFunction("fasl-sharp-question-mark", PACKAGE_SYS, |
---|
284 | false, "stream sub-char numarg") |
---|
285 | { |
---|
286 | @Override |
---|
287 | public LispObject execute(Stream stream, char c, int n) |
---|
288 | { |
---|
289 | return Load.getUninternedSymbol(n); |
---|
290 | } |
---|
291 | }; |
---|
292 | |
---|
293 | } |
---|