package net.minecraft.util.parsing.packrat; import java.util.ArrayList; import java.util.List; import net.minecraft.Util; public interface ErrorCollector { void store(int p_334236_, SuggestionSupplier p_329361_, Object p_331748_); default void store(int p_330627_, Object p_332187_) { this.store(p_330627_, SuggestionSupplier.empty(), p_332187_); } void finish(int p_334270_); public static class LongestOnly implements ErrorCollector { private ErrorCollector.LongestOnly.MutableErrorEntry[] entries = new ErrorCollector.LongestOnly.MutableErrorEntry[16]; private int nextErrorEntry; private int lastCursor = -1; private void discardErrorsFromShorterParse(int p_331637_) { if (p_331637_ > this.lastCursor) { this.lastCursor = p_331637_; this.nextErrorEntry = 0; } } @Override public void finish(int p_334009_) { this.discardErrorsFromShorterParse(p_334009_); } @Override public void store(int p_331115_, SuggestionSupplier p_329965_, Object p_332125_) { this.discardErrorsFromShorterParse(p_331115_); if (p_331115_ == this.lastCursor) { this.addErrorEntry(p_329965_, p_332125_); } } private void addErrorEntry(SuggestionSupplier p_397931_, Object p_397847_) { int i = this.entries.length; if (this.nextErrorEntry >= i) { int j = Util.growByHalf(i, this.nextErrorEntry + 1); ErrorCollector.LongestOnly.MutableErrorEntry[] mutableerrorentry = new ErrorCollector.LongestOnly.MutableErrorEntry[j]; System.arraycopy(this.entries, 0, mutableerrorentry, 0, i); this.entries = mutableerrorentry; } int k = this.nextErrorEntry++; ErrorCollector.LongestOnly.MutableErrorEntry mutableerrorentry1 = this.entries[k]; if (mutableerrorentry1 == null) { mutableerrorentry1 = new ErrorCollector.LongestOnly.MutableErrorEntry<>(); this.entries[k] = mutableerrorentry1; } mutableerrorentry1.suggestions = p_397931_; mutableerrorentry1.reason = p_397847_; } public List> entries() { int i = this.nextErrorEntry; if (i == 0) { return List.of(); } else { List> list = new ArrayList<>(i); for (int j = 0; j < i; j++) { ErrorCollector.LongestOnly.MutableErrorEntry mutableerrorentry = this.entries[j]; list.add(new ErrorEntry<>(this.lastCursor, mutableerrorentry.suggestions, mutableerrorentry.reason)); } return list; } } public int cursor() { return this.lastCursor; } static class MutableErrorEntry { SuggestionSupplier suggestions = SuggestionSupplier.empty(); Object reason = "empty"; } } public static class Nop implements ErrorCollector { @Override public void store(int p_393771_, SuggestionSupplier p_392237_, Object p_393518_) { } @Override public void finish(int p_396049_) { } } }