Class Scope<T>

  • Type Parameters:
    T - The type of values in scope.

    public final class Scope<T>
    extends java.lang.Object
    Scope is a stack for tracking facts for named values of the given type.
    • Constructor Summary

      Constructors 
      Constructor Description
      Scope()
      Crates a new, empty scope with a single layer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T expectValue​(Identifier name)
      Gets the first value in scope for the specified identifier, throwing InnerParseError if the identifier is undefined in all the scope.
      static Scope<Value> fromNode​(Node node)
      Creates a Scope instance from the given Node information.
      java.util.Optional<java.util.Map.Entry<Identifier,​T>> getDeclaration​(Identifier name)
      Gets the first declaration in scope for the specified identifier.
      java.util.Optional<T> getValue​(Identifier name)
      Gets the first value in scope for the specified identifier.
      <U> U inScope​(java.util.function.Supplier<U> supplier)
      Assesses a value supplier in the current scope.
      void insert​(java.lang.String name, T value)
      Inserts a named value into the current scope.
      void insert​(Identifier name, T value)
      Inserts a named value into the current scope.
      boolean isNonNull​(Reference reference)
      Gets if a reference is non-null in the current scope.
      void pop()
      Pops the most recent ScopeLayer out of the current scope.
      void push()
      Pushes an empty ScopeLayer into the current scope.
      void setNonNull​(Reference name)
      Inserts a non-null reference into the current scope.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Scope

        public Scope()
        Crates a new, empty scope with a single layer.
    • Method Detail

      • fromNode

        public static Scope<Value> fromNode​(Node node)
        Creates a Scope instance from the given Node information.
        Parameters:
        node - the node to deserialize.
        Returns:
        the created Scope.
      • inScope

        public <U> U inScope​(java.util.function.Supplier<U> supplier)
        Assesses a value supplier in the current scope.
        Type Parameters:
        U - the type of the value returned by the supplier.
        Parameters:
        supplier - the value supplier to assess.
        Returns:
        the value returned by the supplier.
      • push

        public void push()
        Pushes an empty ScopeLayer into the current scope.
      • pop

        public void pop()
        Pops the most recent ScopeLayer out of the current scope.
      • insert

        public void insert​(java.lang.String name,
                           T value)
        Inserts a named value into the current scope.
        Parameters:
        name - the name of the value to insert.
        value - the value to insert.
      • insert

        public void insert​(Identifier name,
                           T value)
        Inserts a named value into the current scope.
        Parameters:
        name - the name of the value to insert.
        value - the value to insert.
      • setNonNull

        public void setNonNull​(Reference name)
        Inserts a non-null reference into the current scope.
        Parameters:
        name - the name of the reference to insert.
      • isNonNull

        public boolean isNonNull​(Reference reference)
        Gets if a reference is non-null in the current scope.
        Parameters:
        reference - the reference to check nullability for.
        Returns:
        true if the reference is non-null, false otherwise.
      • getDeclaration

        public java.util.Optional<java.util.Map.Entry<Identifier,​T>> getDeclaration​(Identifier name)
        Gets the first declaration in scope for the specified identifier.
        Parameters:
        name - the identifier to retrieve a declaration for.
        Returns:
        an optional of the declaration for the identifier, or empty otherwise.
      • expectValue

        public T expectValue​(Identifier name)
                      throws InnerParseError
        Gets the first value in scope for the specified identifier, throwing InnerParseError if the identifier is undefined in all the scope.
        Parameters:
        name - the identifier to retrieve a declaration for.
        Returns:
        the value for the identifier.
        Throws:
        InnerParseError - when the identifier has no value in the scope.
      • getValue

        public java.util.Optional<T> getValue​(Identifier name)
        Gets the first value in scope for the specified identifier.
        Parameters:
        name - the identifier to retrieve a value for.
        Returns:
        an optional of the value for the identifier, or empty otherwise.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object