1 4 package gnu.kawa.lispexpr; 5 import gnu.text.*; 6 import gnu.mapping.InPort; 7 8 12 13 public class ReaderTypespec extends ReadTableEntry 14 { 15 public int getKind() 16 { 17 return ReadTable.NON_TERMINATING_MACRO; 18 } 19 20 public Object read (Lexer in, int ch, int count) 21 throws java.io.IOException , SyntaxException 22 { 23 int startPos = in.tokenBufferLength; 24 LineBufferedReader port = in.getPort(); 25 ReadTable rtable = ReadTable.getCurrent(); 26 ReadTableEntry entry; 27 char saveReadState = '\0'; 28 in.tokenBufferAppend(ch); 29 int c = ch; 30 int prev; 31 if (port instanceof InPort) 32 { 33 saveReadState = ((InPort) port).readState; 34 ((InPort) port).readState = (char) ch; 35 } 36 try 37 { 38 boolean got_open_square = false; 39 for (;;) 40 { 41 int next; 42 43 prev = c; 44 45 if (port.pos < port.limit && prev != '\n') 46 c = port.buffer[port.pos++]; 47 else 48 c = port.read(); 49 if (c == '\\') 50 { 51 if (in instanceof LispReader) 52 c = ((LispReader) in).readEscape(); 53 else 54 c = port.read(); 55 } 56 else 57 { 58 if ( (!got_open_square && c == '[' 59 && true == (got_open_square = true)) 60 || (got_open_square && c == ']' 61 && false == (got_open_square = false)) 62 || (null != (entry = rtable.lookup(c)) 63 && entry.getKind() == ReadTable.CONSTITUENT)) 64 { 65 in.tokenBufferAppend(c); 66 continue; 67 } 68 else 69 { 70 in.unread(c); 71 break; 72 } 73 } 74 } 75 return (new java.lang.String (in.tokenBuffer, startPos, 76 in.tokenBufferLength - startPos)).intern(); 77 } 78 finally 79 { 80 in.tokenBufferLength = startPos; 81 if (port instanceof InPort) 82 ((InPort) port).readState = saveReadState; 83 } 84 } 85 } 86 | Popular Tags |