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