mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-04 14:31:53 +00:00
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: MiniDigger | Martin <admin@minidigger.dev> Co-authored-by: Nassim Jahnke <nassim@njahnke.dev> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com> Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com> Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
40 lines
1.5 KiB
Diff
40 lines
1.5 KiB
Diff
--- a/net/minecraft/util/parsing/packrat/Scope.java
|
|
+++ b/net/minecraft/util/parsing/packrat/Scope.java
|
|
@@ -281,4 +_,36 @@
|
|
|
|
return true;
|
|
}
|
|
+
|
|
+ // Paper start - track depth
|
|
+ private int depth;
|
|
+ @SuppressWarnings({"unchecked","rawtypes"})
|
|
+ public static <S> Term<S> increaseDepth() {
|
|
+ class IncreasingDepthTerm<W> implements Term<W> {
|
|
+ public static final IncreasingDepthTerm INSTANCE = new IncreasingDepthTerm();
|
|
+ @Override
|
|
+ public boolean parse(final ParseState<W> parseState, final Scope scope, final Control control) {
|
|
+ if (++scope.depth > 512) {
|
|
+ parseState.errorCollector().store(parseState.mark(), new IllegalStateException("Too deep"));
|
|
+ return false;
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ return (Term<S>) IncreasingDepthTerm.INSTANCE;
|
|
+ }
|
|
+
|
|
+ @SuppressWarnings({"unchecked","rawtypes"})
|
|
+ public static <S> Term<S> decreaseDepth() {
|
|
+ class DecreasingDepthTerm<W> implements Term<W> {
|
|
+ public static final DecreasingDepthTerm INSTANCE = new DecreasingDepthTerm();
|
|
+ @Override
|
|
+ public boolean parse(final ParseState<W> parseState, final Scope scope, final Control control) {
|
|
+ scope.depth--;
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ return (Term<S>) DecreasingDepthTerm.INSTANCE;
|
|
+ }
|
|
+ // Paper end - track depth
|
|
}
|