static List <Object> ReadDelimitedList(char delim, PushbackTextReader r, bool isRecursive, object opts) { LineNumberingTextReader lntr = r as LineNumberingTextReader; int firstLine = lntr != null ? lntr.LineNumber : -1; List <Object> a = new List <object>(); for (; ;) { int ch = r.Read(); while (isWhitespace(ch)) { ch = r.Read(); } if (ch == -1) { if (firstLine < 0) { throw new EndOfStreamException("EOF while reading"); } else { throw new EndOfStreamException("EOF while reading, starting at line " + firstLine); } } if (ch == delim) { break; } IFn macroFn = getMacro(ch); if (macroFn != null) { Object mret = macroFn.invoke(r, (char)ch, opts); //no op macros return the reader if (mret != r) { a.Add(mret); } } else { Unread(r, ch); object o = read(r, true, null, isRecursive, opts); if (o != r) { a.Add(o); } } } return(a); }
public void Setup() { _sr = new StringReader(_sample); _rdr = new LineNumberingTextReader(_sr); }
static void ConsumeWhitespaces(LineNumberingTextReader lnReader) { int ch = lnReader.Read(); while (LispReader.isWhitespace(ch)) ch = lnReader.Read(); LispReader.Unread(lnReader, ch); }
protected override object Read(PushbackTextReader r, char caret, object opts) { int startLine = -1; int startCol = -1; LineNumberingTextReader lntr = r as LineNumberingTextReader; if (lntr != null) { startLine = lntr.LineNumber; startCol = lntr.ColumnNumber; } IPersistentMap metaAsMap; { object meta = ReadAux(r, opts); if (meta is Symbol || meta is String) { metaAsMap = RT.map(RT.TagKey, meta); } else if (meta is Keyword) { metaAsMap = RT.map(meta, true); } else if ((metaAsMap = meta as IPersistentMap) == null) { throw new ArgumentException("Metadata must be Symbol,Keyword,String or Map"); } } object o = ReadAux(r, opts); if (o is IMeta) { if (startLine != -1 && o is ISeq) { metaAsMap = metaAsMap.assoc(RT.LineKey, startLine) .assoc(RT.ColumnKey, startCol) .assoc(RT.SourceSpanKey, RT.map( RT.StartLineKey, startLine, RT.StartColumnKey, startCol, RT.EndLineKey, lntr.LineNumber, RT.EndColumnKey, lntr.ColumnNumber)); } if (o is IReference iref) { iref.resetMeta(metaAsMap); return(o); } object ometa = RT.meta(o); for (ISeq s = RT.seq(metaAsMap); s != null; s = s.next()) { IMapEntry kv = (IMapEntry)s.first(); ometa = RT.assoc(ometa, kv.key(), kv.val()); } return(((IObj)o).withMeta((IPersistentMap)ometa)); } else { throw new ArgumentException("Metadata can only be applied to IMetas"); } }
// There is really no reason for the main entry point to have an isRecursive flag, is there? public static object read(PushbackTextReader r, bool eofIsError, object eofValue, bool isRecursive) { try { for (; ;) { int ch = r.Read(); while (isWhitespace(ch)) { ch = r.Read(); } if (ch == -1) { if (eofIsError) { throw new EndOfStreamException("EOF while reading"); } return(eofValue); } if (Char.IsDigit((char)ch)) { object n = readNumber(r, (char)ch); return(RT.suppressRead() ? null : n); } IFn macroFn = getMacro(ch); if (macroFn != null) { object ret = macroFn.invoke(r, (char)ch); if (RT.suppressRead()) { return(null); } // no op macros return the reader if (ret == r) { continue; } return(ret); } if (ch == '+' || ch == '-') { int ch2 = r.Read(); if (Char.IsDigit((char)ch2)) { Unread(r, ch2); object n = readNumber(r, (char)ch); return(RT.suppressRead() ? null : n); } Unread(r, ch2); } string token = readToken(r, (char)ch); return(RT.suppressRead() ? null : interpretToken(token)); } } catch (Exception e) { if (isRecursive || !(r is LineNumberingTextReader)) { throw e; } LineNumberingTextReader rdr = r as LineNumberingTextReader; throw new ReaderException(rdr.LineNumber, e); } }
public static object read(PushbackTextReader r, bool eofIsError, object eofValue, bool isRecursive, Object opts) { try { for (; ;) { int ch = r.Read(); while (isWhitespace(ch)) { ch = r.Read(); } if (ch == -1) { if (eofIsError) { throw new EndOfStreamException("EOF while reading"); } return(eofValue); } if (Char.IsDigit((char)ch)) { object n = readNumber(r, (char)ch); return(RT.suppressRead() ? null : n); } IFn macroFn = getMacro(ch); if (macroFn != null) { object ret = macroFn.invoke(r, (char)ch, opts); if (RT.suppressRead()) { return(null); } // no op macros return the reader if (ret == r) { continue; } return(ret); } if (ch == '+' || ch == '-') { int ch2 = r.Read(); if (Char.IsDigit((char)ch2)) { Unread(r, ch2); object n = readNumber(r, (char)ch); return(RT.suppressRead() ? null : n); } Unread(r, ch2); } //string token = readToken(r, (char)ch); //return RT.suppressRead() ? null : interpretToken(token); string rawToken; string token; string mask; bool eofSeen; readToken(r, (char)ch, true, out rawToken, out token, out mask, out eofSeen); if (eofSeen) { if (eofIsError) { throw new EndOfStreamException("EOF while reading symbol"); } return(eofValue); } return(RT.suppressRead() ? null : InterpretToken(rawToken, token, mask)); } } catch (Exception e) { if (isRecursive) { throw; } LineNumberingTextReader lntr = r as LineNumberingTextReader; if (lntr == null) { throw; } throw new ReaderException(lntr.LineNumber, lntr.ColumnNumber, e); } }