diff --git a/examples/canvas/animate_line.own b/examples/canvas/animate_line.own index d017e8a..b16d336 100644 --- a/examples/canvas/animate_line.own +++ b/examples/canvas/animate_line.own @@ -46,10 +46,12 @@ def sethsbcolor(h1) { hueindex = floor(qr) % 6 f = qr - floor(qr) - if hueindex == 0 color(255, f*255, 0) - else if hueindex == 1 color(255 - f*255, 255, 0) - else if hueindex == 2 color(0, 255, f*255) - else if hueindex == 3 color(0, 255-f*255, 255) - else if hueindex == 4 color(f*255, 0, 255) - else if hueindex == 5 color(255, 0, 255-f*255) + match hueindex { + case 0: color(255, f*255, 0) + case 1: color(255 - f*255, 255, 0) + case 2: color(0, 255, f*255) + case 3: color(0, 255-f*255, 255) + case 4: color(f*255, 0, 255) + case 5: color(255, 0, 255-f*255) + } } \ No newline at end of file diff --git a/src/com/annimon/ownlang/parser/Parser.java b/src/com/annimon/ownlang/parser/Parser.java index 6c80ae9..ece352a 100644 --- a/src/com/annimon/ownlang/parser/Parser.java +++ b/src/com/annimon/ownlang/parser/Parser.java @@ -84,8 +84,11 @@ public final class Parser { if (match(TokenType.DEF)) { return functionDefine(); } + if (match(TokenType.MATCH)) { + return new ExprStatement(match()); + } if (lookMatch(0, TokenType.WORD) && lookMatch(1, TokenType.LPAREN)) { - return new FunctionStatement(function(qualifiedName())); + return new ExprStatement(function(qualifiedName())); } return assignmentStatement(); } diff --git a/src/com/annimon/ownlang/parser/ast/ExprStatement.java b/src/com/annimon/ownlang/parser/ast/ExprStatement.java new file mode 100644 index 0000000..e7d8e8c --- /dev/null +++ b/src/com/annimon/ownlang/parser/ast/ExprStatement.java @@ -0,0 +1,30 @@ +package com.annimon.ownlang.parser.ast; + +/** + * Wrapper for expressions, which can be used as statements. + * + * @author aNNiMON + */ +public final class ExprStatement implements Statement { + + public final Expression expr; + + public ExprStatement(Expression function) { + this.expr = function; + } + + @Override + public void execute() { + expr.eval(); + } + + @Override + public void accept(Visitor visitor) { + visitor.visit(this); + } + + @Override + public String toString() { + return expr.toString(); + } +} diff --git a/src/com/annimon/ownlang/parser/ast/FunctionStatement.java b/src/com/annimon/ownlang/parser/ast/FunctionStatement.java deleted file mode 100644 index 54cda62..0000000 --- a/src/com/annimon/ownlang/parser/ast/FunctionStatement.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.annimon.ownlang.parser.ast; - -/** - * - * @author aNNiMON - */ -public final class FunctionStatement implements Statement { - - public final FunctionalExpression function; - - public FunctionStatement(FunctionalExpression function) { - this.function = function; - } - - @Override - public void execute() { - function.eval(); - } - - @Override - public void accept(Visitor visitor) { - visitor.visit(this); - } - - @Override - public String toString() { - return function.toString(); - } -} diff --git a/src/com/annimon/ownlang/parser/ast/Visitor.java b/src/com/annimon/ownlang/parser/ast/Visitor.java index 1c1735d..ab3356a 100644 --- a/src/com/annimon/ownlang/parser/ast/Visitor.java +++ b/src/com/annimon/ownlang/parser/ast/Visitor.java @@ -21,7 +21,7 @@ public interface Visitor { void visit(ForeachMapStatement s); void visit(FunctionDefineStatement s); void visit(FunctionReferenceExpression e); - void visit(FunctionStatement s); + void visit(ExprStatement s); void visit(FunctionalExpression s); void visit(IfStatement s); void visit(MapExpression s); diff --git a/src/com/annimon/ownlang/parser/visitors/AbstractVisitor.java b/src/com/annimon/ownlang/parser/visitors/AbstractVisitor.java index b6a960f..661c1ed 100644 --- a/src/com/annimon/ownlang/parser/visitors/AbstractVisitor.java +++ b/src/com/annimon/ownlang/parser/visitors/AbstractVisitor.java @@ -98,8 +98,8 @@ public abstract class AbstractVisitor implements Visitor { } @Override - public void visit(FunctionStatement s) { - s.function.accept(this); + public void visit(ExprStatement s) { + s.expr.accept(this); } @Override