| 1 package gnu.kawa.brl; 2 import gnu.kawa.lispexpr.*; 3 import gnu.text.SyntaxException; 4 import gnu.mapping.*; 5 import gnu.text.SourceMessages; 6 import gnu.lists.*; 7 8 9 10 public class BRLRead extends LispReader 11 { 12 int nesting; 13 14 15 public boolean inLiteral () 16 { 17 return ((InPort) port).readState == ']'; 18 } 19 20 void init() 21 { 22 initialColonIsKeyword = false; 23 ((InPort) port).readState = ']'; 24 } 25 26 public BRLRead(InPort port) 27 { 28 super(port); 29 init(); 30 } 31 32 public BRLRead(InPort port, SourceMessages messages) 33 { 34 super(port, messages); 35 init(); 36 } 37 38 public Object readObject () 39 throws java.io.IOException , SyntaxException 40 { 41 int startPos = tokenBufferLength; 42 InPort port = (InPort) getPort(); 43 int saveNesting = nesting; 44 try 45 { 46 for (;;) 47 { 48 int ch = port.read(); 49 if (ch < 0) 50 { 51 if (port.readState != ']' && ! isInteractive()) 52 error('e', expressionStartFile, 53 expressionStartLine + 1, expressionStartColumn, 54 "an unmatched '[' was read"); 55 return Sequence.eofValue; } 57 if (port.readState == ']') 58 { 59 port.unread(); 60 Object value = BRL.brlReader.read(this, ']', 1); 61 if (ch == '[' && value == BRL.emptyForm) 62 continue; 63 return value; 64 } 65 else 66 { 67 if (ch == ']') 68 port.readState = ']'; 69 else 70 { 71 nesting++; 72 Object value = readValues(ch, ReadTable.getCurrent()); 73 if (value != Values.empty) 74 { 75 if (value == gnu.expr.QuoteExp.voidExp) 76 value = Values.empty; 77 return value; 78 } 79 nesting = saveNesting; 80 } 81 } 82 } 83 } 84 finally 85 { 86 nesting = saveNesting; 87 tokenBufferLength = startPos; 88 } 90 } 91 92 public static Object readObject(InPort port) 93 throws java.io.IOException , SyntaxException 94 { 95 return (new BRLRead(port)).readObject(); 96 } 97 98 boolean brlCompatible = false; 99 100 public boolean isBrlCompatible() { return brlCompatible; } 101 public void setBrlCompatible(boolean compat) 102 { 103 brlCompatible = compat; 104 initialColonIsKeyword = compat; 105 } 106 107 108 String expressionStartFile; 109 int expressionStartLine; 110 int expressionStartColumn; 111 112 void saveExpressionStartPosition() 113 { 114 expressionStartFile = port.getName(); 115 expressionStartLine = port.getLineNumber(); 116 expressionStartColumn = port.getColumnNumber(); 117 } 118 } 119 | Popular Tags |