
org.snapscript.tree.variable.Variable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.variable;
import org.snapscript.core.Evaluation;
import org.snapscript.core.Scope;
import org.snapscript.core.State;
import org.snapscript.core.Value;
import org.snapscript.tree.NameReference;
public class Variable implements Evaluation {
private final NameReference reference;
private final VariableBinder binder;
public Variable(Evaluation identifier) {
this.reference = new NameReference(identifier);
this.binder = new VariableBinder();
}
@Override
public Value evaluate(Scope scope, Object left) throws Exception{
String name = reference.getName(scope);
if(left == null) {
State state = scope.getState();
Value value = state.get(name);
if(value != null) {
return value;
}
}
return binder.bind(scope, left, name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy