Rule .java

net.minecraft.util.parsing.packrat.Rule (interface, 45 lines): members: SimpleRuleAction, WrappedTerm, RuleAction, fromTerm, parse. imports: Nullable.

net.minecraft.util.parsing.packratinterface45 linescommon1.1 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

Rule.java45 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.parsing.packrat;
2
3
import org.jspecify.annotations.Nullable;
4
5
public interface Rule<S, T> {
6
	@Nullable T parse(ParseState<S> state);
7
8
	static <S, T> Rule<S, T> fromTerm(final Term<S> child, final Rule.RuleAction<S, T> action) {
9
		return new Rule.WrappedTerm<>(action, child);
10
	}
11
12
	static <S, T> Rule<S, T> fromTerm(final Term<S> child, final Rule.SimpleRuleAction<S, T> action) {
13
		return new Rule.WrappedTerm<>(action, child);
14
	}
15
16
	@FunctionalInterface
17
	interface RuleAction<S, T> {
18
		@Nullable T run(ParseState<S> state);
19
	}
20
21
	@FunctionalInterface
22
	interface SimpleRuleAction<S, T> extends Rule.RuleAction<S, T> {
23
		T run(Scope ruleScope);
24
25
		@Override
26
		default T run(final ParseState<S> state) {
27
			return this.run(state.scope());
28
		}
29
	}
30
31
	record WrappedTerm<S, T>(Rule.RuleAction<S, T> action, Term<S> child) implements Rule<S, T> {
32
		@Override
33
		public @Nullable T parse(final ParseState<S> state) {
34
			Scope scope = state.scope();
35
			scope.pushFrame();
36
37
			try {
38
				return this.child.parse(state, scope, Control.UNBOUND) ? this.action.run(state) : null;
39
			} finally {
40
				scope.popFrame();
41
			}
42
		}
43
	}
44
}
45

Decompiled Minecraft 26.3 source of Rule (net/minecraft/util/parsing/packrat/Rule.java) with Mojang official mappings, stored verbatim on the site.