Skip to content

Commit

Permalink
added and implemented IExpressionEvaluator#getBaseEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
BlvckBytes committed Sep 19, 2024
1 parent c4ccbba commit 28a6b2c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/me/blvckbytes/gpeee/GPEEE.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public Object evaluateExpression(AExpression expression, IEvaluationEnvironment
return interpreter.evaluateExpression(expression, environment);
}

@Override
public EvaluationEnvironmentBuilder getBaseEnvironment() {
if (this.baseEnvironment == null)
return new EvaluationEnvironmentBuilder();
return this.baseEnvironment.duplicate();
}

@Override
public void register(String name, AStandardFunction function) {
this.standardFunctions.put(name, function);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/blvckbytes/gpeee/IExpressionEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package me.blvckbytes.gpeee;

import me.blvckbytes.gpeee.error.AEvaluatorError;
import me.blvckbytes.gpeee.interpreter.EvaluationEnvironmentBuilder;
import me.blvckbytes.gpeee.interpreter.IEvaluationEnvironment;
import me.blvckbytes.gpeee.parser.expression.AExpression;

Expand Down Expand Up @@ -56,4 +57,9 @@ public interface IExpressionEvaluator {
*/
Object evaluateExpression(AExpression expression, IEvaluationEnvironment environment) throws AEvaluatorError;

/**
* Get a copy of the evaluator's base environment to be safely modified and built by the caller
*/
EvaluationEnvironmentBuilder getBaseEnvironment();

}

0 comments on commit 28a6b2c

Please sign in to comment.