public static object MapFormReader(TextReader stream, Reader reader) { char cur; if (!(PeekChar(stream, out cur) && cur == '{')) { return null; } NLMap map = new NLMap(); SkipChar(stream); do { object[] pair = { null, null }; SkipWhitespace(stream); if (Empty(stream)) { throw new ReaderException("Unterminated map!"); } PeekChar(stream, out cur); if (cur == '}') { break; } pair[0] = reader.ReadNextForm(stream); if (pair[0] == null) { throw new ReaderException("Unreadable form in map!"); } SkipWhitespace(stream); if (Empty(stream)) { throw new ReaderException("Unterminated map!"); } pair[1] = reader.ReadNextForm(stream); if (pair[1] == null) { throw new ReaderException("Unreadable form in map!"); } SkipWhitespace(stream); if (Empty(stream)) { throw new ReaderException("Unterminated map!"); } map.Assoc(pair[0], pair[1]); } while (PeekChar(stream, out cur) && cur != '}'); SkipChar(stream); return map; }
public static IFlatCollection FlatCollectionFormReader(TextReader stream, Reader reader, char open, char close, FormFactory factory) { char cur; if (!(PeekChar(stream, out cur) && cur == open)) { return null; } IFlatCollection coll = factory(); SkipChar(stream); do { SkipWhitespace(stream); object form = reader.ReadNextForm(stream); if (form != null) { coll.Append(form); } SkipWhitespace(stream); if (Empty(stream)) { throw new ReaderException("Unterminated vector!"); } } while (PeekChar(stream, out cur) && cur != close); SkipChar(stream); return coll; }