make ParseException unchecked

This commit is contained in:
dfsek
2021-09-26 13:35:54 -07:00
parent 89d53d0ea3
commit 4d8d8f656a
17 changed files with 41 additions and 48 deletions

View File

@@ -78,7 +78,7 @@ public class Parser {
* *
* @throws ParseException If parsing fails. * @throws ParseException If parsing fails.
*/ */
public Block parse() throws ParseException { public Block parse() {
Tokenizer tokens = new Tokenizer(data); Tokenizer tokens = new Tokenizer(data);
// Parse ID // Parse ID
@@ -108,8 +108,7 @@ public class Parser {
}; };
} }
private WhileKeyword parseWhileLoop(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, Position start) private WhileKeyword parseWhileLoop(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, Position start) {
throws ParseException {
Returnable<?> first = parseExpression(tokens, true, variableMap); Returnable<?> first = parseExpression(tokens, true, variableMap);
ParserUtil.checkReturnType(first, Returnable.ReturnType.BOOLEAN); ParserUtil.checkReturnType(first, Returnable.ReturnType.BOOLEAN);
@@ -118,8 +117,7 @@ public class Parser {
return new WhileKeyword(parseStatementBlock(tokens, variableMap, true), (Returnable<Boolean>) first, start); // While loop return new WhileKeyword(parseStatementBlock(tokens, variableMap, true), (Returnable<Boolean>) first, start); // While loop
} }
private IfKeyword parseIfStatement(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, Position start, boolean loop) private IfKeyword parseIfStatement(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, Position start, boolean loop) {
throws ParseException {
Returnable<?> condition = parseExpression(tokens, true, variableMap); Returnable<?> condition = parseExpression(tokens, true, variableMap);
ParserUtil.checkReturnType(condition, Returnable.ReturnType.BOOLEAN); ParserUtil.checkReturnType(condition, Returnable.ReturnType.BOOLEAN);
@@ -146,8 +144,7 @@ public class Parser {
return new IfKeyword(statement, (Returnable<Boolean>) condition, elseIf, elseBlock, start); // If statement return new IfKeyword(statement, (Returnable<Boolean>) condition, elseIf, elseBlock, start); // If statement
} }
private Block parseStatementBlock(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, boolean loop) private Block parseStatementBlock(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, boolean loop) {
throws ParseException {
if(tokens.get().getType().equals(Token.Type.BLOCK_BEGIN)) { if(tokens.get().getType().equals(Token.Type.BLOCK_BEGIN)) {
ParserUtil.checkType(tokens.consume(), Token.Type.BLOCK_BEGIN); ParserUtil.checkType(tokens.consume(), Token.Type.BLOCK_BEGIN);
@@ -162,7 +159,7 @@ public class Parser {
} }
} }
private ForKeyword parseForLoop(Tokenizer tokens, Map<String, Returnable.ReturnType> old, Position start) throws ParseException { private ForKeyword parseForLoop(Tokenizer tokens, Map<String, Returnable.ReturnType> old, Position start) {
Map<String, Returnable.ReturnType> variableMap = new HashMap<>(old); // New scope Map<String, Returnable.ReturnType> variableMap = new HashMap<>(old); // New scope
Token f = tokens.get(); Token f = tokens.get();
ParserUtil.checkType(f, Token.Type.NUMBER_VARIABLE, Token.Type.STRING_VARIABLE, Token.Type.BOOLEAN_VARIABLE, Token.Type.IDENTIFIER); ParserUtil.checkType(f, Token.Type.NUMBER_VARIABLE, Token.Type.STRING_VARIABLE, Token.Type.BOOLEAN_VARIABLE, Token.Type.IDENTIFIER);
@@ -191,8 +188,7 @@ public class Parser {
start); start);
} }
private Returnable<?> parseExpression(Tokenizer tokens, boolean full, Map<String, Returnable.ReturnType> variableMap) private Returnable<?> parseExpression(Tokenizer tokens, boolean full, Map<String, Returnable.ReturnType> variableMap) {
throws ParseException {
boolean booleanInverted = false; // Check for boolean not operator boolean booleanInverted = false; // Check for boolean not operator
boolean negate = false; boolean negate = false;
if(tokens.get().getType().equals(Token.Type.BOOLEAN_NOT)) { if(tokens.get().getType().equals(Token.Type.BOOLEAN_NOT)) {
@@ -235,7 +231,7 @@ public class Parser {
return expression; return expression;
} }
private ConstantExpression<?> parseConstantExpression(Tokenizer tokens) throws ParseException { private ConstantExpression<?> parseConstantExpression(Tokenizer tokens) {
Token constantToken = tokens.consume(); Token constantToken = tokens.consume();
Position position = constantToken.getPosition(); Position position = constantToken.getPosition();
switch(constantToken.getType()) { switch(constantToken.getType()) {
@@ -252,15 +248,14 @@ public class Parser {
} }
} }
private Returnable<?> parseGroup(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) throws ParseException { private Returnable<?> parseGroup(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) {
ParserUtil.checkType(tokens.consume(), Token.Type.GROUP_BEGIN); ParserUtil.checkType(tokens.consume(), Token.Type.GROUP_BEGIN);
Returnable<?> expression = parseExpression(tokens, true, variableMap); // Parse inside of group as a separate expression Returnable<?> expression = parseExpression(tokens, true, variableMap); // Parse inside of group as a separate expression
ParserUtil.checkType(tokens.consume(), Token.Type.GROUP_END); ParserUtil.checkType(tokens.consume(), Token.Type.GROUP_END);
return expression; return expression;
} }
private BinaryOperation<?, ?> parseBinaryOperation(Returnable<?> left, Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) private BinaryOperation<?, ?> parseBinaryOperation(Returnable<?> left, Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) {
throws ParseException {
Token binaryOperator = tokens.consume(); Token binaryOperator = tokens.consume();
ParserUtil.checkBinaryOperator(binaryOperator); ParserUtil.checkBinaryOperator(binaryOperator);
@@ -275,7 +270,7 @@ public class Parser {
return assemble(left, right, binaryOperator); return assemble(left, right, binaryOperator);
} }
private BinaryOperation<?, ?> assemble(Returnable<?> left, Returnable<?> right, Token binaryOperator) throws ParseException { private BinaryOperation<?, ?> assemble(Returnable<?> left, Returnable<?> right, Token binaryOperator) {
if(binaryOperator.isStrictNumericOperator()) if(binaryOperator.isStrictNumericOperator())
ParserUtil.checkArithmeticOperation(left, right, binaryOperator); // Numeric type checking ParserUtil.checkArithmeticOperation(left, right, binaryOperator); // Numeric type checking
if(binaryOperator.isStrictBooleanOperator()) ParserUtil.checkBooleanOperation(left, right, binaryOperator); // Boolean type checking if(binaryOperator.isStrictBooleanOperator()) ParserUtil.checkBooleanOperation(left, right, binaryOperator); // Boolean type checking
@@ -315,8 +310,7 @@ public class Parser {
} }
} }
private Declaration<?> parseVariableDeclaration(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) private Declaration<?> parseVariableDeclaration(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) {
throws ParseException {
Token type = tokens.consume(); Token type = tokens.consume();
ParserUtil.checkType(type, Token.Type.STRING_VARIABLE, Token.Type.BOOLEAN_VARIABLE, Token.Type.NUMBER_VARIABLE); ParserUtil.checkType(type, Token.Type.STRING_VARIABLE, Token.Type.BOOLEAN_VARIABLE, Token.Type.NUMBER_VARIABLE);
@@ -337,7 +331,7 @@ public class Parser {
return new Declaration<>(tokens.get().getPosition(), identifier.getContent(), value, returnType); return new Declaration<>(tokens.get().getPosition(), identifier.getContent(), value, returnType);
} }
private Block parseBlock(Tokenizer tokens, Map<String, Returnable.ReturnType> superVars, boolean loop) throws ParseException { private Block parseBlock(Tokenizer tokens, Map<String, Returnable.ReturnType> superVars, boolean loop) {
List<Item<?>> parsedItems = new ArrayList<>(); List<Item<?>> parsedItems = new ArrayList<>();
Map<String, Returnable.ReturnType> parsedVariables = new HashMap<>( Map<String, Returnable.ReturnType> parsedVariables = new HashMap<>(
@@ -357,7 +351,7 @@ public class Parser {
return new Block(parsedItems, first.getPosition()); return new Block(parsedItems, first.getPosition());
} }
private Item<?> parseItem(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, boolean loop) throws ParseException { private Item<?> parseItem(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap, boolean loop) {
Token token = tokens.get(); Token token = tokens.get();
if(loop) ParserUtil.checkType(token, Token.Type.IDENTIFIER, Token.Type.IF_STATEMENT, Token.Type.WHILE_LOOP, Token.Type.FOR_LOOP, if(loop) ParserUtil.checkType(token, Token.Type.IDENTIFIER, Token.Type.IF_STATEMENT, Token.Type.WHILE_LOOP, Token.Type.FOR_LOOP,
Token.Type.NUMBER_VARIABLE, Token.Type.STRING_VARIABLE, Token.Type.BOOLEAN_VARIABLE, Token.Type.NUMBER_VARIABLE, Token.Type.STRING_VARIABLE, Token.Type.BOOLEAN_VARIABLE,
@@ -383,7 +377,7 @@ public class Parser {
else throw new UnsupportedOperationException("Unexpected token " + token.getType() + ": " + token.getPosition()); else throw new UnsupportedOperationException("Unexpected token " + token.getType() + ": " + token.getPosition());
} }
private Assignment<?> parseAssignment(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) throws ParseException { private Assignment<?> parseAssignment(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) {
Token identifier = tokens.consume(); Token identifier = tokens.consume();
ParserUtil.checkType(identifier, Token.Type.IDENTIFIER); ParserUtil.checkType(identifier, Token.Type.IDENTIFIER);
@@ -397,8 +391,7 @@ public class Parser {
return new Assignment<>(value, identifier.getContent(), identifier.getPosition()); return new Assignment<>(value, identifier.getContent(), identifier.getPosition());
} }
private Function<?> parseFunction(Tokenizer tokens, boolean fullStatement, Map<String, Returnable.ReturnType> variableMap) private Function<?> parseFunction(Tokenizer tokens, boolean fullStatement, Map<String, Returnable.ReturnType> variableMap) {
throws ParseException {
Token identifier = tokens.consume(); Token identifier = tokens.consume();
ParserUtil.checkType(identifier, Token.Type.IDENTIFIER); // First token must be identifier ParserUtil.checkType(identifier, Token.Type.IDENTIFIER); // First token must be identifier
@@ -440,7 +433,7 @@ public class Parser {
return id; return id;
} }
private List<Returnable<?>> getArgs(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) throws ParseException { private List<Returnable<?>> getArgs(Tokenizer tokens, Map<String, Returnable.ReturnType> variableMap) {
List<Returnable<?>> args = new ArrayList<>(); List<Returnable<?>> args = new ArrayList<>();
while(!tokens.get().getType().equals(Token.Type.GROUP_END)) { while(!tokens.get().getType().equals(Token.Type.GROUP_END)) {

View File

@@ -44,17 +44,17 @@ public class ParserUtil {
PRECEDENCE.put(Token.Type.BOOLEAN_OR, booleanOps); PRECEDENCE.put(Token.Type.BOOLEAN_OR, booleanOps);
} }
public static void checkType(Token token, Token.Type... expected) throws ParseException { public static void checkType(Token token, Token.Type... expected) {
for(Token.Type type : expected) if(token.getType().equals(type)) return; for(Token.Type type : expected) if(token.getType().equals(type)) return;
throw new ParseException("Expected " + Arrays.toString(expected) + " but found " + token.getType(), token.getPosition()); throw new ParseException("Expected " + Arrays.toString(expected) + " but found " + token.getType(), token.getPosition());
} }
public static void checkReturnType(Returnable<?> returnable, Returnable.ReturnType... types) throws ParseException { public static void checkReturnType(Returnable<?> returnable, Returnable.ReturnType... types) {
for(Returnable.ReturnType type : types) if(returnable.returnType().equals(type)) return; for(Returnable.ReturnType type : types) if(returnable.returnType().equals(type)) return;
throw new ParseException("Expected " + Arrays.toString(types) + " but found " + returnable.returnType(), returnable.getPosition()); throw new ParseException("Expected " + Arrays.toString(types) + " but found " + returnable.returnType(), returnable.getPosition());
} }
public static void checkArithmeticOperation(Returnable<?> left, Returnable<?> right, Token operation) throws ParseException { public static void checkArithmeticOperation(Returnable<?> left, Returnable<?> right, Token operation) {
if(!left.returnType().equals(Returnable.ReturnType.NUMBER) || !right.returnType().equals(Returnable.ReturnType.NUMBER)) { if(!left.returnType().equals(Returnable.ReturnType.NUMBER) || !right.returnType().equals(Returnable.ReturnType.NUMBER)) {
throw new ParseException( throw new ParseException(
"Operation " + operation.getType() + " not supported between " + left.returnType() + " and " + right.returnType(), "Operation " + operation.getType() + " not supported between " + left.returnType() + " and " + right.returnType(),
@@ -62,7 +62,7 @@ public class ParserUtil {
} }
} }
public static void checkBooleanOperation(Returnable<?> left, Returnable<?> right, Token operation) throws ParseException { public static void checkBooleanOperation(Returnable<?> left, Returnable<?> right, Token operation) {
if(!left.returnType().equals(Returnable.ReturnType.BOOLEAN) || !right.returnType().equals(Returnable.ReturnType.BOOLEAN)) { if(!left.returnType().equals(Returnable.ReturnType.BOOLEAN) || !right.returnType().equals(Returnable.ReturnType.BOOLEAN)) {
throw new ParseException( throw new ParseException(
"Operation " + operation.getType() + " not supported between " + left.returnType() + " and " + right.returnType(), "Operation " + operation.getType() + " not supported between " + left.returnType() + " and " + right.returnType(),
@@ -70,7 +70,7 @@ public class ParserUtil {
} }
} }
public static void checkVarType(Token token, Returnable.ReturnType returnType) throws ParseException { public static void checkVarType(Token token, Returnable.ReturnType returnType) {
if(returnType.equals(Returnable.ReturnType.STRING) && token.getType().equals(Token.Type.STRING_VARIABLE)) return; if(returnType.equals(Returnable.ReturnType.STRING) && token.getType().equals(Token.Type.STRING_VARIABLE)) return;
if(returnType.equals(Returnable.ReturnType.NUMBER) && token.getType().equals(Token.Type.NUMBER_VARIABLE)) return; if(returnType.equals(Returnable.ReturnType.NUMBER) && token.getType().equals(Token.Type.NUMBER_VARIABLE)) return;
if(returnType.equals(Returnable.ReturnType.BOOLEAN) && token.getType().equals(Token.Type.BOOLEAN_VARIABLE)) return; if(returnType.equals(Returnable.ReturnType.BOOLEAN) && token.getType().equals(Token.Type.BOOLEAN_VARIABLE)) return;
@@ -84,12 +84,12 @@ public class ParserUtil {
* *
* @throws ParseException If token isn't a binary operator * @throws ParseException If token isn't a binary operator
*/ */
public static void checkBinaryOperator(Token token) throws ParseException { public static void checkBinaryOperator(Token token) {
if(!token.isBinaryOperator()) if(!token.isBinaryOperator())
throw new ParseException("Expected binary operator, found " + token.getType(), token.getPosition()); throw new ParseException("Expected binary operator, found " + token.getType(), token.getPosition());
} }
public static Returnable.ReturnType getVariableReturnType(Token varToken) throws ParseException { public static Returnable.ReturnType getVariableReturnType(Token varToken) {
return switch(varToken.getType()) { return switch(varToken.getType()) {
case NUMBER_VARIABLE -> Returnable.ReturnType.NUMBER; case NUMBER_VARIABLE -> Returnable.ReturnType.NUMBER;
case STRING_VARIABLE -> Returnable.ReturnType.STRING; case STRING_VARIABLE -> Returnable.ReturnType.STRING;

View File

@@ -3,7 +3,7 @@ package com.dfsek.terra.addons.terrascript.parser.exceptions;
import com.dfsek.terra.addons.terrascript.tokenizer.Position; import com.dfsek.terra.addons.terrascript.tokenizer.Position;
public class ParseException extends Exception { public class ParseException extends RuntimeException {
private static final long serialVersionUID = 6744390543046766386L; private static final long serialVersionUID = 6744390543046766386L;
private final Position position; private final Position position;

View File

@@ -8,7 +8,7 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
public interface FunctionBuilder<T extends Function<?>> { public interface FunctionBuilder<T extends Function<?>> {
T build(List<Returnable<?>> argumentList, Position position) throws ParseException; T build(List<Returnable<?>> argumentList, Position position);
int argNumber(); int argNumber();

View File

@@ -56,7 +56,7 @@ public class StructureScript implements Structure {
private String tempID; private String tempID;
public StructureScript(InputStream inputStream, Platform platform, Registry<Structure> registry, Registry<LootTable> lootRegistry, public StructureScript(InputStream inputStream, Platform platform, Registry<Structure> registry, Registry<LootTable> lootRegistry,
Registry<FunctionBuilder<?>> functionRegistry) throws ParseException { Registry<FunctionBuilder<?>> functionRegistry) {
Parser parser; Parser parser;
try { try {
parser = new Parser(IOUtils.toString(inputStream, Charset.defaultCharset())); parser = new Parser(IOUtils.toString(inputStream, Charset.defaultCharset()));

View File

@@ -21,7 +21,7 @@ public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public BlockFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public BlockFunction build(List<Returnable<?>> argumentList, Position position) {
if(argumentList.size() < 4) throw new ParseException("Expected data", position); if(argumentList.size() < 4) throw new ParseException("Expected data", position);
Returnable<Boolean> booleanReturnable = new BooleanConstant(true, position); Returnable<Boolean> booleanReturnable = new BooleanConstant(true, position);
if(argumentList.size() == 5) booleanReturnable = (Returnable<Boolean>) argumentList.get(4); if(argumentList.size() == 5) booleanReturnable = (Returnable<Boolean>) argumentList.get(4);

View File

@@ -19,7 +19,7 @@ public class CheckFunctionBuilder implements FunctionBuilder<CheckFunction> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public CheckFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public CheckFunction build(List<Returnable<?>> argumentList, Position position) {
return new CheckFunction(platform, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new CheckFunction(platform, (Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), position); (Returnable<Number>) argumentList.get(2), position);
} }

View File

@@ -19,7 +19,7 @@ public class EntityFunctionBuilder implements FunctionBuilder<EntityFunction> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public EntityFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public EntityFunction build(List<Returnable<?>> argumentList, Position position) {
return new EntityFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new EntityFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position);
} }

View File

@@ -19,7 +19,7 @@ public class PullFunctionBuilder implements FunctionBuilder<PullFunction> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public PullFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public PullFunction build(List<Returnable<?>> argumentList, Position position) {
return new PullFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new PullFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position);
} }

View File

@@ -12,7 +12,7 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
public class RandomFunctionBuilder implements FunctionBuilder<RandomFunction> { public class RandomFunctionBuilder implements FunctionBuilder<RandomFunction> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public RandomFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public RandomFunction build(List<Returnable<?>> argumentList, Position position) {
return new RandomFunction((Returnable<Number>) argumentList.get(0), position); return new RandomFunction((Returnable<Number>) argumentList.get(0), position);
} }

View File

@@ -11,7 +11,7 @@ import com.dfsek.terra.addons.terrascript.tokenizer.Position;
public class RecursionsFunctionBuilder implements FunctionBuilder<RecursionsFunction> { public class RecursionsFunctionBuilder implements FunctionBuilder<RecursionsFunction> {
@Override @Override
public RecursionsFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public RecursionsFunction build(List<Returnable<?>> argumentList, Position position) {
return new RecursionsFunction(position); return new RecursionsFunction(position);
} }

View File

@@ -16,7 +16,7 @@ public class SetMarkFunctionBuilder implements FunctionBuilder<SetMarkFunction>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public SetMarkFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public SetMarkFunction build(List<Returnable<?>> argumentList, Position position) {
return new SetMarkFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new SetMarkFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), position); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), position);
} }

View File

@@ -19,7 +19,7 @@ public class StateFunctionBuilder implements FunctionBuilder<StateFunction> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public StateFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public StateFunction build(List<Returnable<?>> argumentList, Position position) {
if(argumentList.size() < 4) throw new ParseException("Expected data", position); if(argumentList.size() < 4) throw new ParseException("Expected data", position);
return new StateFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), return new StateFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1),
(Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position); (Returnable<Number>) argumentList.get(2), (Returnable<String>) argumentList.get(3), platform, position);

View File

@@ -24,7 +24,7 @@ public class StructureFunctionBuilder implements FunctionBuilder<StructureFuncti
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public StructureFunction build(List<Returnable<?>> argumentList, Position position) throws ParseException { public StructureFunction build(List<Returnable<?>> argumentList, Position position) {
if(argumentList.size() < 5) throw new ParseException("Expected rotations", position); if(argumentList.size() < 5) throw new ParseException("Expected rotations", position);
return new StructureFunction((Returnable<Number>) argumentList.remove(0), (Returnable<Number>) argumentList.remove(0), return new StructureFunction((Returnable<Number>) argumentList.remove(0), (Returnable<Number>) argumentList.remove(0),

View File

@@ -25,7 +25,7 @@ public class EntityFunction implements Function<Void> {
private final Platform platform; private final Platform platform;
public EntityFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform platform, public EntityFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform platform,
Position position) throws ParseException { Position position) {
this.position = position; this.position = position;
this.platform = platform; this.platform = platform;
if(!(data instanceof ConstantExpression)) throw new ParseException("Entity data must be constant", data.getPosition()); if(!(data instanceof ConstantExpression)) throw new ParseException("Entity data must be constant", data.getPosition());

View File

@@ -26,7 +26,7 @@ public class PullFunction implements Function<Void> {
private final Position position; private final Position position;
public PullFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform platform, public PullFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Platform platform,
Position position) throws ParseException { Position position) {
this.position = position; this.position = position;
if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition()); if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition());

View File

@@ -20,7 +20,7 @@ public class Tokenizer {
private Token current; private Token current;
private Token last; private Token last;
public Tokenizer(String data) throws ParseException { public Tokenizer(String data) {
reader = new Lookahead(new StringReader(data + '\0')); reader = new Lookahead(new StringReader(data + '\0'));
current = fetchCheck(); current = fetchCheck();
} }
@@ -32,7 +32,7 @@ public class Tokenizer {
* *
* @throws ParseException If token does not exist * @throws ParseException If token does not exist
*/ */
public Token get() throws ParseException { public Token get() {
if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition()); if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition());
return current; return current;
} }
@@ -44,14 +44,14 @@ public class Tokenizer {
* *
* @throws ParseException If token does not exist * @throws ParseException If token does not exist
*/ */
public Token consume() throws ParseException { public Token consume() {
if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition()); if(!hasNext()) throw new ParseException("Unexpected end of input", last.getPosition());
Token temp = current; Token temp = current;
current = fetchCheck(); current = fetchCheck();
return temp; return temp;
} }
private Token fetchCheck() throws ParseException { private Token fetchCheck() {
Token fetch = fetch(); Token fetch = fetch();
if(fetch != null) { if(fetch != null) {
last = fetch; last = fetch;