Respackopts/src/main/java/io/gitlab/jfronny/respackopts/model/Condition.java

28 lines
975 B
Java

package io.gitlab.jfronny.respackopts.model;
import io.gitlab.jfronny.muscript.ast.BoolExpr;
import io.gitlab.jfronny.muscript.data.Scope;
import io.gitlab.jfronny.muscript.error.LocationalError;
import io.gitlab.jfronny.muscript.error.LocationalException;
public record Condition(String source, BoolExpr expr) {
public boolean get(Scope dataRoot) throws ConditionException {
try {
return expr.get(dataRoot);
} catch (LocationalException e) {
throw new ConditionException(e.asPrintable(source), e);
} catch (RuntimeException e) {
throw new ConditionException(LocationalError.create(source, 0, e.getMessage()), e);
}
}
public static class ConditionException extends Exception {
public final LocationalError error;
public ConditionException(LocationalError error, Throwable cause) {
super(error.toString(), cause);
this.error = error;
}
}
}