Skip to content

Commit

Permalink
Merge pull request #5742 from mP1/feature/mP1-walkingkooka-tree-pull-…
Browse files Browse the repository at this point in the history
…880-ExpressionEvaluationContext-evaluateExpression-made-default

mP1/walkingkooka-tree#880 ExpressionEvaluatio…
  • Loading branch information
mP1 authored Feb 5, 2025
2 parents 8b79f93 + becaf10 commit 994685e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import walkingkooka.text.CaseSensitivity;
import walkingkooka.text.cursor.TextCursor;
import walkingkooka.text.cursor.parser.ParserReporters;
import walkingkooka.tree.expression.Expression;
import walkingkooka.tree.expression.ExpressionEvaluationContext;
import walkingkooka.tree.expression.ExpressionFunctionName;
import walkingkooka.tree.expression.ExpressionReference;
Expand Down Expand Up @@ -192,21 +191,6 @@ public CaseSensitivity stringEqualsCaseSensitivity() {
return SpreadsheetStrings.CASE_SENSITIVITY;
}

@Override
public Object evaluateExpression(final Expression expression) {
Objects.requireNonNull(expression, "expression");

Object result;

try {
result = expression.toValue(this);
} catch (final RuntimeException exception) {
result = this.handleException(exception);
}

return result;
}

@Override
public ExpressionFunction<?, ExpressionEvaluationContext> expressionFunction(final ExpressionFunctionName name) {
return this.expressionFunctionProvider.expressionFunction(
Expand All @@ -230,14 +214,23 @@ public <T> T prepareParameter(final ExpressionFunctionParameter<T> parameter,
return parameter.convertOrFail(value, this);
}

@Override
public Object evaluateFunction(final ExpressionFunction<?, ? extends ExpressionEvaluationContext> function,
final List<Object> parameters) {
return function
.apply(
this.prepareParameters(function, parameters),
Cast.to(this)
);
Objects.requireNonNull(function, "function");
Objects.requireNonNull(parameters, "parameters");

Object result;

try {
result = function.apply(
this.prepareParameters(function, parameters),
Cast.to(this)
);
} catch (final RuntimeException exception) {
result = this.handleException(exception);
}

return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import walkingkooka.spreadsheet.reference.SpreadsheetSelection;
import walkingkooka.text.CaseSensitivity;
import walkingkooka.text.cursor.TextCursor;
import walkingkooka.tree.expression.Expression;
import walkingkooka.tree.expression.ExpressionEvaluationContext;
import walkingkooka.tree.expression.ExpressionEvaluationException;
import walkingkooka.tree.expression.ExpressionFunctionName;
Expand Down Expand Up @@ -220,27 +219,6 @@ public AbsoluteUrl serverUrl() {

// eval scoped......................................................................................................

/**
* Evaluates the given {@link Expression} using this as the context which should result in the format
* being used.
*/
@Override
public Object evaluateExpression(final Expression expression) {
Objects.requireNonNull(expression, "expression");

Object result;

try {
result = expression.toValue(this);
} catch (final RuntimeException exception) {
result = this.handleException(exception);
}

return result;
}

private int scope;

/**
* Prepares the parameter value.
*/
Expand Down Expand Up @@ -283,6 +261,8 @@ public Object evaluateFunction(final ExpressionFunction<?, ? extends ExpressionE
}
}

private int scope;

// eval delegated..................................................................................................

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import walkingkooka.spreadsheet.reference.SpreadsheetSelection;
import walkingkooka.text.CaseSensitivity;
import walkingkooka.text.cursor.TextCursor;
import walkingkooka.tree.expression.Expression;
import walkingkooka.tree.expression.ExpressionEvaluationContext;
import walkingkooka.tree.expression.ExpressionFunctionName;
import walkingkooka.tree.expression.ExpressionNumberKind;
Expand Down Expand Up @@ -125,11 +124,6 @@ public AbsoluteUrl serverUrl() {

// ExpressionEvaluationContext......................................................................................

@Override
public Object evaluateExpression(final Expression expression) {
return expression.toValue(this);
}

@Override
public SpreadsheetFormulaParserToken parseFormula(final TextCursor cursor) {
return this.context.parseFormula(cursor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ public SpreadsheetParserContext spreadsheetParserContext() {

// ExpressionEvaluationContext......................................................................................

@Override
public Object evaluateExpression(final Expression expression) {
return expression.toValue(this);
}

@Override
public Object evaluateFunction(final ExpressionFunction<?, ? extends ExpressionEvaluationContext> function,
final List<Object> parameters) {
Expand Down

0 comments on commit 994685e

Please sign in to comment.