GreedyPredicateParseRule .java

net.minecraft.util.parsing.packrat.commands.GreedyPredicateParseRule (class): members: isAccepted, minSize, maxSize, error, parse. imports: Rule, Nullable.

net.minecraft.util.parsing.packrat.commandsclass47 linescommon1.5 KB

Implements

API Surface (0)

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

Fields & Constants (3)

minSize
maxSize
error

Code Graph: Dependencies (3)

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

Full Source

GreedyPredicateParseRule.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util.parsing.packrat.commands;
2
3
import com.mojang.brigadier.StringReader;
4
import com.mojang.brigadier.exceptions.CommandSyntaxException;
5
import net.minecraft.util.parsing.packrat.DelayedException;
6
import net.minecraft.util.parsing.packrat.ParseState;
7
import net.minecraft.util.parsing.packrat.Rule;
8
import org.jspecify.annotations.Nullable;
9
10
public abstract class GreedyPredicateParseRule implements Rule<StringReader, String> {
11
	private final int minSize;
12
	private final int maxSize;
13
	private final DelayedException<CommandSyntaxException> error;
14
15
	public GreedyPredicateParseRule(final int minSize, final DelayedException<CommandSyntaxException> error) {
16
		this(minSize, Integer.MAX_VALUE, error);
17
	}
18
19
	public GreedyPredicateParseRule(final int minSize, final int maxSize, final DelayedException<CommandSyntaxException> error) {
20
		this.minSize = minSize;
21
		this.maxSize = maxSize;
22
		this.error = error;
23
	}
24
25
	public @Nullable String parse(final ParseState<StringReader> state) {
26
		StringReader input = state.input();
27
		String fullString = input.getString();
28
		int start = input.getCursor();
29
		int pos = start;
30
31
		while (pos < fullString.length() && this.isAccepted(fullString.charAt(pos)) && pos - start < this.maxSize) {
32
			pos++;
33
		}
34
35
		int length = pos - start;
36
		if (length < this.minSize) {
37
			state.errorCollector().store(state.mark(), this.error);
38
			return null;
39
		} else {
40
			input.setCursor(pos);
41
			return fullString.substring(start, pos);
42
		}
43
	}
44
45
	protected abstract boolean isAccepted(char c);
46
}
47

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