Term.java
net.minecraft.util.parsing.packrat.Term
信息
- 全限定名:net.minecraft.util.parsing.packrat.Term
- 类型:public interface
- 包:net.minecraft.util.parsing.packrat
- 源码路径:src/main/java/net/minecraft/util/parsing/packrat/Term.java
- 起始行号:L6
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
-
net.minecraft.util.parsing.packrat.Term.Alternative- 类型:
record - 修饰符:
public - 源码定位:
L103 - 说明:
TODO
- 类型:
-
net.minecraft.util.parsing.packrat.Term.LookAhead- 类型:
record - 修饰符:
public - 源码定位:
L133 - 说明:
TODO
- 类型:
-
net.minecraft.util.parsing.packrat.Term.Marker- 类型:
record - 修饰符:
public - 源码定位:
L143 - 说明:
TODO
- 类型:
-
net.minecraft.util.parsing.packrat.Term.Maybe- 类型:
record - 修饰符:
public - 源码定位:
L151 - 说明:
TODO
- 类型:
-
net.minecraft.util.parsing.packrat.Term.Repeated- 类型:
record - 修饰符:
public - 源码定位:
L163 - 说明:
TODO
- 类型:
-
net.minecraft.util.parsing.packrat.Term.RepeatedWithSeparator- 类型:
record - 修饰符:
public - 源码定位:
L188 - 说明:
TODO
- 类型:
-
net.minecraft.util.parsing.packrat.Term.Sequence- 类型:
record - 修饰符:
public - 源码定位:
L234 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
boolean parse(ParseState<S> state, Scope scope, Control control) @ L7
- 方法名:parse
- 源码定位:L7
- 返回类型:boolean
- 修饰符:package-private
参数:
- state: ParseState
- scope: Scope
- control: Control
说明:
TODO
static <S,T> Term<S> marker(Atom<T> name, T value) @ L9
- 方法名:marker
- 源码定位:L9
- 返回类型:<S,T> Term
- 修饰符:static
参数:
- name: Atom
- value: T
说明:
TODO
static <S> Term<S> sequence(Term<S>... terms) @ L13
- 方法名:sequence
- 源码定位:L13
- 返回类型:
Term - 修饰符:static
参数:
- terms: Term
…
说明:
TODO
static <S> Term<S> alternative(Term<S>... terms) @ L18
- 方法名:alternative
- 源码定位:L18
- 返回类型:
Term - 修饰符:static
参数:
- terms: Term
…
说明:
TODO
static <S> Term<S> optional(Term<S> term) @ L23
- 方法名:optional
- 源码定位:L23
- 返回类型:
Term - 修饰符:static
参数:
- term: Term
说明:
TODO
static <S,T> Term<S> repeated(NamedRule<S,T> element, Atom<List<T>> listName) @ L27
- 方法名:repeated
- 源码定位:L27
- 返回类型:<S,T> Term
- 修饰符:static
参数:
- element: NamedRule<S,T>
- listName: Atom<List
>
说明:
TODO
static <S,T> Term<S> repeated(NamedRule<S,T> element, Atom<List<T>> listName, int minRepetitions) @ L31
- 方法名:repeated
- 源码定位:L31
- 返回类型:<S,T> Term
- 修饰符:static
参数:
- element: NamedRule<S,T>
- listName: Atom<List
> - minRepetitions: int
说明:
TODO
static <S,T> Term<S> repeatedWithTrailingSeparator(NamedRule<S,T> element, Atom<List<T>> listName, Term<S> separator) @ L35
- 方法名:repeatedWithTrailingSeparator
- 源码定位:L35
- 返回类型:<S,T> Term
- 修饰符:static
参数:
- element: NamedRule<S,T>
- listName: Atom<List
> - separator: Term
说明:
TODO
static <S,T> Term<S> repeatedWithTrailingSeparator(NamedRule<S,T> element, Atom<List<T>> listName, Term<S> separator, int minRepetitions) @ L39
- 方法名:repeatedWithTrailingSeparator
- 源码定位:L39
- 返回类型:<S,T> Term
- 修饰符:static
参数:
- element: NamedRule<S,T>
- listName: Atom<List
> - separator: Term
- minRepetitions: int
说明:
TODO
static <S,T> Term<S> repeatedWithoutTrailingSeparator(NamedRule<S,T> element, Atom<List<T>> listName, Term<S> separator) @ L43
- 方法名:repeatedWithoutTrailingSeparator
- 源码定位:L43
- 返回类型:<S,T> Term
- 修饰符:static
参数:
- element: NamedRule<S,T>
- listName: Atom<List
> - separator: Term
说明:
TODO
static <S,T> Term<S> repeatedWithoutTrailingSeparator(NamedRule<S,T> element, Atom<List<T>> listName, Term<S> separator, int minRepetitions) @ L47
- 方法名:repeatedWithoutTrailingSeparator
- 源码定位:L47
- 返回类型:<S,T> Term
- 修饰符:static
参数:
- element: NamedRule<S,T>
- listName: Atom<List
> - separator: Term
- minRepetitions: int
说明:
TODO
static <S> Term<S> positiveLookahead(Term<S> term) @ L51
- 方法名:positiveLookahead
- 源码定位:L51
- 返回类型:
Term - 修饰符:static
参数:
- term: Term
说明:
TODO
static <S> Term<S> negativeLookahead(Term<S> term) @ L55
- 方法名:negativeLookahead
- 源码定位:L55
- 返回类型:
Term - 修饰符:static
参数:
- term: Term
说明:
TODO
static <S> Term<S> cut() @ L59
- 方法名:cut
- 源码定位:L59
- 返回类型:
Term - 修饰符:static
参数:
- 无
说明:
TODO
static <S> Term<S> empty() @ L74
- 方法名:empty
- 源码定位:L74
- 返回类型:
Term - 修饰符:static
参数:
- 无
说明:
TODO
static <S> Term<S> fail(Object message) @ L88
- 方法名:fail
- 源码定位:L88
- 返回类型:
Term - 修饰符:static
参数:
- message: Object
说明:
TODO
代码
public interface Term<S> {
boolean parse(ParseState<S> state, Scope scope, Control control);
static <S, T> Term<S> marker(Atom<T> name, T value) {
return new Term.Marker<>(name, value);
}
@SafeVarargs
static <S> Term<S> sequence(Term<S>... terms) {
return new Term.Sequence<>(terms);
}
@SafeVarargs
static <S> Term<S> alternative(Term<S>... terms) {
return new Term.Alternative<>(terms);
}
static <S> Term<S> optional(Term<S> term) {
return new Term.Maybe<>(term);
}
static <S, T> Term<S> repeated(NamedRule<S, T> element, Atom<List<T>> listName) {
return repeated(element, listName, 0);
}
static <S, T> Term<S> repeated(NamedRule<S, T> element, Atom<List<T>> listName, int minRepetitions) {
return new Term.Repeated<>(element, listName, minRepetitions);
}
static <S, T> Term<S> repeatedWithTrailingSeparator(NamedRule<S, T> element, Atom<List<T>> listName, Term<S> separator) {
return repeatedWithTrailingSeparator(element, listName, separator, 0);
}
static <S, T> Term<S> repeatedWithTrailingSeparator(NamedRule<S, T> element, Atom<List<T>> listName, Term<S> separator, int minRepetitions) {
return new Term.RepeatedWithSeparator<>(element, listName, separator, minRepetitions, true);
}
static <S, T> Term<S> repeatedWithoutTrailingSeparator(NamedRule<S, T> element, Atom<List<T>> listName, Term<S> separator) {
return repeatedWithoutTrailingSeparator(element, listName, separator, 0);
}
static <S, T> Term<S> repeatedWithoutTrailingSeparator(NamedRule<S, T> element, Atom<List<T>> listName, Term<S> separator, int minRepetitions) {
return new Term.RepeatedWithSeparator<>(element, listName, separator, minRepetitions, false);
}
static <S> Term<S> positiveLookahead(Term<S> term) {
return new Term.LookAhead<>(term, true);
}
static <S> Term<S> negativeLookahead(Term<S> term) {
return new Term.LookAhead<>(term, false);
}
static <S> Term<S> cut() {
return new Term<S>() {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
control.cut();
return true;
}
@Override
public String toString() {
return "\u2191";
}
};
}
static <S> Term<S> empty() {
return new Term<S>() {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
return true;
}
@Override
public String toString() {
return "\u03b5";
}
};
}
static <S> Term<S> fail(Object message) {
return new Term<S>() {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
state.errorCollector().store(state.mark(), message);
return false;
}
@Override
public String toString() {
return "fail";
}
};
}
public record Alternative<S>(Term<S>[] elements) implements Term<S> {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
Control controlForThis = state.acquireControl();
try {
int mark = state.mark();
scope.splitFrame();
for (Term<S> element : this.elements) {
if (element.parse(state, scope, controlForThis)) {
scope.mergeFrame();
return true;
}
scope.clearFrameValues();
state.restore(mark);
if (controlForThis.hasCut()) {
break;
}
}
scope.popFrame();
return false;
} finally {
state.releaseControl();
}
}
}
public record LookAhead<S>(Term<S> term, boolean positive) implements Term<S> {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
int mark = state.mark();
boolean result = this.term.parse(state.silent(), scope, control);
state.restore(mark);
return this.positive == result;
}
}
public record Marker<S, T>(Atom<T> name, T value) implements Term<S> {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
scope.put(this.name, this.value);
return true;
}
}
public record Maybe<S>(Term<S> term) implements Term<S> {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
int mark = state.mark();
if (!this.term.parse(state, scope, control)) {
state.restore(mark);
}
return true;
}
}
public record Repeated<S, T>(NamedRule<S, T> element, Atom<List<T>> listName, int minRepetitions) implements Term<S> {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
int mark = state.mark();
List<T> elements = new ArrayList<>(this.minRepetitions);
while (true) {
int entryMark = state.mark();
T parsedElement = state.parse(this.element);
if (parsedElement == null) {
state.restore(entryMark);
if (elements.size() < this.minRepetitions) {
state.restore(mark);
return false;
} else {
scope.put(this.listName, elements);
return true;
}
}
elements.add(parsedElement);
}
}
}
public record RepeatedWithSeparator<S, T>(
NamedRule<S, T> element, Atom<List<T>> listName, Term<S> separator, int minRepetitions, boolean allowTrailingSeparator
) implements Term<S> {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
int listMark = state.mark();
List<T> elements = new ArrayList<>(this.minRepetitions);
boolean first = true;
while (true) {
int markBeforeSeparator = state.mark();
if (!first && !this.separator.parse(state, scope, control)) {
state.restore(markBeforeSeparator);
break;
}
int markAfterSeparator = state.mark();
T parsedElement = state.parse(this.element);
if (parsedElement == null) {
if (first) {
state.restore(markAfterSeparator);
} else {
if (!this.allowTrailingSeparator) {
state.restore(listMark);
return false;
}
state.restore(markAfterSeparator);
}
break;
}
elements.add(parsedElement);
first = false;
}
if (elements.size() < this.minRepetitions) {
state.restore(listMark);
return false;
} else {
scope.put(this.listName, elements);
return true;
}
}
}
public record Sequence<S>(Term<S>[] elements) implements Term<S> {
@Override
public boolean parse(ParseState<S> state, Scope scope, Control control) {
int mark = state.mark();
for (Term<S> element : this.elements) {
if (!element.parse(state, scope, control)) {
state.restore(mark);
return false;
}
}
return true;
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: