match теперь может использоваться в качестве оператора

This commit is contained in:
Victor 2016-01-22 19:07:06 +02:00
parent 6b95ae54cf
commit 95ca908243
6 changed files with 45 additions and 39 deletions

View File

@ -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)
}
}

View File

@ -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();
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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);

View File

@ -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