Rule.java

net.minecraft.util.parsing.packrat.Rule

信息

  • 全限定名:net.minecraft.util.parsing.packrat.Rule
  • 类型:public interface
  • 包:net.minecraft.util.parsing.packrat
  • 源码路径:src/main/java/net/minecraft/util/parsing/packrat/Rule.java
  • 起始行号:L5
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

  • net.minecraft.util.parsing.packrat.Rule.RuleAction

    • 类型: interface
    • 修饰符: public
    • 源码定位: L17
    • 说明:

      TODO

  • net.minecraft.util.parsing.packrat.Rule.SimpleRuleAction

    • 类型: interface
    • 修饰符: public
    • 源码定位: L22
    • 说明:

      TODO

  • net.minecraft.util.parsing.packrat.Rule.WrappedTerm

    • 类型: record
    • 修饰符: public
    • 源码定位: L31
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

T parse(ParseState<S> state) @ L6

  • 方法名:parse
  • 源码定位:L6
  • 返回类型:T
  • 修饰符:package-private

参数:

  • state: ParseState

说明:

TODO

static <S,T> Rule<S,T> fromTerm(Term<S> child, Rule.RuleAction<S,T> action) @ L8

  • 方法名:fromTerm
  • 源码定位:L8
  • 返回类型:<S,T> Rule<S,T>
  • 修饰符:static

参数:

  • child: Term
  • action: Rule.RuleAction<S,T>

说明:

TODO

static <S,T> Rule<S,T> fromTerm(Term<S> child, Rule.SimpleRuleAction<S,T> action) @ L12

  • 方法名:fromTerm
  • 源码定位:L12
  • 返回类型:<S,T> Rule<S,T>
  • 修饰符:static

参数:

  • child: Term
  • action: Rule.SimpleRuleAction<S,T>

说明:

TODO

代码

public interface Rule<S, T> {
    @Nullable T parse(ParseState<S> state);
 
    static <S, T> Rule<S, T> fromTerm(Term<S> child, Rule.RuleAction<S, T> action) {
        return new Rule.WrappedTerm<>(action, child);
    }
 
    static <S, T> Rule<S, T> fromTerm(Term<S> child, Rule.SimpleRuleAction<S, T> action) {
        return new Rule.WrappedTerm<>(action, child);
    }
 
    @FunctionalInterface
    public interface RuleAction<S, T> {
        @Nullable T run(ParseState<S> state);
    }
 
    @FunctionalInterface
    public interface SimpleRuleAction<S, T> extends Rule.RuleAction<S, T> {
        T run(Scope ruleScope);
 
        @Override
        default T run(ParseState<S> state) {
            return this.run(state.scope());
        }
    }
 
    public record WrappedTerm<S, T>(Rule.RuleAction<S, T> action, Term<S> child) implements Rule<S, T> {
        @Override
        public @Nullable T parse(ParseState<S> 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;
        }
    }
}

引用的其他类