mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 14:00:14 +00:00
Make error handler only handle compilation exceptions
This commit is contained in:
1 parent
ff031df903
commit
c3909ca1e0
4 files changed
+31
-6
No files matched your search
+6
-4
@@ -1,19 +1,21 @@
|
|||||||
package com.dfsek.terra.addons.terrascript.v2;
|
package com.dfsek.terra.addons.terrascript.v2;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.terrascript.v2.exception.CompilationException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class ErrorHandler {
|
public class ErrorHandler {
|
||||||
|
|
||||||
private final List<Exception> exceptions = new ArrayList<>();
|
private final List<CompilationException> exceptions = new ArrayList<>();
|
||||||
|
|
||||||
public void add(Exception e) {
|
public void add(CompilationException e) {
|
||||||
exceptions.add(e);
|
exceptions.add(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void throwAny() throws Exception {
|
public void throwAny() throws CompilationException {
|
||||||
for(Exception e : exceptions) {
|
for(CompilationException e : exceptions) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.terrascript.v2.exception.CompilationException;
|
||||||
|
import com.dfsek.terra.addons.terrascript.v2.lexer.SourcePosition;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidArgumentsException extends CompilationException {
|
||||||
|
public InvalidArgumentsException(String message, SourcePosition position) {
|
||||||
|
super(message, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis;
|
||||||
|
|
||||||
|
import com.dfsek.terra.addons.terrascript.v2.exception.CompilationException;
|
||||||
|
import com.dfsek.terra.addons.terrascript.v2.lexer.SourcePosition;
|
||||||
|
|
||||||
|
|
||||||
|
public class InvalidCalleeException extends CompilationException {
|
||||||
|
public InvalidCalleeException(String message, SourcePosition position) {
|
||||||
|
super(message, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -17,6 +17,7 @@ import com.dfsek.terra.addons.terrascript.v2.ast.Expr.Void;
|
|||||||
import com.dfsek.terra.addons.terrascript.v2.ast.Stmt;
|
import com.dfsek.terra.addons.terrascript.v2.ast.Stmt;
|
||||||
import com.dfsek.terra.addons.terrascript.v2.ast.TypedExpr;
|
import com.dfsek.terra.addons.terrascript.v2.ast.TypedExpr;
|
||||||
import com.dfsek.terra.addons.terrascript.v2.ast.TypedStmt;
|
import com.dfsek.terra.addons.terrascript.v2.ast.TypedStmt;
|
||||||
|
import com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis.InvalidArgumentsException;
|
||||||
import com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis.InvalidCalleeException;
|
import com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis.InvalidCalleeException;
|
||||||
import com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis.InvalidFunctionDeclarationException;
|
import com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis.InvalidFunctionDeclarationException;
|
||||||
import com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis.InvalidTypeException;
|
import com.dfsek.terra.addons.terrascript.v2.exception.semanticanalysis.InvalidTypeException;
|
||||||
@@ -62,7 +63,7 @@ public class TypeChecker implements Visitor<TypedExpr>, Stmt.Visitor<TypedStmt>
|
|||||||
if(leftType.typeOf(Type.STRING) || rightType.typeOf(Type.STRING)) {
|
if(leftType.typeOf(Type.STRING) || rightType.typeOf(Type.STRING)) {
|
||||||
yield Type.STRING;
|
yield Type.STRING;
|
||||||
}
|
}
|
||||||
errorHandler.add(new RuntimeException("Addition operands must be either both of type '" + Type.NUMBER + "', or one of type '" + Type.STRING + "'"));
|
errorHandler.add(new InvalidTypeException("Addition operands must be either both of type '" + Type.NUMBER + "', or one of type '" + Type.STRING + "'", expr.position));
|
||||||
yield Type.VOID;
|
yield Type.VOID;
|
||||||
}
|
}
|
||||||
case SUBTRACT, MULTIPLY, DIVIDE, MODULO -> {
|
case SUBTRACT, MULTIPLY, DIVIDE, MODULO -> {
|
||||||
@@ -114,7 +115,7 @@ public class TypeChecker implements Visitor<TypedExpr>, Stmt.Visitor<TypedStmt>
|
|||||||
List<Type> parameters = functionType.getParameters();
|
List<Type> parameters = functionType.getParameters();
|
||||||
|
|
||||||
if(arguments.size() != parameters.size())
|
if(arguments.size() != parameters.size())
|
||||||
errorHandler.add(new ParseException(
|
errorHandler.add(new InvalidArgumentsException(
|
||||||
"Provided " + arguments.size() + " arguments to function call, expected " + parameters.size() + " arguments", expr.position));
|
"Provided " + arguments.size() + " arguments to function call, expected " + parameters.size() + " arguments", expr.position));
|
||||||
|
|
||||||
for(int i = 0; i < parameters.size(); i++) {
|
for(int i = 0; i < parameters.size(); i++) {
|
||||||
|
|||||||
Reference in new issue
Block a user