private ReadResults ReadTypedValue(out INbtTag result) { result = default; Reader.SkipWhitespace(); int start = Reader.GetCursor(); ReadResults readResults; if (Reader.IsQuotedStringStart(Reader.Peek())) { readResults = Reader.ReadQuotedString(out string quotedString); if (readResults.Successful) { result = new StringNbtTag(quotedString); } return(readResults); } readResults = Reader.ReadUnquotedString(out string s); if (!readResults.Successful) { return(readResults); } if (string.IsNullOrEmpty(s)) { Reader.SetCursor(start); return(ReadResults.Failure(CommandError.ExpectedValue())); } result = GetType(s); return(ReadResults.Success()); }
private ReadResults ReadListContents(ref INbtCollectionTag list) { ReadResults readResults; while (Reader.CanRead() && Reader.Peek() != ']') { int start = Reader.GetCursor(); readResults = ReadValue(out INbtTag tag); if (!readResults.Successful) { return(readResults); } if (!list.Add(tag)) { Reader.SetCursor(start); return(ReadResults.Failure(CommandError.NbtCannotInsert(tag, list).WithContext(Reader))); } if (!HasElementSeparator()) { break; } if (Reader.CanRead()) { continue; } return(ReadResults.Failure(CommandError.ExpectedValue().WithContext(Reader))); } return(Reader.Expect(']')); }
private ReadResults ReadArrayTag(out INbtTag result) { result = default; ReadResults readResults = Reader.Expect('['); if (!readResults.Successful) { return(readResults); } int start = Reader.GetCursor(); char type = Reader.Read(); Reader.Skip(); Reader.SkipWhitespace(); if (!Reader.CanRead()) { return(ReadResults.Failure(CommandError.ExpectedValue().WithContext(Reader))); } INbtCollectionTag list; switch (type) { case 'B': list = new ByteArrayNbtTag(); break; case 'I': list = new IntegerArrayNbtTag(); break; case 'L': list = new LongArrayNbtTag(); break; default: Reader.SetCursor(start); return(ReadResults.Failure(CommandError.InvalidArrayType(type).WithContext(Reader))); } readResults = ReadListContents(ref list); if (readResults.Successful) { result = list; } return(readResults); }
private ReadResults ReadListTag(out INbtTag result) { result = default; ReadResults readResults = Reader.Expect('['); if (!readResults.Successful) { return(readResults); } if (!Reader.CanRead()) { return(ReadResults.Failure(CommandError.ExpectedValue().WithContext(Reader))); } INbtCollectionTag list = new ListNbtTag(); return(ReadListContents(ref list)); }
public ReadResults ReadValue(out INbtTag result) { result = default; Reader.SkipWhitespace(); if (!Reader.CanRead()) { return(ReadResults.Failure(CommandError.ExpectedValue().WithContext(Reader))); } char c = Reader.Peek(); if (c == '{') { return(ReadCompound(out result)); } if (c == '[') { return(ReadList(out result)); } return(ReadTypedValue(out result)); }