forked from IrisShaders/Iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/trunk' into mojmap
- Loading branch information
Showing
34 changed files
with
1,371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/kroppeb/stareval/element/AccessibleExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package kroppeb.stareval.element; | ||
|
||
public interface AccessibleExpression extends Expression { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package kroppeb.stareval.element; | ||
|
||
public interface Element { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kroppeb.stareval.element; | ||
|
||
public interface Expression extends Element { | ||
@Override | ||
String toString(); | ||
|
||
default Expression simplify() { | ||
return this; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/kroppeb/stareval/element/PriorityOperatorElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kroppeb.stareval.element; | ||
|
||
public interface PriorityOperatorElement extends Element { | ||
int getPriority(); | ||
|
||
Expression resolveWith(Expression right); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/kroppeb/stareval/element/token/BinaryOperatorToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package kroppeb.stareval.element.token; | ||
|
||
import kroppeb.stareval.parser.BinaryOp; | ||
|
||
public class BinaryOperatorToken extends Token { | ||
public final BinaryOp op; | ||
|
||
public BinaryOperatorToken(BinaryOp op) { | ||
this.op = op; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BinaryOp{" + this.op + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package kroppeb.stareval.element.token; | ||
|
||
import kroppeb.stareval.element.AccessibleExpression; | ||
|
||
public class IdToken extends Token implements AccessibleExpression { | ||
public final String id; | ||
|
||
public IdToken(String id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Id{" + this.id + "}"; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/kroppeb/stareval/element/token/NumberToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package kroppeb.stareval.element.token; | ||
|
||
import kroppeb.stareval.element.Expression; | ||
|
||
public class NumberToken extends Token implements Expression { | ||
private final String number; | ||
|
||
public NumberToken(String number) { | ||
this.number = number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Number{" + this.number + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package kroppeb.stareval.element.token; | ||
|
||
import kroppeb.stareval.element.Element; | ||
|
||
public abstract class Token implements Element { | ||
@Override | ||
public abstract String toString(); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/kroppeb/stareval/element/token/UnaryOperatorToken.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package kroppeb.stareval.element.token; | ||
|
||
import kroppeb.stareval.element.PriorityOperatorElement; | ||
import kroppeb.stareval.element.Expression; | ||
import kroppeb.stareval.element.tree.UnaryExpression; | ||
import kroppeb.stareval.parser.UnaryOp; | ||
|
||
public class UnaryOperatorToken extends Token implements PriorityOperatorElement { | ||
private final UnaryOp op; | ||
|
||
public UnaryOperatorToken(UnaryOp op) { | ||
this.op = op; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UnaryOp{" + this.op + "}"; | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return -1; | ||
} | ||
|
||
@Override | ||
public UnaryExpression resolveWith(Expression right) { | ||
return new UnaryExpression(this.op, right); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/kroppeb/stareval/element/tree/AccessExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package kroppeb.stareval.element.tree; | ||
|
||
import kroppeb.stareval.element.AccessibleExpression; | ||
|
||
public class AccessExpression implements AccessibleExpression { | ||
private final AccessibleExpression base; | ||
private final String index; | ||
|
||
public AccessExpression(AccessibleExpression base, String index) { | ||
this.base = base; | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Access{" + this.base + "[" + this.index + "]}"; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/kroppeb/stareval/element/tree/BinaryExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package kroppeb.stareval.element.tree; | ||
|
||
import kroppeb.stareval.element.Expression; | ||
import kroppeb.stareval.parser.BinaryOp; | ||
|
||
public class BinaryExpression implements Expression { | ||
private final BinaryOp op; | ||
private Expression left; | ||
private Expression right; | ||
|
||
public BinaryExpression(BinaryOp op, Expression left, Expression right) { | ||
this.op = op; | ||
this.left = left; | ||
this.right = right; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BinaryExpr{ {" + this.left + "} " + this.op + " {" + this.right + "} }"; | ||
} | ||
|
||
@Override | ||
public Expression simplify() { | ||
this.left = this.left.simplify(); | ||
this.right = this.right.simplify(); | ||
return this; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/kroppeb/stareval/element/tree/FunctionCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package kroppeb.stareval.element.tree; | ||
|
||
import kroppeb.stareval.element.Expression; | ||
|
||
import java.util.List; | ||
|
||
public class FunctionCall implements Expression { | ||
private final String id; | ||
private final List<Expression> args; | ||
|
||
public FunctionCall(String id, List<Expression> args) { | ||
this.id = id; | ||
this.args = args; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FunctionCall{" + this.id + " {" + this.args + "} }"; | ||
} | ||
|
||
@Override | ||
public Expression simplify() { | ||
for (int i = 0; i < this.args.size(); i++) { | ||
this.args.set(i, this.args.get(i).simplify()); | ||
} | ||
|
||
return this; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/kroppeb/stareval/element/tree/UnaryExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package kroppeb.stareval.element.tree; | ||
|
||
import kroppeb.stareval.element.Expression; | ||
import kroppeb.stareval.parser.UnaryOp; | ||
|
||
public class UnaryExpression implements Expression { | ||
private final UnaryOp op; | ||
private Expression inner; | ||
|
||
public UnaryExpression(UnaryOp op, Expression inner) { | ||
this.op = op; | ||
this.inner = inner; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UnaryExpr{" + this.op + " {" + this.inner + "} }"; | ||
} | ||
|
||
@Override | ||
public Expression simplify() { | ||
this.inner = this.inner.simplify(); | ||
return this; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/kroppeb/stareval/element/tree/partial/PartialBinaryExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package kroppeb.stareval.element.tree.partial; | ||
|
||
import kroppeb.stareval.element.PriorityOperatorElement; | ||
import kroppeb.stareval.element.tree.BinaryExpression; | ||
import kroppeb.stareval.element.Expression; | ||
import kroppeb.stareval.parser.BinaryOp; | ||
|
||
public class PartialBinaryExpression extends PartialExpression implements PriorityOperatorElement { | ||
private final Expression left; | ||
private final BinaryOp op; | ||
|
||
public PartialBinaryExpression(Expression left, BinaryOp op) { | ||
this.left = left; | ||
this.op = op; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PartialBinaryExpression{ {" + this.left + "} " + this.op + "}"; | ||
} | ||
|
||
@Override | ||
public int getPriority() { | ||
return this.op.getPriority(); | ||
} | ||
|
||
@Override | ||
public BinaryExpression resolveWith(Expression right) { | ||
return new BinaryExpression(this.op, this.left, right); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/kroppeb/stareval/element/tree/partial/PartialExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package kroppeb.stareval.element.tree.partial; | ||
|
||
import kroppeb.stareval.element.Element; | ||
|
||
public abstract class PartialExpression implements Element { | ||
@Override | ||
public abstract String toString(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/kroppeb/stareval/element/tree/partial/UnfinishedArgsExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kroppeb.stareval.element.tree.partial; | ||
|
||
import kroppeb.stareval.element.Expression; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class UnfinishedArgsExpression extends PartialExpression { | ||
public final List<Expression> tokens = new ArrayList<>(); | ||
|
||
@Override | ||
public String toString() { | ||
return "UnfinishedArgs{" + this.tokens + "}"; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/kroppeb/stareval/exception/MissingTokenException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kroppeb.stareval.exception; | ||
|
||
public class MissingTokenException extends ParseException { | ||
public MissingTokenException(String message, int index) { | ||
super(message + " at index " + index); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/kroppeb/stareval/exception/ParseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package kroppeb.stareval.exception; | ||
|
||
public abstract class ParseException extends Exception{ | ||
public ParseException() { | ||
} | ||
|
||
public ParseException(String message) { | ||
super(message); | ||
} | ||
|
||
public ParseException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public ParseException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { | ||
super(message, cause, enableSuppression, writableStackTrace); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/kroppeb/stareval/exception/UnexpectedCharacterException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kroppeb.stareval.exception; | ||
|
||
public class UnexpectedCharacterException extends ParseException { | ||
public UnexpectedCharacterException(char expected, char actual, int index) { | ||
this("Expected to read '" + expected + "' but got '" + actual + "' at index " + index); | ||
} | ||
|
||
public UnexpectedCharacterException(char actual, int index) { | ||
this("Read an unexpected character '" + actual + "' at index " + index); | ||
} | ||
|
||
public UnexpectedCharacterException(String expected, char actual, int index) { | ||
this("Expected to read " + expected + " but got '" + actual + "' at index " + index); | ||
} | ||
|
||
private UnexpectedCharacterException(String message) { | ||
super(message); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/kroppeb/stareval/exception/UnexpectedEndingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package kroppeb.stareval.exception; | ||
|
||
public class UnexpectedEndingException extends ParseException { | ||
public UnexpectedEndingException() { | ||
this("Expected to read more text, but the string has ended"); | ||
} | ||
|
||
public UnexpectedEndingException(String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/kroppeb/stareval/exception/UnexpectedTokenException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kroppeb.stareval.exception; | ||
|
||
public class UnexpectedTokenException extends ParseException { | ||
public UnexpectedTokenException(String message, int index) { | ||
super(message + " at index " + index); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kroppeb.stareval.parser; | ||
|
||
public class BinaryOp { | ||
private final String name; | ||
private final int priority; | ||
|
||
public BinaryOp(String name, int priority) { | ||
this.name = name; | ||
this.priority = priority; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.name + "{" + this.priority + "}"; | ||
} | ||
|
||
public int getPriority() { | ||
return this.priority; | ||
} | ||
} |
Oops, something went wrong.