mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
match теперь может использоваться в качестве оператора
This commit is contained in:
parent
6b95ae54cf
commit
95ca908243
@ -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)
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
30
src/com/annimon/ownlang/parser/ast/ExprStatement.java
Normal file
30
src/com/annimon/ownlang/parser/ast/ExprStatement.java
Normal 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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user