Class StdScope

java.lang.Object
com.hypixel.hytale.server.npc.util.expression.StdScope
All Implemented Interfaces:
Scope
Direct Known Subclasses:
StdLib

public class StdScope extends Object implements Scope
Helper class for implementing symbol tables for expressions.

A StdScope can have a parent scope used when symbol can't be resolved in current scope.

  • Constructor Details

    • StdScope

      public StdScope(Scope parent)
  • Method Details

    • copyOf

      @Nonnull public static StdScope copyOf(@Nonnull StdScope other)
      Shallow clone a scope (but not the symbols itself).
      Parameters:
      other - Scope to copy
      Returns:
      Duplicate of scope
    • merge

      @Nonnull public StdScope merge(@Nonnull StdScope other)
      Merge symbols of another scope into current scope.
      Parameters:
      other - Scope to get symbols from
      Returns:
      Current scope with symbols merged in
    • mergeScopes

      @Nonnull public static StdScope mergeScopes(@Nonnull StdScope first, @Nonnull StdScope second)
    • addConst

      public void addConst(String name, @Nullable String value)
    • addConst

      public void addConst(String name, double value)
    • addConst

      public void addConst(String name, boolean value)
    • addConst

      public void addConst(String name, @Nullable String[] value)
    • addConst

      public void addConst(String name, @Nullable double[] value)
    • addConst

      public void addConst(String name, @Nullable boolean[] value)
    • addConstEmptyArray

      public void addConstEmptyArray(String name)
    • addVar

      public void addVar(String name, @Nullable String value)
    • addVar

      public void addVar(String name, double value)
    • addVar

      public void addVar(String name, boolean value)
    • addVar

      public void addVar(String name, @Nullable String[] value)
    • addVar

      public void addVar(String name, @Nullable double[] value)
    • addVar

      public void addVar(String name, @Nullable boolean[] value)
    • addInvariant

      public void addInvariant(@Nonnull String name, Scope.Function function, ValueType returnType, @Nonnull ValueType... argumentTypes)
    • addVariant

      public void addVariant(@Nonnull String name, Scope.Function function, ValueType returnType, @Nonnull ValueType... argumentTypes)
    • addSupplier

      public void addSupplier(String name, Supplier<String> value)
    • addSupplier

      public void addSupplier(String name, DoubleSupplier value)
    • addSupplier

      public void addSupplier(String name, BooleanSupplier value)
    • addStringArraySupplier

      public void addStringArraySupplier(String name, Supplier<String[]> value)
    • addDoubleArraySupplier

      public void addDoubleArraySupplier(String name, Supplier<double[]> value)
    • addBooleanArraySupplier

      public void addBooleanArraySupplier(String name, Supplier<boolean[]> value)
    • changeValue

      public void changeValue(String name, @Nullable String value)
      Change value of variable in a scope.

      Use copy-on-write to create an new symbol for a changed value.

      Parameters:
      name - Name of variable
      value - New value of variable
    • changeValue

      public void changeValue(String name, double value)
      Change value of variable in a scope.

      Use copy-on-write to create an new symbol for a changed value.

      Parameters:
      name - Name of variable
      value - New value of variable
    • changeValue

      public void changeValue(String name, boolean value)
      Change value of variable in a scope.

      Use copy-on-write to create an new symbol for a changed value.

      Parameters:
      name - Name of variable
      value - New value of variable
    • changeValue

      public void changeValue(String name, @Nullable String[] value)
      Change value of variable in a scope.

      Use copy-on-write to create an new symbol for a changed value.

      Parameters:
      name - Name of variable
      value - New value of variable
    • changeValue

      public void changeValue(String name, @Nullable double[] value)
      Change value of variable in a scope.

      Use copy-on-write to create an new symbol for a changed value.

      Parameters:
      name - Name of variable
      value - New value of variable
    • changeValue

      public void changeValue(String name, @Nullable boolean[] value)
      Change value of variable in a scope.

      Use copy-on-write to create an new symbol for a changed value.

      Parameters:
      name - Name of variable
      value - New value of variable
    • changeValueToEmptyArray

      public void changeValueToEmptyArray(String name)
      Change value of variable in a scope to empty array.

      Use copy-on-write to create an new symbol for a changed value.

      Parameters:
      name - Name of variable
    • getStringSupplier

      public Supplier<String> getStringSupplier(String name)
      Specified by:
      getStringSupplier in interface Scope
    • getNumberSupplier

      public DoubleSupplier getNumberSupplier(String name)
      Specified by:
      getNumberSupplier in interface Scope
    • getBooleanSupplier

      public BooleanSupplier getBooleanSupplier(String name)
      Specified by:
      getBooleanSupplier in interface Scope
    • getStringArraySupplier

      public Supplier<String[]> getStringArraySupplier(String name)
      Specified by:
      getStringArraySupplier in interface Scope
    • getNumberArraySupplier

      public Supplier<double[]> getNumberArraySupplier(String name)
      Specified by:
      getNumberArraySupplier in interface Scope
    • getBooleanArraySupplier

      public Supplier<boolean[]> getBooleanArraySupplier(String name)
      Specified by:
      getBooleanArraySupplier in interface Scope
    • getFunction

      public Scope.Function getFunction(String name)
      Specified by:
      getFunction in interface Scope
    • isConstant

      public boolean isConstant(String name)
      Description copied from interface: Scope
      Check if a variable is a constant or a function always returns the same result for the same set of arguments.
      Specified by:
      isConstant in interface Scope
      Parameters:
      name - Name of function/variable.
      Returns:
      true if variable is constant or function is invariant
    • getType

      @Nullable public ValueType getType(String name)
      Specified by:
      getType in interface Scope