All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.tree.variable.InstancePointer Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version

package org.snapscript.tree.variable;

import org.snapscript.core.Scope;
import org.snapscript.core.Value;
import org.snapscript.tree.define.ThisScopeBinder;

public class InstancePointer implements VariablePointer {
   
   private final VariablePointer pointer;
   private final ThisScopeBinder binder; 
   
   public InstancePointer(String name) {
      this.pointer = new LocalPointer(name);
      this.binder = new ThisScopeBinder();
   }
   
   @Override
   public Value get(Scope scope, Object left) {
      Scope instance = binder.bind(scope, scope);
      
      if(instance != null) {
         return pointer.get(instance, left);
      }
      return null;
   }
}