package net.minecraft.util.parsing.packrat; import org.jspecify.annotations.Nullable; public interface Rule { @Nullable T parse(ParseState state); static Rule fromTerm(final Term child, final Rule.RuleAction action) { return new Rule.WrappedTerm<>(action, child); } static Rule fromTerm(final Term child, final Rule.SimpleRuleAction action) { return new Rule.WrappedTerm<>(action, child); } @FunctionalInterface public interface RuleAction { @Nullable T run(ParseState state); } @FunctionalInterface public interface SimpleRuleAction extends Rule.RuleAction { T run(Scope ruleScope); @Override default T run(final ParseState state) { return this.run(state.scope()); } } public record WrappedTerm(Rule.RuleAction action, Term child) implements Rule { @Nullable @Override public T parse(final ParseState state) { Scope scope = state.scope(); scope.pushFrame(); Object var3; try { if (!this.child.parse(state, scope, Control.UNBOUND)) { return null; } var3 = this.action.run(state); } finally { scope.popFrame(); } return (T)var3; } } }