mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-27 06:20:05 +00:00
cleanup, refactor, remove logging
This commit is contained in:
1 parent
7d72a91bb7
commit
fe17683d27
3 files changed
+27
-15
No files matched your search
@@ -85,12 +85,12 @@ public class Parser {
|
|||||||
Keyword<?> k = null;
|
Keyword<?> k = null;
|
||||||
if(identifier.getContent().equals("if")) {
|
if(identifier.getContent().equals("if")) {
|
||||||
|
|
||||||
checkType(tokens.remove(0), Token.Type.BODY_BEGIN);
|
checkType(tokens.remove(0), Token.Type.GROUP_BEGIN);
|
||||||
|
|
||||||
Returnable<?> comparator = parseExpression(tokens, true);
|
Returnable<?> comparator = parseExpression(tokens, true);
|
||||||
checkReturnType(comparator, Returnable.ReturnType.BOOLEAN);
|
checkReturnType(comparator, Returnable.ReturnType.BOOLEAN);
|
||||||
|
|
||||||
checkType(tokens.remove(0), Token.Type.BODY_END);
|
checkType(tokens.remove(0), Token.Type.GROUP_END);
|
||||||
|
|
||||||
checkType(tokens.remove(0), Token.Type.BLOCK_BEGIN);
|
checkType(tokens.remove(0), Token.Type.BLOCK_BEGIN);
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ public class Parser {
|
|||||||
private Returnable<?> parseExpression(List<Token> tokens, boolean full) throws ParseException {
|
private Returnable<?> parseExpression(List<Token> tokens, boolean full) throws ParseException {
|
||||||
System.out.println(tokens.get(0));
|
System.out.println(tokens.get(0));
|
||||||
Token first = tokens.get(0);
|
Token first = tokens.get(0);
|
||||||
checkType(first, Token.Type.IDENTIFIER, Token.Type.BOOLEAN, Token.Type.STRING, Token.Type.NUMBER, Token.Type.BOOLEAN_NOT, Token.Type.BODY_BEGIN);
|
checkType(first, Token.Type.IDENTIFIER, Token.Type.BOOLEAN, Token.Type.STRING, Token.Type.NUMBER, Token.Type.BOOLEAN_NOT, Token.Type.GROUP_BEGIN);
|
||||||
|
|
||||||
boolean not = false;
|
boolean not = false;
|
||||||
if(first.getType().equals(Token.Type.BOOLEAN_NOT)) {
|
if(first.getType().equals(Token.Type.BOOLEAN_NOT)) {
|
||||||
@@ -152,12 +152,9 @@ public class Parser {
|
|||||||
Returnable<?> right = parseExpression(tokens, false);
|
Returnable<?> right = parseExpression(tokens, false);
|
||||||
|
|
||||||
Token other = tokens.get(0);
|
Token other = tokens.get(0);
|
||||||
System.out.println("other: " + other);
|
|
||||||
if(other.isBinaryOperator() && (other.getType().equals(Token.Type.MULTIPLICATION_OPERATOR) || other.getType().equals(Token.Type.DIVISION_OPERATOR))) {
|
if(other.isBinaryOperator() && (other.getType().equals(Token.Type.MULTIPLICATION_OPERATOR) || other.getType().equals(Token.Type.DIVISION_OPERATOR))) {
|
||||||
System.out.println("using left");
|
|
||||||
return assemble(left, parseBinaryOperation(right, tokens), binaryOperator);
|
return assemble(left, parseBinaryOperation(right, tokens), binaryOperator);
|
||||||
} else if(other.isBinaryOperator()) {
|
} else if(other.isBinaryOperator()) {
|
||||||
System.out.println("using right");
|
|
||||||
return parseBinaryOperation(assemble(left, right, binaryOperator), tokens);
|
return parseBinaryOperation(assemble(left, right, binaryOperator), tokens);
|
||||||
}
|
}
|
||||||
return assemble(left, right, binaryOperator);
|
return assemble(left, right, binaryOperator);
|
||||||
@@ -232,7 +229,7 @@ public class Parser {
|
|||||||
if(!functions.containsKey(identifier.getContent()))
|
if(!functions.containsKey(identifier.getContent()))
|
||||||
throw new ParseException("No such function " + identifier.getContent() + ": " + identifier.getPosition());
|
throw new ParseException("No such function " + identifier.getContent() + ": " + identifier.getPosition());
|
||||||
|
|
||||||
checkType(tokens.remove(0), Token.Type.BODY_BEGIN); // Second is body begin
|
checkType(tokens.remove(0), Token.Type.GROUP_BEGIN); // Second is body begin
|
||||||
|
|
||||||
|
|
||||||
List<Returnable<?>> args = getArgs(tokens); // Extract arguments, consume the rest.
|
List<Returnable<?>> args = getArgs(tokens); // Extract arguments, consume the rest.
|
||||||
@@ -251,9 +248,9 @@ public class Parser {
|
|||||||
private List<Returnable<?>> getArgs(List<Token> tokens) throws ParseException {
|
private List<Returnable<?>> getArgs(List<Token> tokens) throws ParseException {
|
||||||
List<Returnable<?>> args = new GlueList<>();
|
List<Returnable<?>> args = new GlueList<>();
|
||||||
|
|
||||||
while(!tokens.get(0).getType().equals(Token.Type.BODY_END)) {
|
while(!tokens.get(0).getType().equals(Token.Type.GROUP_END)) {
|
||||||
args.add(parseExpression(tokens, true));
|
args.add(parseExpression(tokens, true));
|
||||||
checkType(tokens.get(0), Token.Type.SEPARATOR, Token.Type.BODY_END);
|
checkType(tokens.get(0), Token.Type.SEPARATOR, Token.Type.GROUP_END);
|
||||||
if(tokens.get(0).getType().equals(Token.Type.SEPARATOR)) tokens.remove(0);
|
if(tokens.get(0).getType().equals(Token.Type.SEPARATOR)) tokens.remove(0);
|
||||||
}
|
}
|
||||||
return args;
|
return args;
|
||||||
|
|||||||
@@ -78,13 +78,13 @@ public class Token {
|
|||||||
*/
|
*/
|
||||||
BOOLEAN,
|
BOOLEAN,
|
||||||
/**
|
/**
|
||||||
* Beginning of function body
|
* Beginning of group
|
||||||
*/
|
*/
|
||||||
BODY_BEGIN,
|
GROUP_BEGIN,
|
||||||
/**
|
/**
|
||||||
* Ending of function body
|
* Ending of group
|
||||||
*/
|
*/
|
||||||
BODY_END,
|
GROUP_END,
|
||||||
/**
|
/**
|
||||||
* End of statement
|
* End of statement
|
||||||
*/
|
*/
|
||||||
@@ -109,10 +109,25 @@ public class Token {
|
|||||||
* Boolean equals operator
|
* Boolean equals operator
|
||||||
*/
|
*/
|
||||||
EQUALS_OPERATOR,
|
EQUALS_OPERATOR,
|
||||||
|
/**
|
||||||
|
* Boolean not equals operator
|
||||||
|
*/
|
||||||
NOT_EQUALS_OPERATOR,
|
NOT_EQUALS_OPERATOR,
|
||||||
|
/**
|
||||||
|
* Boolean greater than operator
|
||||||
|
*/
|
||||||
GREATER_THAN_OPERATOR,
|
GREATER_THAN_OPERATOR,
|
||||||
|
/**
|
||||||
|
* Boolean less than operator
|
||||||
|
*/
|
||||||
LESS_THAN_OPERATOR,
|
LESS_THAN_OPERATOR,
|
||||||
|
/**
|
||||||
|
* Boolean greater than or equal to operator
|
||||||
|
*/
|
||||||
GREATER_THAN_OR_EQUALS_OPERATOR,
|
GREATER_THAN_OR_EQUALS_OPERATOR,
|
||||||
|
/**
|
||||||
|
* Boolean less than or equal to operator
|
||||||
|
*/
|
||||||
LESS_THAN_OR_EQUALS_OPERATOR,
|
LESS_THAN_OR_EQUALS_OPERATOR,
|
||||||
/**
|
/**
|
||||||
* Addition/concatenation operator
|
* Addition/concatenation operator
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ public class Tokenizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(reader.current().is('('))
|
if(reader.current().is('('))
|
||||||
return new Token(reader.consume().toString(), Token.Type.BODY_BEGIN, new Position(reader.getLine(), reader.getIndex()));
|
return new Token(reader.consume().toString(), Token.Type.GROUP_BEGIN, new Position(reader.getLine(), reader.getIndex()));
|
||||||
if(reader.current().is(')'))
|
if(reader.current().is(')'))
|
||||||
return new Token(reader.consume().toString(), Token.Type.BODY_END, new Position(reader.getLine(), reader.getIndex()));
|
return new Token(reader.consume().toString(), Token.Type.GROUP_END, new Position(reader.getLine(), reader.getIndex()));
|
||||||
if(reader.current().is(';'))
|
if(reader.current().is(';'))
|
||||||
return new Token(reader.consume().toString(), Token.Type.STATEMENT_END, new Position(reader.getLine(), reader.getIndex()));
|
return new Token(reader.consume().toString(), Token.Type.STATEMENT_END, new Position(reader.getLine(), reader.getIndex()));
|
||||||
if(reader.current().is(','))
|
if(reader.current().is(','))
|
||||||
|
|||||||
Reference in new issue
Block a user