continue and break scarpet functions to replace _exit_ conditions in loops

This commit is contained in:
gnembon committed 2019-12-06 12:22:27 -04:00
1 parent 20d066c674
commit 7f49ee09ad
4 files changed
+176 -86

No files matched your search

@@ -6,6 +6,8 @@ import carpet.script.ExpressionInspector;
import carpet.script.Fluff;
import carpet.script.LazyValue;
import carpet.script.Tokenizer;
import carpet.script.exception.BreakStatement;
import carpet.script.exception.ContinueStatement;
import carpet.script.exception.ExitStatement;
import carpet.script.exception.ExpressionException;
import carpet.script.exception.InternalExpressionException;
@@ -164,6 +166,10 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
{
retVal = body.evalValue(newFrame, type); // todo not sure if we need to propagete type / consider boolean context in defined functions - answer seems ye
}
catch (BreakStatement | ContinueStatement exc)
{
throw new ExpressionException(e, t, "'continue' and 'break' can only be called inside loop function bodies");
}
catch (ReturnStatement returnStatement)
{
retVal = returnStatement.retval;