package net.minecraft.util.parsing.packrat; import javax.annotation.Nullable; public interface Rule { @Nullable T parse(ParseState p_335539_); static Rule fromTerm(Term p_334127_, Rule.RuleAction p_334890_) { return new Rule.WrappedTerm<>(p_334890_, p_334127_); } static Rule fromTerm(Term p_336211_, Rule.SimpleRuleAction p_332994_) { return new Rule.WrappedTerm<>(p_332994_, p_336211_); } @FunctionalInterface public interface RuleAction { @Nullable T run(ParseState p_332162_); } @FunctionalInterface public interface SimpleRuleAction extends Rule.RuleAction { T run(Scope p_332535_); @Override default T run(ParseState p_392774_) { return this.run(p_392774_.scope()); } } public record WrappedTerm(Rule.RuleAction action, Term child) implements Rule { @Nullable @Override public T parse(ParseState p_328860_) { Scope scope = p_328860_.scope(); scope.pushFrame(); Object object; try { if (!this.child.parse(p_328860_, scope, Control.UNBOUND)) { return null; } object = this.action.run(p_328860_); } finally { scope.popFrame(); } return (T)object; } } }