01: // Copyright (c) 2001 Per M.A. Bothner
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.kawa.lispexpr;
05:
06: import gnu.mapping.*;
07: import gnu.math.IntNum;
08: import gnu.text.Char;
09: import gnu.text.Lexer;
10:
11: /** Wrapper for user-supplied reader dispatch macro procedure.
12: * This for second-level dispatching, typically after '#'. */
13:
14: public class ReaderDispatchMacro extends ReaderMisc {
15: Procedure procedure;
16:
17: public ReaderDispatchMacro(Procedure procedure) {
18: super (ReadTable.TERMINATING_MACRO);
19: this .procedure = procedure;
20: }
21:
22: public Procedure getProcedure() {
23: return procedure;
24: }
25:
26: public Object read(Lexer in, int ch, int count)
27: throws java.io.IOException, gnu.text.SyntaxException {
28: // java.io.Reader reader = in;
29: java.io.Reader reader = in.getPort();
30: try {
31: return procedure.apply3(reader, Char.make(ch), IntNum
32: .make(count));
33: } catch (java.io.IOException ex) {
34: throw ex;
35: } catch (gnu.text.SyntaxException ex) {
36: throw ex;
37: } catch (Throwable ex) {
38: in.fatal("reader macro '" + procedure + "' threw: " + ex);
39: return null; // Never executed.
40: }
41: }
42: }
|