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.text.Lexer;
07: import gnu.text.SyntaxException;
08: import gnu.lists.PairWithPosition;
09:
10: public class ReaderQuote extends ReadTableEntry {
11: Object magicSymbol;
12: char next;
13: Object magicSymbol2;
14:
15: /** Read an expression EXP and return (magicSymbol EXP). */
16: public ReaderQuote(Object magicSymbol) {
17: this .magicSymbol = magicSymbol;
18: }
19:
20: /** If the next character is 'next' read an expression EXP
21: * and return (magicSymbol2 EXP).
22: * Otherwise, read EXP and return (magicSymbol EXP). */
23: public ReaderQuote(Object magicSymbol, char next,
24: Object magicSymbol2) {
25: this .next = next;
26: this .magicSymbol = magicSymbol;
27: this .magicSymbol2 = magicSymbol2;
28: }
29:
30: public Object read(Lexer in, int ch, int count)
31: throws java.io.IOException, SyntaxException {
32: LispReader reader = (LispReader) in;
33: String file = reader.getName();
34: int line1 = reader.getLineNumber() + 1;
35: int column1 = reader.getColumnNumber() + 1;
36: Object magic = magicSymbol;
37: if (next != '\0') {
38: ch = reader.read();
39: if (ch == next)
40: magic = magicSymbol2;
41: else if (ch >= 0)
42: reader.unread(ch);
43: }
44: int line2 = reader.getLineNumber() + 1;
45: int column2 = reader.getColumnNumber() + 1;
46: Object operand = reader.readObject();
47: return PairWithPosition.make(magic, PairWithPosition.make(
48: operand, reader.makeNil(), file, line2, column2), file,
49: line1, column1);
50: }
51: }
|