KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > lispexpr > ReaderDispatchMacro


1 // Copyright (c) 2001 Per M.A. Bothner
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.lispexpr;
5 import gnu.mapping.*;
6 import gnu.math.IntNum;
7 import gnu.text.Char;
8 import gnu.text.Lexer;
9
10 /** Wrapper for user-supplied reader dispatch macro procedure.
11  * This for second-level dispatching, typically after '#'. */

12
13 public class ReaderDispatchMacro extends ReaderMisc
14 {
15   Procedure procedure;
16
17   public ReaderDispatchMacro(Procedure procedure)
18   {
19     super(ReadTable.TERMINATING_MACRO);
20     this.procedure = procedure;
21   }
22
23   public Procedure getProcedure()
24   {
25     return procedure;
26   }
27
28   public Object JavaDoc read (Lexer in, int ch, int count)
29     throws java.io.IOException JavaDoc, gnu.text.SyntaxException
30   {
31     // java.io.Reader reader = in;
32
java.io.Reader JavaDoc reader = in.getPort();
33     try
34       {
35     return procedure.apply3(reader, Char.make(ch), IntNum.make(count));
36       }
37     catch (java.io.IOException JavaDoc ex)
38       {
39     throw ex;
40       }
41     catch (gnu.text.SyntaxException ex)
42       {
43     throw ex;
44       }
45     catch (Throwable JavaDoc ex)
46       {
47     in.fatal("reader macro '"+procedure+"' threw: "+ex);
48     return null; // Never executed.
49
}
50   }
51 }
52
Popular Tags