Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into mojmap
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Sep 11, 2021
2 parents 31855c6 + 4406454 commit a31ce6e
Show file tree
Hide file tree
Showing 34 changed files with 1,371 additions and 2 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ dependencies {
includeFabricApiModule "fabric-api-base"

// JUnit 5 Jupiter test engine
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package kroppeb.stareval.element;

public interface AccessibleExpression extends Expression {
}
4 changes: 4 additions & 0 deletions src/main/java/kroppeb/stareval/element/Element.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package kroppeb.stareval.element;

public interface Element {
}
10 changes: 10 additions & 0 deletions src/main/java/kroppeb/stareval/element/Expression.java
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;
}
}
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);
}
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 + "}";
}
}
16 changes: 16 additions & 0 deletions src/main/java/kroppeb/stareval/element/token/IdToken.java
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 src/main/java/kroppeb/stareval/element/token/NumberToken.java
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 + "}";
}
}
8 changes: 8 additions & 0 deletions src/main/java/kroppeb/stareval/element/token/Token.java
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();
}
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 src/main/java/kroppeb/stareval/element/tree/AccessExpression.java
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 src/main/java/kroppeb/stareval/element/tree/BinaryExpression.java
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 src/main/java/kroppeb/stareval/element/tree/FunctionCall.java
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 src/main/java/kroppeb/stareval/element/tree/UnaryExpression.java
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;
}
}
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);
}
}
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();
}
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 + "}";
}
}
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 src/main/java/kroppeb/stareval/exception/ParseException.java
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);
}
}
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);
}
}
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);
}
}
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);
}
}
20 changes: 20 additions & 0 deletions src/main/java/kroppeb/stareval/parser/BinaryOp.java
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;
}
}
Loading

0 comments on commit a31ce6e

Please sign in to comment.