mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-20 23:30:29 +00:00
Formatting & name changes
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer;
|
||||
package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
public class Char {
|
||||
private final char character;
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer;
|
||||
package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
@@ -13,20 +13,21 @@ import java.io.StringReader;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Token.TokenType;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.exceptions.EOFException;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.exceptions.FormatException;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.exceptions.TokenizerException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.exceptions.EOFException;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.exceptions.FormatException;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.exceptions.TokenizerException;
|
||||
|
||||
|
||||
public class Tokenizer {
|
||||
public class Lexer {
|
||||
public static final Set<Character> syntaxSignificant = Sets.newHashSet(';', '(', ')', '"', ',', '\\', '=', '{', '}', '+', '-', '*', '/',
|
||||
'>', '<', '!'); // Reserved chars
|
||||
private final LookaheadStream reader;
|
||||
private final Stack<Token> bracketStack = new Stack<>();
|
||||
private Token current;
|
||||
|
||||
public Tokenizer(String data) {
|
||||
public Lexer(String data) {
|
||||
reader = new LookaheadStream(new StringReader(data + '\0'));
|
||||
current = tokenize();
|
||||
}
|
||||
@@ -50,7 +51,7 @@ public class Tokenizer {
|
||||
* @throws ParseException If token does not exist
|
||||
*/
|
||||
public Token consume() {
|
||||
if (current.getType() == Token.Type.END_OF_FILE) return current;
|
||||
if(current.getType() == TokenType.END_OF_FILE) return current;
|
||||
Token temp = current;
|
||||
current = tokenize();
|
||||
return temp;
|
||||
@@ -62,7 +63,7 @@ public class Tokenizer {
|
||||
* @return {@code true} if more tokens are present, otherwise {@code false}
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return current.getType() != Token.Type.END_OF_FILE;
|
||||
return current.getType() != TokenType.END_OF_FILE;
|
||||
}
|
||||
|
||||
private Token tokenize() throws TokenizerException {
|
||||
@@ -76,29 +77,29 @@ public class Tokenizer {
|
||||
|
||||
// Reached end of file
|
||||
if(reader.current().isEOF()) {
|
||||
if (!bracketStack.isEmpty()) throw new ParseException("Dangling closing brace", bracketStack.peek().getPosition());
|
||||
return new Token(reader.consume().toString(), Token.Type.END_OF_FILE, reader.getPosition());
|
||||
if(!bracketStack.isEmpty()) throw new ParseException("Dangling closing brace", bracketStack.peek().getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.END_OF_FILE, reader.getPosition());
|
||||
}
|
||||
|
||||
// Check if operator token
|
||||
if(reader.matchesString("==", true))
|
||||
return new Token("==", Token.Type.EQUALS_OPERATOR, reader.getPosition());
|
||||
return new Token("==", TokenType.EQUALS_OPERATOR, reader.getPosition());
|
||||
if(reader.matchesString("!=", true))
|
||||
return new Token("!=", Token.Type.NOT_EQUALS_OPERATOR, reader.getPosition());
|
||||
return new Token("!=", TokenType.NOT_EQUALS_OPERATOR, reader.getPosition());
|
||||
if(reader.matchesString(">=", true))
|
||||
return new Token(">=", Token.Type.GREATER_THAN_OR_EQUALS_OPERATOR, reader.getPosition());
|
||||
return new Token(">=", TokenType.GREATER_THAN_OR_EQUALS_OPERATOR, reader.getPosition());
|
||||
if(reader.matchesString("<=", true))
|
||||
return new Token("<=", Token.Type.LESS_THAN_OR_EQUALS_OPERATOR, reader.getPosition());
|
||||
return new Token("<=", TokenType.LESS_THAN_OR_EQUALS_OPERATOR, reader.getPosition());
|
||||
if(reader.matchesString(">", true))
|
||||
return new Token(">", Token.Type.GREATER_THAN_OPERATOR, reader.getPosition());
|
||||
return new Token(">", TokenType.GREATER_THAN_OPERATOR, reader.getPosition());
|
||||
if(reader.matchesString("<", true))
|
||||
return new Token("<", Token.Type.LESS_THAN_OPERATOR, reader.getPosition());
|
||||
return new Token("<", TokenType.LESS_THAN_OPERATOR, reader.getPosition());
|
||||
|
||||
// Check if logical operator
|
||||
if(reader.matchesString("||", true))
|
||||
return new Token("||", Token.Type.BOOLEAN_OR, reader.getPosition());
|
||||
return new Token("||", TokenType.BOOLEAN_OR, reader.getPosition());
|
||||
if(reader.matchesString("&&", true))
|
||||
return new Token("&&", Token.Type.BOOLEAN_AND, reader.getPosition());
|
||||
return new Token("&&", TokenType.BOOLEAN_AND, reader.getPosition());
|
||||
|
||||
// Check if number
|
||||
if(isNumberStart()) {
|
||||
@@ -106,7 +107,7 @@ public class Tokenizer {
|
||||
while(!reader.current().isEOF() && isNumberLike()) {
|
||||
num.append(reader.consume());
|
||||
}
|
||||
return new Token(num.toString(), Token.Type.NUMBER, reader.getPosition());
|
||||
return new Token(num.toString(), TokenType.NUMBER, reader.getPosition());
|
||||
}
|
||||
|
||||
// Check if string literal
|
||||
@@ -126,45 +127,45 @@ public class Tokenizer {
|
||||
}
|
||||
reader.consume(); // Consume last quote
|
||||
|
||||
return new Token(string.toString(), Token.Type.STRING, reader.getPosition());
|
||||
return new Token(string.toString(), TokenType.STRING, reader.getPosition());
|
||||
}
|
||||
|
||||
if(reader.current().is('('))
|
||||
return new Token(reader.consume().toString(), Token.Type.GROUP_BEGIN, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.GROUP_BEGIN, reader.getPosition());
|
||||
if(reader.current().is(')'))
|
||||
return new Token(reader.consume().toString(), Token.Type.GROUP_END, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.GROUP_END, reader.getPosition());
|
||||
if(reader.current().is(';'))
|
||||
return new Token(reader.consume().toString(), Token.Type.STATEMENT_END, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.STATEMENT_END, reader.getPosition());
|
||||
if(reader.current().is(','))
|
||||
return new Token(reader.consume().toString(), Token.Type.SEPARATOR, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.SEPARATOR, reader.getPosition());
|
||||
|
||||
if(reader.current().is('{')) {
|
||||
Token token = new Token(reader.consume().toString(), Token.Type.BLOCK_BEGIN, reader.getPosition());
|
||||
Token token = new Token(reader.consume().toString(), TokenType.BLOCK_BEGIN, reader.getPosition());
|
||||
bracketStack.push(token);
|
||||
return token;
|
||||
}
|
||||
if(reader.current().is('}')) {
|
||||
if(bracketStack.isEmpty()) throw new ParseException("Dangling opening brace", new SourcePosition(0, 0));
|
||||
bracketStack.pop();
|
||||
return new Token(reader.consume().toString(), Token.Type.BLOCK_END, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.BLOCK_END, reader.getPosition());
|
||||
}
|
||||
|
||||
if(reader.current().is('='))
|
||||
return new Token(reader.consume().toString(), Token.Type.ASSIGNMENT, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.ASSIGNMENT, reader.getPosition());
|
||||
if(reader.current().is('+'))
|
||||
return new Token(reader.consume().toString(), Token.Type.ADDITION_OPERATOR, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.ADDITION_OPERATOR, reader.getPosition());
|
||||
if(reader.current().is('-'))
|
||||
return new Token(reader.consume().toString(), Token.Type.SUBTRACTION_OPERATOR,
|
||||
return new Token(reader.consume().toString(), TokenType.SUBTRACTION_OPERATOR,
|
||||
reader.getPosition());
|
||||
if(reader.current().is('*'))
|
||||
return new Token(reader.consume().toString(), Token.Type.MULTIPLICATION_OPERATOR,
|
||||
return new Token(reader.consume().toString(), TokenType.MULTIPLICATION_OPERATOR,
|
||||
reader.getPosition());
|
||||
if(reader.current().is('/'))
|
||||
return new Token(reader.consume().toString(), Token.Type.DIVISION_OPERATOR, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.DIVISION_OPERATOR, reader.getPosition());
|
||||
if(reader.current().is('%'))
|
||||
return new Token(reader.consume().toString(), Token.Type.MODULO_OPERATOR, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.MODULO_OPERATOR, reader.getPosition());
|
||||
if(reader.current().is('!'))
|
||||
return new Token(reader.consume().toString(), Token.Type.BOOLEAN_NOT, reader.getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.BOOLEAN_NOT, reader.getPosition());
|
||||
|
||||
// Read word
|
||||
StringBuilder token = new StringBuilder();
|
||||
@@ -177,39 +178,39 @@ public class Tokenizer {
|
||||
|
||||
// Check if word is a keyword
|
||||
if(tokenString.equals("true"))
|
||||
return new Token(tokenString, Token.Type.BOOLEAN, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.BOOLEAN, reader.getPosition());
|
||||
if(tokenString.equals("false"))
|
||||
return new Token(tokenString, Token.Type.BOOLEAN, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.BOOLEAN, reader.getPosition());
|
||||
|
||||
if(tokenString.equals("num"))
|
||||
return new Token(tokenString, Token.Type.TYPE_NUMBER, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.TYPE_NUMBER, reader.getPosition());
|
||||
if(tokenString.equals("str"))
|
||||
return new Token(tokenString, Token.Type.TYPE_STRING, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.TYPE_STRING, reader.getPosition());
|
||||
if(tokenString.equals("bool"))
|
||||
return new Token(tokenString, Token.Type.TYPE_BOOLEAN, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.TYPE_BOOLEAN, reader.getPosition());
|
||||
if(tokenString.equals("void"))
|
||||
return new Token(tokenString, Token.Type.TYPE_VOID, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.TYPE_VOID, reader.getPosition());
|
||||
|
||||
if(tokenString.equals("if"))
|
||||
return new Token(tokenString, Token.Type.IF_STATEMENT, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.IF_STATEMENT, reader.getPosition());
|
||||
if(tokenString.equals("else"))
|
||||
return new Token(tokenString, Token.Type.ELSE, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.ELSE, reader.getPosition());
|
||||
if(tokenString.equals("while"))
|
||||
return new Token(tokenString, Token.Type.WHILE_LOOP, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.WHILE_LOOP, reader.getPosition());
|
||||
if(tokenString.equals("for"))
|
||||
return new Token(tokenString, Token.Type.FOR_LOOP, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.FOR_LOOP, reader.getPosition());
|
||||
|
||||
if(tokenString.equals("return"))
|
||||
return new Token(tokenString, Token.Type.RETURN, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.RETURN, reader.getPosition());
|
||||
if(tokenString.equals("continue"))
|
||||
return new Token(tokenString, Token.Type.CONTINUE, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.CONTINUE, reader.getPosition());
|
||||
if(tokenString.equals("break"))
|
||||
return new Token(tokenString, Token.Type.BREAK, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.BREAK, reader.getPosition());
|
||||
if(tokenString.equals("fail"))
|
||||
return new Token(tokenString, Token.Type.FAIL, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.FAIL, reader.getPosition());
|
||||
|
||||
// If not keyword, assume it is an identifier
|
||||
return new Token(tokenString, Token.Type.IDENTIFIER, reader.getPosition());
|
||||
return new Token(tokenString, TokenType.IDENTIFIER, reader.getPosition());
|
||||
}
|
||||
|
||||
private void skipLine() {
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer;
|
||||
package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer;
|
||||
package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
public class SourcePosition {
|
||||
private final int line;
|
||||
@@ -5,14 +5,14 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer;
|
||||
package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
public class Token {
|
||||
private final String content;
|
||||
private final Type type;
|
||||
private final TokenType type;
|
||||
private final SourcePosition start;
|
||||
|
||||
public Token(String content, Type type, SourcePosition start) {
|
||||
public Token(String content, TokenType type, SourcePosition start) {
|
||||
this.content = content;
|
||||
this.type = type;
|
||||
this.start = start;
|
||||
@@ -23,7 +23,7 @@ public class Token {
|
||||
return type + ": '" + content + "'";
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
public TokenType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -36,58 +36,58 @@ public class Token {
|
||||
}
|
||||
|
||||
public boolean isConstant() {
|
||||
return this.type.equals(Type.NUMBER) || this.type.equals(Type.STRING) || this.type.equals(Type.BOOLEAN);
|
||||
return this.type.equals(TokenType.NUMBER) || this.type.equals(TokenType.STRING) || this.type.equals(TokenType.BOOLEAN);
|
||||
}
|
||||
|
||||
public boolean isType(Type type) {
|
||||
public boolean isType(TokenType type) {
|
||||
return type == getType();
|
||||
}
|
||||
|
||||
public boolean isBinaryOperator() {
|
||||
return type.equals(Type.ADDITION_OPERATOR)
|
||||
|| type.equals(Type.SUBTRACTION_OPERATOR)
|
||||
|| type.equals(Type.MULTIPLICATION_OPERATOR)
|
||||
|| type.equals(Type.DIVISION_OPERATOR)
|
||||
|| type.equals(Type.EQUALS_OPERATOR)
|
||||
|| type.equals(Type.NOT_EQUALS_OPERATOR)
|
||||
|| type.equals(Type.LESS_THAN_OPERATOR)
|
||||
|| type.equals(Type.GREATER_THAN_OPERATOR)
|
||||
|| type.equals(Type.LESS_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(Type.GREATER_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(Type.BOOLEAN_OR)
|
||||
|| type.equals(Type.BOOLEAN_AND)
|
||||
|| type.equals(Type.MODULO_OPERATOR);
|
||||
return type.equals(TokenType.ADDITION_OPERATOR)
|
||||
|| type.equals(TokenType.SUBTRACTION_OPERATOR)
|
||||
|| type.equals(TokenType.MULTIPLICATION_OPERATOR)
|
||||
|| type.equals(TokenType.DIVISION_OPERATOR)
|
||||
|| type.equals(TokenType.EQUALS_OPERATOR)
|
||||
|| type.equals(TokenType.NOT_EQUALS_OPERATOR)
|
||||
|| type.equals(TokenType.LESS_THAN_OPERATOR)
|
||||
|| type.equals(TokenType.GREATER_THAN_OPERATOR)
|
||||
|| type.equals(TokenType.LESS_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(TokenType.GREATER_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(TokenType.BOOLEAN_OR)
|
||||
|| type.equals(TokenType.BOOLEAN_AND)
|
||||
|| type.equals(TokenType.MODULO_OPERATOR);
|
||||
}
|
||||
|
||||
public boolean isStrictNumericOperator() {
|
||||
return type.equals(Type.SUBTRACTION_OPERATOR)
|
||||
|| type.equals(Type.MULTIPLICATION_OPERATOR)
|
||||
|| type.equals(Type.DIVISION_OPERATOR)
|
||||
|| type.equals(Type.GREATER_THAN_OPERATOR)
|
||||
|| type.equals(Type.LESS_THAN_OPERATOR)
|
||||
|| type.equals(Type.LESS_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(Type.GREATER_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(Type.MODULO_OPERATOR);
|
||||
return type.equals(TokenType.SUBTRACTION_OPERATOR)
|
||||
|| type.equals(TokenType.MULTIPLICATION_OPERATOR)
|
||||
|| type.equals(TokenType.DIVISION_OPERATOR)
|
||||
|| type.equals(TokenType.GREATER_THAN_OPERATOR)
|
||||
|| type.equals(TokenType.LESS_THAN_OPERATOR)
|
||||
|| type.equals(TokenType.LESS_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(TokenType.GREATER_THAN_OR_EQUALS_OPERATOR)
|
||||
|| type.equals(TokenType.MODULO_OPERATOR);
|
||||
}
|
||||
|
||||
public boolean isStrictBooleanOperator() {
|
||||
return type.equals(Type.BOOLEAN_AND)
|
||||
|| type.equals(Type.BOOLEAN_OR);
|
||||
return type.equals(TokenType.BOOLEAN_AND)
|
||||
|| type.equals(TokenType.BOOLEAN_OR);
|
||||
}
|
||||
|
||||
public boolean isVariableDeclaration() {
|
||||
return type.equals(Type.TYPE_STRING)
|
||||
|| type.equals(Type.TYPE_BOOLEAN)
|
||||
|| type.equals(Type.TYPE_NUMBER);
|
||||
return type.equals(TokenType.TYPE_STRING)
|
||||
|| type.equals(TokenType.TYPE_BOOLEAN)
|
||||
|| type.equals(TokenType.TYPE_NUMBER);
|
||||
}
|
||||
|
||||
public boolean isControlStructure() {
|
||||
return type.equals(Type.IF_STATEMENT)
|
||||
|| type.equals(Type.WHILE_LOOP)
|
||||
|| type.equals(Type.FOR_LOOP);
|
||||
return type.equals(TokenType.IF_STATEMENT)
|
||||
|| type.equals(TokenType.WHILE_LOOP)
|
||||
|| type.equals(TokenType.FOR_LOOP);
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
public enum TokenType {
|
||||
/**
|
||||
* Function identifier or language keyword
|
||||
*/
|
||||
@@ -5,11 +5,11 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer.exceptions;
|
||||
package com.dfsek.terra.addons.terrascript.lexer.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class EOFException extends TokenizerException {
|
||||
@@ -5,11 +5,11 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer.exceptions;
|
||||
package com.dfsek.terra.addons.terrascript.lexer.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class FormatException extends TokenizerException {
|
||||
@@ -5,12 +5,12 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.tokenizer.exceptions;
|
||||
package com.dfsek.terra.addons.terrascript.lexer.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public abstract class TokenizerException extends ParseException {
|
||||
@@ -11,6 +11,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Lexer;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Token;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Token.TokenType;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Executable;
|
||||
@@ -54,9 +58,6 @@ import com.dfsek.terra.addons.terrascript.parser.lang.variables.assign.VariableA
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.variables.reference.BoolVariableReferenceNode;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.variables.reference.NumVariableReferenceNode;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.variables.reference.StrVariableReferenceNode;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Token;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Tokenizer;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
@@ -77,41 +78,42 @@ public class Parser {
|
||||
* @throws ParseException If parsing fails.
|
||||
*/
|
||||
public Executable parse(ScopeBuilder scopeBuilder) {
|
||||
return new Executable(parseBlock(new Tokenizer(source), scopeBuilder, ReturnType.VOID), scopeBuilder);
|
||||
return new Executable(parseBlock(new Lexer(source), scopeBuilder, ReturnType.VOID), scopeBuilder);
|
||||
}
|
||||
|
||||
private WhileKeyword parseWhileLoop(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = tokenizer.consume().getPosition();
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_BEGIN);
|
||||
private WhileKeyword parseWhileLoop(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = lexer.consume().getPosition();
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_BEGIN);
|
||||
scopeBuilder = scopeBuilder.innerLoopScope();
|
||||
Expression<?> condition = parseExpression(tokenizer, true, scopeBuilder);
|
||||
Expression<?> condition = parseExpression(lexer, true, scopeBuilder);
|
||||
ParserUtil.ensureReturnType(condition, Expression.ReturnType.BOOLEAN);
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_END);
|
||||
return new WhileKeyword(parseStatementBlock(tokenizer, scopeBuilder, ReturnType.VOID), (Expression<Boolean>) condition, start); // While loop
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_END);
|
||||
return new WhileKeyword(parseStatementBlock(lexer, scopeBuilder, ReturnType.VOID), (Expression<Boolean>) condition,
|
||||
start); // While loop
|
||||
}
|
||||
|
||||
private IfKeyword parseIfStatement(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = tokenizer.consume().getPosition();
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_BEGIN);
|
||||
Expression<?> condition = parseExpression(tokenizer, true, scopeBuilder);
|
||||
private IfKeyword parseIfStatement(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = lexer.consume().getPosition();
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_BEGIN);
|
||||
Expression<?> condition = parseExpression(lexer, true, scopeBuilder);
|
||||
ParserUtil.ensureReturnType(condition, Expression.ReturnType.BOOLEAN);
|
||||
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_END);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_END);
|
||||
|
||||
Block elseBlock = null;
|
||||
Block statement = parseStatementBlock(tokenizer, scopeBuilder, ReturnType.VOID);
|
||||
Block statement = parseStatementBlock(lexer, scopeBuilder, ReturnType.VOID);
|
||||
|
||||
List<Pair<Expression<Boolean>, Block>> elseIf = new ArrayList<>();
|
||||
|
||||
while(tokenizer.hasNext() && tokenizer.current().isType(Token.Type.ELSE)) {
|
||||
tokenizer.consume(); // Consume else.
|
||||
if(tokenizer.current().isType(Token.Type.IF_STATEMENT)) {
|
||||
tokenizer.consume(); // Consume if.
|
||||
Expression<?> elseCondition = parseExpression(tokenizer, true, scopeBuilder);
|
||||
while(lexer.hasNext() && lexer.current().isType(TokenType.ELSE)) {
|
||||
lexer.consume(); // Consume else.
|
||||
if(lexer.current().isType(TokenType.IF_STATEMENT)) {
|
||||
lexer.consume(); // Consume if.
|
||||
Expression<?> elseCondition = parseExpression(lexer, true, scopeBuilder);
|
||||
ParserUtil.ensureReturnType(elseCondition, Expression.ReturnType.BOOLEAN);
|
||||
elseIf.add(Pair.of((Expression<Boolean>) elseCondition, parseStatementBlock(tokenizer, scopeBuilder, ReturnType.VOID)));
|
||||
elseIf.add(Pair.of((Expression<Boolean>) elseCondition, parseStatementBlock(lexer, scopeBuilder, ReturnType.VOID)));
|
||||
} else {
|
||||
elseBlock = parseStatementBlock(tokenizer, scopeBuilder, ReturnType.VOID);
|
||||
elseBlock = parseStatementBlock(lexer, scopeBuilder, ReturnType.VOID);
|
||||
break; // Else must be last.
|
||||
}
|
||||
}
|
||||
@@ -119,74 +121,75 @@ public class Parser {
|
||||
return new IfKeyword(statement, (Expression<Boolean>) condition, elseIf, elseBlock, start); // If statement
|
||||
}
|
||||
|
||||
private Block parseStatementBlock(Tokenizer tokenizer, ScopeBuilder scopeBuilder, ReturnType blockReturnType) {
|
||||
if(tokenizer.current().isType(Token.Type.BLOCK_BEGIN)) {
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.BLOCK_BEGIN);
|
||||
Block block = parseBlock(tokenizer, scopeBuilder, blockReturnType);
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.BLOCK_END);
|
||||
private Block parseStatementBlock(Lexer lexer, ScopeBuilder scopeBuilder, ReturnType blockReturnType) {
|
||||
if(lexer.current().isType(TokenType.BLOCK_BEGIN)) {
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.BLOCK_BEGIN);
|
||||
Block block = parseBlock(lexer, scopeBuilder, blockReturnType);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.BLOCK_END);
|
||||
return block;
|
||||
} else {
|
||||
SourcePosition position = tokenizer.current().getPosition();
|
||||
return new Block(Collections.singletonList(parseStatement(tokenizer, scopeBuilder)), position, blockReturnType);
|
||||
SourcePosition position = lexer.current().getPosition();
|
||||
return new Block(Collections.singletonList(parseStatement(lexer, scopeBuilder)), position, blockReturnType);
|
||||
}
|
||||
}
|
||||
|
||||
private ForKeyword parseForLoop(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = tokenizer.consume().getPosition();
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_BEGIN);
|
||||
private ForKeyword parseForLoop(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = lexer.consume().getPosition();
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_BEGIN);
|
||||
scopeBuilder = scopeBuilder.innerLoopScope(); // new scope
|
||||
Token f = tokenizer.current();
|
||||
ParserUtil.ensureType(f, Token.Type.TYPE_NUMBER, Token.Type.TYPE_STRING, Token.Type.TYPE_BOOLEAN, Token.Type.IDENTIFIER);
|
||||
Token f = lexer.current();
|
||||
ParserUtil.ensureType(f, TokenType.TYPE_NUMBER, TokenType.TYPE_STRING, TokenType.TYPE_BOOLEAN, TokenType.IDENTIFIER);
|
||||
Expression<?> initializer;
|
||||
if(f.isVariableDeclaration()) {
|
||||
Expression<?> forVar = parseDeclaration(tokenizer, scopeBuilder);
|
||||
Token name = tokenizer.current();
|
||||
Expression<?> forVar = parseDeclaration(lexer, scopeBuilder);
|
||||
Token name = lexer.current();
|
||||
if(scopeBuilder.containsFunction(name.getContent()) || scopeBuilder.contains(name.getContent()))
|
||||
throw new ParseException(name.getContent() + " is already defined in this scope", name.getPosition());
|
||||
initializer = forVar;
|
||||
} else initializer = parseExpression(tokenizer, true, scopeBuilder);
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.STATEMENT_END);
|
||||
Expression<?> conditional = parseExpression(tokenizer, true, scopeBuilder);
|
||||
} else initializer = parseExpression(lexer, true, scopeBuilder);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.STATEMENT_END);
|
||||
Expression<?> conditional = parseExpression(lexer, true, scopeBuilder);
|
||||
ParserUtil.ensureReturnType(conditional, Expression.ReturnType.BOOLEAN);
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.STATEMENT_END);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.STATEMENT_END);
|
||||
|
||||
Expression<?> incrementer;
|
||||
Token token = tokenizer.current();
|
||||
Token token = lexer.current();
|
||||
if(scopeBuilder.contains(token.getContent())) { // Assume variable assignment
|
||||
incrementer = parseAssignment(tokenizer, scopeBuilder);
|
||||
} else incrementer = parseFunctionInvocation(tokenizer, true, scopeBuilder);
|
||||
incrementer = parseAssignment(lexer, scopeBuilder);
|
||||
} else incrementer = parseFunctionInvocation(lexer, true, scopeBuilder);
|
||||
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_END);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_END);
|
||||
|
||||
return new ForKeyword(parseStatementBlock(tokenizer, scopeBuilder, ReturnType.VOID), initializer, (Expression<Boolean>) conditional, incrementer,
|
||||
return new ForKeyword(parseStatementBlock(lexer, scopeBuilder, ReturnType.VOID), initializer, (Expression<Boolean>) conditional,
|
||||
incrementer,
|
||||
start);
|
||||
}
|
||||
|
||||
private Expression<?> parseExpression(Tokenizer tokenizer, boolean full, ScopeBuilder scopeBuilder) {
|
||||
private Expression<?> parseExpression(Lexer lexer, boolean full, ScopeBuilder scopeBuilder) {
|
||||
boolean booleanInverted = false; // Check for boolean not operator
|
||||
boolean negate = false;
|
||||
if(tokenizer.current().isType(Token.Type.BOOLEAN_NOT)) {
|
||||
if(lexer.current().isType(TokenType.BOOLEAN_NOT)) {
|
||||
booleanInverted = true;
|
||||
tokenizer.consume();
|
||||
} else if(tokenizer.current().isType(Token.Type.SUBTRACTION_OPERATOR)) {
|
||||
lexer.consume();
|
||||
} else if(lexer.current().isType(TokenType.SUBTRACTION_OPERATOR)) {
|
||||
negate = true;
|
||||
tokenizer.consume();
|
||||
lexer.consume();
|
||||
}
|
||||
|
||||
Token id = tokenizer.current();
|
||||
Token id = lexer.current();
|
||||
|
||||
ParserUtil.ensureType(id, Token.Type.IDENTIFIER, Token.Type.BOOLEAN, Token.Type.STRING, Token.Type.NUMBER, Token.Type.GROUP_BEGIN);
|
||||
ParserUtil.ensureType(id, TokenType.IDENTIFIER, TokenType.BOOLEAN, TokenType.STRING, TokenType.NUMBER, TokenType.GROUP_BEGIN);
|
||||
|
||||
Expression<?> expression;
|
||||
if(id.isConstant()) {
|
||||
expression = parseConstantExpression(tokenizer);
|
||||
} else if(id.isType(Token.Type.GROUP_BEGIN)) { // Parse grouped expression
|
||||
expression = parseExpressionGroup(tokenizer, scopeBuilder);
|
||||
expression = parseConstantExpression(lexer);
|
||||
} else if(id.isType(TokenType.GROUP_BEGIN)) { // Parse grouped expression
|
||||
expression = parseExpressionGroup(lexer, scopeBuilder);
|
||||
} else {
|
||||
if(scopeBuilder.containsFunction(id.getContent()))
|
||||
expression = parseFunctionInvocation(tokenizer, false, scopeBuilder);
|
||||
expression = parseFunctionInvocation(lexer, false, scopeBuilder);
|
||||
else if(scopeBuilder.contains(id.getContent())) {
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.IDENTIFIER);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.IDENTIFIER);
|
||||
String varId = id.getContent();
|
||||
ReturnType varType = scopeBuilder.getType(varId);
|
||||
expression = switch(varType) {
|
||||
@@ -207,14 +210,14 @@ public class Parser {
|
||||
expression = new NegationOperation((Expression<Number>) expression, expression.getPosition());
|
||||
}
|
||||
|
||||
if(full && tokenizer.current().isBinaryOperator()) { // Parse binary operations
|
||||
return parseBinaryOperation(expression, tokenizer, scopeBuilder);
|
||||
if(full && lexer.current().isBinaryOperator()) { // Parse binary operations
|
||||
return parseBinaryOperation(expression, lexer, scopeBuilder);
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
private ConstantExpression<?> parseConstantExpression(Tokenizer tokenizer) {
|
||||
Token constantToken = tokenizer.consume();
|
||||
private ConstantExpression<?> parseConstantExpression(Lexer lexer) {
|
||||
Token constantToken = lexer.consume();
|
||||
SourcePosition position = constantToken.getPosition();
|
||||
return switch(constantToken.getType()) {
|
||||
case NUMBER -> {
|
||||
@@ -223,31 +226,32 @@ public class Parser {
|
||||
}
|
||||
case STRING -> new StringConstant(constantToken.getContent(), position);
|
||||
case BOOLEAN -> new BooleanConstant(Boolean.parseBoolean(constantToken.getContent()), position);
|
||||
default -> throw new UnsupportedOperationException("Unsupported constant token: " + constantToken.getType() + " at position: " + position);
|
||||
default -> throw new UnsupportedOperationException(
|
||||
"Unsupported constant token: " + constantToken.getType() + " at position: " + position);
|
||||
};
|
||||
}
|
||||
|
||||
private Expression<?> parseExpressionGroup(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_BEGIN);
|
||||
Expression<?> expression = parseExpression(tokenizer, true, scopeBuilder); // Parse inside of group as a separate expression
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_END);
|
||||
private Expression<?> parseExpressionGroup(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_BEGIN);
|
||||
Expression<?> expression = parseExpression(lexer, true, scopeBuilder); // Parse inside of group as a separate expression
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_END);
|
||||
return expression;
|
||||
}
|
||||
|
||||
private BinaryOperation<?, ?> parseBinaryOperation(Expression<?> left, Tokenizer tokenizer,
|
||||
private BinaryOperation<?, ?> parseBinaryOperation(Expression<?> left, Lexer lexer,
|
||||
ScopeBuilder scopeBuilder) {
|
||||
Token binaryOperator = tokenizer.consume();
|
||||
Token binaryOperator = lexer.consume();
|
||||
ParserUtil.checkBinaryOperator(binaryOperator);
|
||||
|
||||
Expression<?> right = parseExpression(tokenizer, false, scopeBuilder);
|
||||
Expression<?> right = parseExpression(lexer, false, scopeBuilder);
|
||||
|
||||
Token other = tokenizer.current();
|
||||
Token other = lexer.current();
|
||||
|
||||
if(ParserUtil.hasPrecedence(binaryOperator.getType(), other.getType()))
|
||||
return assemble(left, parseBinaryOperation(right, tokenizer, scopeBuilder), binaryOperator);
|
||||
|
||||
return assemble(left, parseBinaryOperation(right, lexer, scopeBuilder), binaryOperator);
|
||||
|
||||
if(other.isBinaryOperator())
|
||||
return parseBinaryOperation(assemble(left, right, binaryOperator), tokenizer, scopeBuilder);
|
||||
return parseBinaryOperation(assemble(left, right, binaryOperator), lexer, scopeBuilder);
|
||||
|
||||
return assemble(left, right, binaryOperator);
|
||||
}
|
||||
@@ -292,43 +296,46 @@ public class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private Expression<?> parseDeclaration(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
Token type = tokenizer.consume();
|
||||
private Expression<?> parseDeclaration(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
Token type = lexer.consume();
|
||||
|
||||
Token identifier = tokenizer.consume();
|
||||
ParserUtil.ensureType(identifier, Token.Type.IDENTIFIER);
|
||||
Token identifier = lexer.consume();
|
||||
ParserUtil.ensureType(identifier, TokenType.IDENTIFIER);
|
||||
|
||||
Token declarationType = tokenizer.consume();
|
||||
ParserUtil.ensureType(declarationType, Token.Type.ASSIGNMENT, Token.Type.GROUP_BEGIN);
|
||||
Token declarationType = lexer.consume();
|
||||
ParserUtil.ensureType(declarationType, TokenType.ASSIGNMENT, TokenType.GROUP_BEGIN);
|
||||
|
||||
return switch(declarationType.getType()) {
|
||||
case ASSIGNMENT -> parseVariableDeclaration(tokenizer, scopeBuilder, type, identifier);
|
||||
case GROUP_BEGIN -> parseFunctionDeclaration(tokenizer, scopeBuilder, type, identifier);
|
||||
case ASSIGNMENT -> parseVariableDeclaration(lexer, scopeBuilder, type, identifier);
|
||||
case GROUP_BEGIN -> parseFunctionDeclaration(lexer, scopeBuilder, type, identifier);
|
||||
default -> throw new ParseException("Illegal type for declaration: " + type, declarationType.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private Expression<?> parseVariableDeclaration(Tokenizer tokenizer, ScopeBuilder scopeBuilder, Token type, Token identifier) {
|
||||
ParserUtil.ensureType(type, Token.Type.TYPE_STRING, Token.Type.TYPE_BOOLEAN, Token.Type.TYPE_NUMBER);
|
||||
private Expression<?> parseVariableDeclaration(Lexer lexer, ScopeBuilder scopeBuilder, Token type, Token identifier) {
|
||||
ParserUtil.ensureType(type, TokenType.TYPE_STRING, TokenType.TYPE_BOOLEAN, TokenType.TYPE_NUMBER);
|
||||
|
||||
if(scopeBuilder.contains(identifier.getContent()))
|
||||
throw new ParseException(identifier.getContent() + " is already defined in this scope", identifier.getPosition());
|
||||
|
||||
Expression<?> value = parseExpression(tokenizer, true, scopeBuilder);
|
||||
Expression<?> value = parseExpression(lexer, true, scopeBuilder);
|
||||
ParserUtil.ensureReturnType(value, ParserUtil.getVariableReturnType(type));
|
||||
|
||||
String variableName = identifier.getContent();
|
||||
return switch(value.returnType()) {
|
||||
case NUMBER -> new NumAssignmentNode((Expression<Number>) value, identifier.getPosition(), scopeBuilder.declareNum(variableName));
|
||||
case STRING -> new StrAssignmentNode((Expression<String>) value, identifier.getPosition(), scopeBuilder.declareStr(variableName));
|
||||
case BOOLEAN -> new BoolAssignmentNode((Expression<Boolean>) value, identifier.getPosition(), scopeBuilder.declareBool(variableName));
|
||||
case NUMBER -> new NumAssignmentNode((Expression<Number>) value, identifier.getPosition(),
|
||||
scopeBuilder.declareNum(variableName));
|
||||
case STRING -> new StrAssignmentNode((Expression<String>) value, identifier.getPosition(),
|
||||
scopeBuilder.declareStr(variableName));
|
||||
case BOOLEAN -> new BoolAssignmentNode((Expression<Boolean>) value, identifier.getPosition(),
|
||||
scopeBuilder.declareBool(variableName));
|
||||
default -> throw new ParseException("Illegal type for variable declaration: " + type, value.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
private Expression<?> parseFunctionDeclaration(Tokenizer tokenizer, ScopeBuilder scopeBuilder, Token type, Token identifier) {
|
||||
ParserUtil.ensureType(type, Token.Type.TYPE_STRING, Token.Type.TYPE_BOOLEAN, Token.Type.TYPE_NUMBER, Token.Type.TYPE_VOID);
|
||||
private Expression<?> parseFunctionDeclaration(Lexer lexer, ScopeBuilder scopeBuilder, Token type, Token identifier) {
|
||||
ParserUtil.ensureType(type, TokenType.TYPE_STRING, TokenType.TYPE_BOOLEAN, TokenType.TYPE_NUMBER, TokenType.TYPE_VOID);
|
||||
|
||||
if(scopeBuilder.contains(identifier.getContent()))
|
||||
throw new ParseException(identifier.getContent() + " is already defined in this scope", identifier.getPosition());
|
||||
@@ -338,14 +345,15 @@ public class Parser {
|
||||
ScopeBuilder functionBodyScope = scopeBuilder.functionScope();
|
||||
|
||||
// Declare argument names into function body scope
|
||||
List<Pair<Integer, ReturnType>> argumentInfo = getFunctionArgumentsDeclaration(tokenizer).stream().map(arg -> Pair.of(switch(arg.getRight()) {
|
||||
case NUMBER -> functionBodyScope.declareNum(arg.getLeft());
|
||||
case BOOLEAN -> functionBodyScope.declareBool(arg.getLeft());
|
||||
case STRING -> functionBodyScope.declareStr(arg.getLeft());
|
||||
default -> throw new IllegalArgumentException("Unsupported argument type: " + arg.getRight());
|
||||
}, arg.getRight())).toList();
|
||||
List<Pair<Integer, ReturnType>> argumentInfo = getFunctionArgumentsDeclaration(lexer).stream().map(
|
||||
arg -> Pair.of(switch(arg.getRight()) {
|
||||
case NUMBER -> functionBodyScope.declareNum(arg.getLeft());
|
||||
case BOOLEAN -> functionBodyScope.declareBool(arg.getLeft());
|
||||
case STRING -> functionBodyScope.declareStr(arg.getLeft());
|
||||
default -> throw new IllegalArgumentException("Unsupported argument type: " + arg.getRight());
|
||||
}, arg.getRight())).toList();
|
||||
|
||||
Block body = parseStatementBlock(tokenizer, functionBodyScope, returnType);
|
||||
Block body = parseStatementBlock(lexer, functionBodyScope, returnType);
|
||||
|
||||
FunctionBuilder<?> functionBuilder = new UserDefinedFunctionBuilder<>(returnType, argumentInfo, body, functionBodyScope);
|
||||
|
||||
@@ -353,104 +361,109 @@ public class Parser {
|
||||
return Expression.NOOP;
|
||||
}
|
||||
|
||||
private List<Pair<String, ReturnType>> getFunctionArgumentsDeclaration(Tokenizer tokenizer) {
|
||||
private List<Pair<String, ReturnType>> getFunctionArgumentsDeclaration(Lexer lexer) {
|
||||
List<Pair<String, ReturnType>> arguments = new ArrayList<>();
|
||||
while (tokenizer.current().getType() != Token.Type.GROUP_END) {
|
||||
while(lexer.current().getType() != TokenType.GROUP_END) {
|
||||
// Parse argument type
|
||||
Token typeToken = tokenizer.consume();
|
||||
ParserUtil.ensureType(typeToken, Token.Type.TYPE_BOOLEAN, Token.Type.TYPE_STRING, Token.Type.TYPE_NUMBER);
|
||||
Token typeToken = lexer.consume();
|
||||
ParserUtil.ensureType(typeToken, TokenType.TYPE_BOOLEAN, TokenType.TYPE_STRING, TokenType.TYPE_NUMBER);
|
||||
ReturnType argType = ParserUtil.getVariableReturnType(typeToken);
|
||||
|
||||
// Parse argument name
|
||||
Token identifierToken = tokenizer.consume();
|
||||
ParserUtil.ensureType(identifierToken, Token.Type.IDENTIFIER);
|
||||
Token identifierToken = lexer.consume();
|
||||
ParserUtil.ensureType(identifierToken, TokenType.IDENTIFIER);
|
||||
String argName = identifierToken.getContent();
|
||||
|
||||
arguments.add(Pair.of(argName, argType));
|
||||
|
||||
// Consume separator if present, trailing separators are allowed
|
||||
if (tokenizer.current().isType(Token.Type.SEPARATOR)) tokenizer.consume();
|
||||
if(lexer.current().isType(TokenType.SEPARATOR)) lexer.consume();
|
||||
}
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_END);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_END);
|
||||
return arguments;
|
||||
}
|
||||
|
||||
private Block parseBlock(Tokenizer tokenizer, ScopeBuilder scopeBuilder, ReturnType blockReturnType) {
|
||||
private Block parseBlock(Lexer lexer, ScopeBuilder scopeBuilder, ReturnType blockReturnType) {
|
||||
List<Expression<?>> expressions = new ArrayList<>();
|
||||
scopeBuilder = scopeBuilder.innerScope();
|
||||
SourcePosition startPosition = tokenizer.current().getPosition();
|
||||
SourcePosition startPosition = lexer.current().getPosition();
|
||||
|
||||
boolean hasReturn = false;
|
||||
|
||||
// Parse each statement
|
||||
while(tokenizer.hasNext()) {
|
||||
Token token = tokenizer.current();
|
||||
if(token.isType(Token.Type.BLOCK_END)) break; // Stop parsing at block end.
|
||||
Expression<?> expression = parseStatement(tokenizer, scopeBuilder);
|
||||
while(lexer.hasNext()) {
|
||||
Token token = lexer.current();
|
||||
if(token.isType(TokenType.BLOCK_END)) break; // Stop parsing at block end.
|
||||
Expression<?> expression = parseStatement(lexer, scopeBuilder);
|
||||
if(expression != Expression.NOOP) {
|
||||
expressions.add(expression);
|
||||
}
|
||||
if(expression instanceof ReturnKeyword returnKeyword) {
|
||||
hasReturn = true;
|
||||
if (returnKeyword.dataReturnType() != blockReturnType)
|
||||
throw new ParseException("Invalid return type, expected " + blockReturnType + ", found " + returnKeyword.dataReturnType(), expression.getPosition());
|
||||
if(returnKeyword.dataReturnType() != blockReturnType)
|
||||
throw new ParseException(
|
||||
"Invalid return type, expected " + blockReturnType + ", found " + returnKeyword.dataReturnType(),
|
||||
expression.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
if (blockReturnType != ReturnType.VOID && !hasReturn)
|
||||
if(blockReturnType != ReturnType.VOID && !hasReturn)
|
||||
throw new ParseException("Block does not contain a return statement, must return type " + blockReturnType, startPosition);
|
||||
|
||||
return new Block(expressions, startPosition, blockReturnType);
|
||||
}
|
||||
|
||||
private Expression<?> parseStatement(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
Token token = tokenizer.current();
|
||||
private Expression<?> parseStatement(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
Token token = lexer.current();
|
||||
|
||||
// Include BREAK and CONTINUE as valid token types if scope is within a loop
|
||||
if(scopeBuilder.isInLoop()) ParserUtil.ensureType(token, Token.Type.IDENTIFIER, Token.Type.IF_STATEMENT, Token.Type.WHILE_LOOP, Token.Type.FOR_LOOP,
|
||||
Token.Type.TYPE_NUMBER, Token.Type.TYPE_STRING, Token.Type.TYPE_BOOLEAN, Token.Type.TYPE_VOID,
|
||||
Token.Type.RETURN, Token.Type.BREAK, Token.Type.CONTINUE, Token.Type.FAIL);
|
||||
else ParserUtil.ensureType(token, Token.Type.IDENTIFIER, Token.Type.IF_STATEMENT, Token.Type.WHILE_LOOP, Token.Type.FOR_LOOP,
|
||||
Token.Type.TYPE_NUMBER, Token.Type.TYPE_STRING, Token.Type.TYPE_BOOLEAN, Token.Type.TYPE_VOID, Token.Type.RETURN,
|
||||
Token.Type.FAIL);
|
||||
if(scopeBuilder.isInLoop()) ParserUtil.ensureType(token, TokenType.IDENTIFIER, TokenType.IF_STATEMENT, TokenType.WHILE_LOOP,
|
||||
TokenType.FOR_LOOP,
|
||||
TokenType.TYPE_NUMBER, TokenType.TYPE_STRING, TokenType.TYPE_BOOLEAN,
|
||||
TokenType.TYPE_VOID,
|
||||
TokenType.RETURN, TokenType.BREAK, TokenType.CONTINUE, TokenType.FAIL);
|
||||
else ParserUtil.ensureType(token, TokenType.IDENTIFIER, TokenType.IF_STATEMENT, TokenType.WHILE_LOOP, TokenType.FOR_LOOP,
|
||||
TokenType.TYPE_NUMBER, TokenType.TYPE_STRING, TokenType.TYPE_BOOLEAN, TokenType.TYPE_VOID,
|
||||
TokenType.RETURN,
|
||||
TokenType.FAIL);
|
||||
|
||||
Expression<?> expression = switch(token.getType()) {
|
||||
case FOR_LOOP -> parseForLoop(tokenizer, scopeBuilder);
|
||||
case IF_STATEMENT -> parseIfStatement(tokenizer, scopeBuilder);
|
||||
case WHILE_LOOP -> parseWhileLoop(tokenizer, scopeBuilder);
|
||||
case FOR_LOOP -> parseForLoop(lexer, scopeBuilder);
|
||||
case IF_STATEMENT -> parseIfStatement(lexer, scopeBuilder);
|
||||
case WHILE_LOOP -> parseWhileLoop(lexer, scopeBuilder);
|
||||
case IDENTIFIER -> {
|
||||
if(scopeBuilder.contains(token.getContent())) yield parseAssignment(tokenizer, scopeBuilder); // Assume variable assignment
|
||||
else yield parseFunctionInvocation(tokenizer, true, scopeBuilder);
|
||||
if(scopeBuilder.contains(token.getContent())) yield parseAssignment(lexer, scopeBuilder); // Assume variable assignment
|
||||
else yield parseFunctionInvocation(lexer, true, scopeBuilder);
|
||||
}
|
||||
case TYPE_NUMBER, TYPE_STRING, TYPE_BOOLEAN, TYPE_VOID -> parseDeclaration(tokenizer, scopeBuilder);
|
||||
case RETURN -> parseReturn(tokenizer, scopeBuilder);
|
||||
case BREAK -> new BreakKeyword(tokenizer.consume().getPosition());
|
||||
case CONTINUE -> new ContinueKeyword(tokenizer.consume().getPosition());
|
||||
case FAIL -> new FailKeyword(tokenizer.consume().getPosition());
|
||||
case TYPE_NUMBER, TYPE_STRING, TYPE_BOOLEAN, TYPE_VOID -> parseDeclaration(lexer, scopeBuilder);
|
||||
case RETURN -> parseReturn(lexer, scopeBuilder);
|
||||
case BREAK -> new BreakKeyword(lexer.consume().getPosition());
|
||||
case CONTINUE -> new ContinueKeyword(lexer.consume().getPosition());
|
||||
case FAIL -> new FailKeyword(lexer.consume().getPosition());
|
||||
default -> throw new UnsupportedOperationException("Unexpected token " + token.getType() + ": " + token.getPosition());
|
||||
};
|
||||
if(!token.isControlStructure() && expression != Expression.NOOP) ParserUtil.ensureType(tokenizer.consume(), Token.Type.STATEMENT_END);
|
||||
if(!token.isControlStructure() && expression != Expression.NOOP) ParserUtil.ensureType(lexer.consume(), TokenType.STATEMENT_END);
|
||||
return expression;
|
||||
}
|
||||
|
||||
private ReturnKeyword parseReturn(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
Token returnToken = tokenizer.consume();
|
||||
ParserUtil.ensureType(returnToken, Token.Type.RETURN);
|
||||
private ReturnKeyword parseReturn(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
Token returnToken = lexer.consume();
|
||||
ParserUtil.ensureType(returnToken, TokenType.RETURN);
|
||||
Expression<?> data = null;
|
||||
if (!tokenizer.current().isType(Token.Type.STATEMENT_END)) {
|
||||
data = parseExpression(tokenizer, true, scopeBuilder);
|
||||
if(!lexer.current().isType(TokenType.STATEMENT_END)) {
|
||||
data = parseExpression(lexer, true, scopeBuilder);
|
||||
}
|
||||
return new ReturnKeyword(data, returnToken.getPosition());
|
||||
}
|
||||
|
||||
private VariableAssignmentNode<?> parseAssignment(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
Token identifier = tokenizer.consume();
|
||||
private VariableAssignmentNode<?> parseAssignment(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
Token identifier = lexer.consume();
|
||||
|
||||
ParserUtil.ensureType(identifier, Token.Type.IDENTIFIER);
|
||||
ParserUtil.ensureType(identifier, TokenType.IDENTIFIER);
|
||||
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.ASSIGNMENT);
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.ASSIGNMENT);
|
||||
|
||||
Expression<?> value = parseExpression(tokenizer, true, scopeBuilder);
|
||||
Expression<?> value = parseExpression(lexer, true, scopeBuilder);
|
||||
|
||||
String id = identifier.getContent();
|
||||
|
||||
@@ -466,20 +479,20 @@ public class Parser {
|
||||
};
|
||||
}
|
||||
|
||||
private Expression<?> parseFunctionInvocation(Tokenizer tokenizer, boolean fullStatement, ScopeBuilder scopeBuilder) {
|
||||
Token identifier = tokenizer.consume();
|
||||
ParserUtil.ensureType(identifier, Token.Type.IDENTIFIER); // First token must be identifier
|
||||
private Expression<?> parseFunctionInvocation(Lexer lexer, boolean fullStatement, ScopeBuilder scopeBuilder) {
|
||||
Token identifier = lexer.consume();
|
||||
ParserUtil.ensureType(identifier, TokenType.IDENTIFIER); // First token must be identifier
|
||||
|
||||
if(!scopeBuilder.containsFunction(identifier.getContent()))
|
||||
throw new ParseException("Function \"" + identifier.getContent() + "\" is not defined in this scope", identifier.getPosition());
|
||||
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_BEGIN); // Second is body begin
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_BEGIN); // Second is body begin
|
||||
|
||||
List<Expression<?>> args = getFunctionArgs(tokenizer, scopeBuilder); // Extract arguments, consume the rest.
|
||||
List<Expression<?>> args = getFunctionArgs(lexer, scopeBuilder); // Extract arguments, consume the rest.
|
||||
|
||||
ParserUtil.ensureType(tokenizer.consume(), Token.Type.GROUP_END); // Remove body end
|
||||
ParserUtil.ensureType(lexer.consume(), TokenType.GROUP_END); // Remove body end
|
||||
|
||||
if(fullStatement) ParserUtil.ensureType(tokenizer.current(), Token.Type.STATEMENT_END);
|
||||
if(fullStatement) ParserUtil.ensureType(lexer.current(), TokenType.STATEMENT_END);
|
||||
|
||||
if(ignoredFunctions.contains(identifier.getContent())) {
|
||||
return Expression.NOOP;
|
||||
@@ -503,13 +516,13 @@ public class Parser {
|
||||
throw new UnsupportedOperationException("Unsupported function: " + identifier.getContent());
|
||||
}
|
||||
|
||||
private List<Expression<?>> getFunctionArgs(Tokenizer tokenizer, ScopeBuilder scopeBuilder) {
|
||||
private List<Expression<?>> getFunctionArgs(Lexer lexer, ScopeBuilder scopeBuilder) {
|
||||
List<Expression<?>> args = new ArrayList<>();
|
||||
|
||||
while(!tokenizer.current().isType(Token.Type.GROUP_END)) {
|
||||
args.add(parseExpression(tokenizer, true, scopeBuilder));
|
||||
ParserUtil.ensureType(tokenizer.current(), Token.Type.SEPARATOR, Token.Type.GROUP_END);
|
||||
if(tokenizer.current().isType(Token.Type.SEPARATOR)) tokenizer.consume();
|
||||
while(!lexer.current().isType(TokenType.GROUP_END)) {
|
||||
args.add(parseExpression(lexer, true, scopeBuilder));
|
||||
ParserUtil.ensureType(lexer.current(), TokenType.SEPARATOR, TokenType.GROUP_END);
|
||||
if(lexer.current().isType(TokenType.SEPARATOR)) lexer.consume();
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -12,47 +12,48 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Token;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Token.TokenType;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.Token;
|
||||
|
||||
|
||||
public class ParserUtil {
|
||||
|
||||
private static final Map<Token.Type, Map<Token.Type, Boolean>> PRECEDENCE = new HashMap<>(); // If second has precedence, true.
|
||||
private static final List<Token.Type> ARITHMETIC = Arrays.asList(Token.Type.ADDITION_OPERATOR, Token.Type.SUBTRACTION_OPERATOR,
|
||||
Token.Type.MULTIPLICATION_OPERATOR, Token.Type.DIVISION_OPERATOR,
|
||||
Token.Type.MODULO_OPERATOR);
|
||||
private static final List<Token.Type> COMPARISON = Arrays.asList(Token.Type.EQUALS_OPERATOR, Token.Type.NOT_EQUALS_OPERATOR,
|
||||
Token.Type.LESS_THAN_OPERATOR, Token.Type.LESS_THAN_OR_EQUALS_OPERATOR,
|
||||
Token.Type.GREATER_THAN_OPERATOR,
|
||||
Token.Type.GREATER_THAN_OR_EQUALS_OPERATOR);
|
||||
private static final Map<TokenType, Map<TokenType, Boolean>> PRECEDENCE = new HashMap<>(); // If second has precedence, true.
|
||||
private static final List<TokenType> ARITHMETIC = Arrays.asList(TokenType.ADDITION_OPERATOR, TokenType.SUBTRACTION_OPERATOR,
|
||||
TokenType.MULTIPLICATION_OPERATOR, TokenType.DIVISION_OPERATOR,
|
||||
TokenType.MODULO_OPERATOR);
|
||||
private static final List<TokenType> COMPARISON = Arrays.asList(TokenType.EQUALS_OPERATOR, TokenType.NOT_EQUALS_OPERATOR,
|
||||
TokenType.LESS_THAN_OPERATOR, TokenType.LESS_THAN_OR_EQUALS_OPERATOR,
|
||||
TokenType.GREATER_THAN_OPERATOR,
|
||||
TokenType.GREATER_THAN_OR_EQUALS_OPERATOR);
|
||||
|
||||
static { // Setup precedence
|
||||
Map<Token.Type, Boolean> add = new HashMap<>(); // Addition/subtraction before Multiplication/division.
|
||||
add.put(Token.Type.MULTIPLICATION_OPERATOR, true);
|
||||
add.put(Token.Type.DIVISION_OPERATOR, true);
|
||||
Map<TokenType, Boolean> add = new HashMap<>(); // Addition/subtraction before Multiplication/division.
|
||||
add.put(TokenType.MULTIPLICATION_OPERATOR, true);
|
||||
add.put(TokenType.DIVISION_OPERATOR, true);
|
||||
|
||||
PRECEDENCE.put(Token.Type.ADDITION_OPERATOR, add);
|
||||
PRECEDENCE.put(Token.Type.SUBTRACTION_OPERATOR, add);
|
||||
PRECEDENCE.put(TokenType.ADDITION_OPERATOR, add);
|
||||
PRECEDENCE.put(TokenType.SUBTRACTION_OPERATOR, add);
|
||||
|
||||
Map<Token.Type, Boolean> numericBoolean = new HashMap<>();
|
||||
Map<TokenType, Boolean> numericBoolean = new HashMap<>();
|
||||
|
||||
ARITHMETIC.forEach(op -> numericBoolean.put(op, true)); // Numbers before comparison
|
||||
COMPARISON.forEach(op -> PRECEDENCE.put(op, numericBoolean));
|
||||
|
||||
|
||||
Map<Token.Type, Boolean> booleanOps = new HashMap<>();
|
||||
Map<TokenType, Boolean> booleanOps = new HashMap<>();
|
||||
ARITHMETIC.forEach(op -> booleanOps.put(op, true)); // Everything before boolean
|
||||
COMPARISON.forEach(op -> booleanOps.put(op, true));
|
||||
|
||||
|
||||
PRECEDENCE.put(Token.Type.BOOLEAN_AND, booleanOps);
|
||||
PRECEDENCE.put(Token.Type.BOOLEAN_OR, booleanOps);
|
||||
PRECEDENCE.put(TokenType.BOOLEAN_AND, booleanOps);
|
||||
PRECEDENCE.put(TokenType.BOOLEAN_OR, booleanOps);
|
||||
}
|
||||
|
||||
public static void ensureType(Token token, Token.Type... expected) {
|
||||
for(Token.Type type : expected) if(token.getType().equals(type)) return;
|
||||
public static void ensureType(Token token, TokenType... expected) {
|
||||
for(TokenType type : expected) if(token.getType().equals(type)) return;
|
||||
throw new ParseException("Expected " + Arrays.toString(expected) + " but found " + token.getType(), token.getPosition());
|
||||
}
|
||||
|
||||
@@ -77,13 +78,6 @@ public class ParserUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkVarType(Token token, Expression.ReturnType returnType) {
|
||||
if(returnType.equals(Expression.ReturnType.STRING) && token.getType().equals(Token.Type.TYPE_STRING)) return;
|
||||
if(returnType.equals(Expression.ReturnType.NUMBER) && token.getType().equals(Token.Type.TYPE_NUMBER)) return;
|
||||
if(returnType.equals(Expression.ReturnType.BOOLEAN) && token.getType().equals(Token.Type.TYPE_BOOLEAN)) return;
|
||||
throw new ParseException("Type mismatch, cannot convert from " + returnType + " to " + token.getType(), token.getPosition());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if token is a binary operator
|
||||
*
|
||||
@@ -107,9 +101,9 @@ public class ParserUtil {
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean hasPrecedence(Token.Type first, Token.Type second) {
|
||||
public static boolean hasPrecedence(TokenType first, TokenType second) {
|
||||
if(!PRECEDENCE.containsKey(first)) return false;
|
||||
Map<Token.Type, Boolean> pre = PRECEDENCE.get(first);
|
||||
Map<TokenType, Boolean> pre = PRECEDENCE.get(first);
|
||||
if(!pre.containsKey(second)) return false;
|
||||
return pre.get(second);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ package com.dfsek.terra.addons.terrascript.parser.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class ParseException extends RuntimeException {
|
||||
|
||||
@@ -9,9 +9,8 @@ package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class Block implements Expression<EvaluationInfo<?>> {
|
||||
|
||||
@@ -7,12 +7,12 @@ import com.dfsek.terra.addons.terrascript.parser.lang.Scope.ScopeBuilder;
|
||||
public class Executable {
|
||||
private final Block script;
|
||||
private final ThreadLocal<Scope> scope;
|
||||
|
||||
|
||||
public Executable(Block script, ScopeBuilder scopeBuilder) {
|
||||
this.script = script;
|
||||
this.scope = ThreadLocal.withInitial(scopeBuilder::build);
|
||||
}
|
||||
|
||||
|
||||
public boolean execute(ImplementationArguments arguments) {
|
||||
return script.evaluate(arguments, scope.get()).level() != Block.EvaluationLevel.FAIL;
|
||||
}
|
||||
|
||||
@@ -7,24 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public interface Expression<T> {
|
||||
ReturnType returnType();
|
||||
|
||||
T evaluate(ImplementationArguments implementationArguments, Scope scope);
|
||||
|
||||
default double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
throw new UnsupportedOperationException("Cannot apply " + this + " as double");
|
||||
}
|
||||
|
||||
default boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
throw new UnsupportedOperationException("Cannot apply " + this + " as double");
|
||||
}
|
||||
|
||||
SourcePosition getPosition();
|
||||
|
||||
Expression<Void> NOOP = new Expression<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
@@ -42,6 +28,21 @@ public interface Expression<T> {
|
||||
}
|
||||
};
|
||||
|
||||
ReturnType returnType();
|
||||
|
||||
T evaluate(ImplementationArguments implementationArguments, Scope scope);
|
||||
|
||||
default double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
throw new UnsupportedOperationException("Cannot apply " + this + " as double");
|
||||
}
|
||||
|
||||
default boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
throw new UnsupportedOperationException("Cannot apply " + this + " as double");
|
||||
}
|
||||
|
||||
SourcePosition getPosition();
|
||||
|
||||
|
||||
enum ReturnType {
|
||||
NUMBER(true),
|
||||
STRING(true),
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression.ReturnType;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
@@ -87,7 +86,7 @@ public class Scope {
|
||||
|
||||
public ScopeBuilder innerLoopScope() { return new ScopeBuilder(this, true); }
|
||||
|
||||
public ScopeBuilder functionScope() { return new ScopeBuilder(functions); }
|
||||
public ScopeBuilder functionScope() { return new ScopeBuilder(functions); }
|
||||
|
||||
public ScopeBuilder registerFunction(String name, FunctionBuilder<? extends Function<?>> functionBuilder) {
|
||||
functions.put(name, functionBuilder);
|
||||
@@ -143,14 +142,14 @@ public class Scope {
|
||||
parent.updateBoolSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateNumSize(int size) {
|
||||
this.numSize = FastMath.max(numSize, size);
|
||||
if(parent != null) {
|
||||
parent.updateNumSize(size);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void updateStrSize(int size) {
|
||||
this.strSize = FastMath.max(strSize, size);
|
||||
if(parent != null) {
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BooleanConstant extends ConstantExpression<Boolean> {
|
||||
private final boolean constant;
|
||||
|
||||
|
||||
public BooleanConstant(Boolean constant, SourcePosition position) {
|
||||
super(constant, position);
|
||||
this.constant = constant;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public abstract class ConstantExpression<T> implements Expression<T> {
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class NumericConstant extends ConstantExpression<Number> {
|
||||
private final double constant;
|
||||
|
||||
|
||||
public NumericConstant(Number constant, SourcePosition position) {
|
||||
super(constant, position);
|
||||
this.constant = constant.doubleValue();
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class StringConstant extends ConstantExpression<String> {
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
|
||||
|
||||
public interface Function<T> extends Expression<T> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,8 +9,8 @@ package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public interface FunctionBuilder<T extends Function<?>> {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression.ReturnType;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope.ScopeBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class UserDefinedFunctionBuilder<T extends Function<?>> implements FunctionBuilder<T> {
|
||||
|
||||
@@ -19,7 +19,8 @@ public class UserDefinedFunctionBuilder<T extends Function<?>> implements Functi
|
||||
private final ScopeBuilder bodyScopeBuilder;
|
||||
private final Block body;
|
||||
|
||||
public UserDefinedFunctionBuilder(ReturnType returnType, List<Pair<Integer, ReturnType>> argumentInfo, Block body, ScopeBuilder functionBodyScope) {
|
||||
public UserDefinedFunctionBuilder(ReturnType returnType, List<Pair<Integer, ReturnType>> argumentInfo, Block body,
|
||||
ScopeBuilder functionBodyScope) {
|
||||
this.returnType = returnType;
|
||||
this.bodyScopeBuilder = functionBodyScope;
|
||||
this.body = body;
|
||||
@@ -30,7 +31,7 @@ public class UserDefinedFunctionBuilder<T extends Function<?>> implements Functi
|
||||
public T build(List<Expression<?>> argumentList, SourcePosition position) {
|
||||
//noinspection unchecked
|
||||
return (T) new Function() {
|
||||
|
||||
|
||||
private final ThreadLocal<Scope> threadLocalScope = ThreadLocal.withInitial(bodyScopeBuilder::build);
|
||||
|
||||
@Override
|
||||
@@ -42,7 +43,7 @@ public class UserDefinedFunctionBuilder<T extends Function<?>> implements Functi
|
||||
public Object evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
Scope bodyScope = threadLocalScope.get();
|
||||
// Pass arguments into scope of function body
|
||||
for (int i = 0; i < argumentList.size(); i++) {
|
||||
for(int i = 0; i < argumentList.size(); i++) {
|
||||
Pair<Integer, ReturnType> argInfo = argumentInfo.get(i);
|
||||
Expression<?> argExpression = argumentList.get(i);
|
||||
switch(argInfo.getRight()) {
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BreakKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class ContinueKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class FailKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
public class ReturnKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class ForKeyword implements Keyword<Block.EvaluationInfo<?>> {
|
||||
@@ -23,7 +23,8 @@ public class ForKeyword implements Keyword<Block.EvaluationInfo<?>> {
|
||||
private final Expression<?> incrementer;
|
||||
private final SourcePosition position;
|
||||
|
||||
public ForKeyword(Block conditional, Expression<?> initializer, Expression<Boolean> statement, Expression<?> incrementer, SourcePosition position) {
|
||||
public ForKeyword(Block conditional, Expression<?> initializer, Expression<Boolean> statement, Expression<?> incrementer,
|
||||
SourcePosition position) {
|
||||
this.conditional = conditional;
|
||||
this.initializer = initializer;
|
||||
this.statement = statement;
|
||||
|
||||
@@ -7,18 +7,17 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class WhileKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public abstract class BinaryOperation<I, O> implements Expression<O> {
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BooleanAndOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BooleanNotOperation extends UnaryOperation<Boolean> {
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
@@ -27,7 +27,7 @@ public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyBoolean(implementationArguments, scope) || right.applyBoolean(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class ConcatenationOperation extends BinaryOperation<Object, Object> {
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class DivisionOperation extends BinaryOperation<Number, Number> {
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class ModuloOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -27,7 +27,7 @@ public class ModuloOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) % right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class MultiplicationOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -27,7 +27,7 @@ public class MultiplicationOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) * right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class NegationOperation extends UnaryOperation<Number> {
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class NumberAdditionOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -27,7 +27,7 @@ public class NumberAdditionOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) + right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class SubtractionOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -27,7 +27,7 @@ public class SubtractionOperation extends BinaryOperation<Number, Number> {
|
||||
public double applyDouble(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) - right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public abstract class UnaryOperation<T> implements Expression<T> {
|
||||
|
||||
@@ -9,11 +9,11 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
import static com.dfsek.terra.api.util.MathUtil.EPSILON;
|
||||
|
||||
@@ -42,7 +42,7 @@ public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
if(leftValue instanceof Number l && rightValue instanceof Number r) {
|
||||
return FastMath.abs(l.doubleValue() - r.doubleValue()) <= EPSILON;
|
||||
}
|
||||
|
||||
|
||||
return leftValue.equals(rightValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class GreaterOrEqualsThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class GreaterThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean> {
|
||||
@@ -29,7 +29,7 @@ public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean>
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) <= right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class LessThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
@@ -29,7 +29,7 @@ public class LessThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
public boolean applyBoolean(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return left.applyDouble(implementationArguments, scope) < right.applyDouble(implementationArguments, scope);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
|
||||
@@ -9,11 +9,11 @@ package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.operations.BinaryOperation;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
import static com.dfsek.terra.api.util.MathUtil.EPSILON;
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BooleanVariable implements Variable<Boolean> {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class NumberVariable implements Variable<Number> {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class StringVariable implements Variable<String> {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public interface Variable<T> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BoolAssignmentNode extends VariableAssignmentNode<Boolean> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class NumAssignmentNode extends VariableAssignmentNode<Number> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class StrAssignmentNode extends VariableAssignmentNode<String> {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public abstract class VariableAssignmentNode<T> implements Expression<T> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BoolVariableReferenceNode extends VariableReferenceNode<Boolean> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class NumVariableReferenceNode extends VariableReferenceNode<Number> {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class StrVariableReferenceNode extends VariableReferenceNode<String> {
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public abstract class VariableReferenceNode<T> implements Expression<T> {
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope.ScopeBuilder;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -24,6 +20,7 @@ import java.util.Random;
|
||||
import com.dfsek.terra.addons.terrascript.parser.Parser;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Executable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope.ScopeBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.BinaryNumberFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.BiomeFunctionBuilder;
|
||||
|
||||
@@ -10,12 +10,12 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class BinaryNumberFunctionBuilder implements FunctionBuilder<Function<Number>> {
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.BiomeFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.constants.BooleanConstant;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.constants.StringConstant;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.BlockFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.CheckBlockFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunction> {
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.EntityFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.GetMarkFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class GetMarkFunctionBuilder implements FunctionBuilder<GetMarkFunction> {
|
||||
|
||||
@@ -9,11 +9,11 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.LootFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.PullFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.RandomFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class RandomFunctionBuilder implements FunctionBuilder<RandomFunction> {
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.RecursionsFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class RecursionsFunctionBuilder implements FunctionBuilder<RecursionsFunction> {
|
||||
|
||||
@@ -9,10 +9,10 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.SetMarkFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class SetMarkFunctionBuilder implements FunctionBuilder<SetMarkFunction> {
|
||||
|
||||
@@ -9,11 +9,11 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.StateFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.functions.StructureFunction;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
|
||||
@@ -10,13 +10,13 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Void>> {
|
||||
|
||||
@@ -9,12 +9,12 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class UnaryNumberFunctionBuilder implements FunctionBuilder<Function<Number>> {
|
||||
|
||||
@@ -9,12 +9,12 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void>> {
|
||||
|
||||
@@ -9,13 +9,13 @@ package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
|
||||
@@ -9,12 +9,12 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
@@ -14,13 +14,13 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.constants.StringConstant;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
@@ -69,7 +69,8 @@ public class BlockFunction implements Function<Void> {
|
||||
void setBlock(ImplementationArguments implementationArguments, Scope scope,
|
||||
TerraImplementationArguments arguments, BlockState rot) {
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.evaluate(implementationArguments, scope).doubleValue(),
|
||||
z.evaluate(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
z.evaluate(implementationArguments, scope).doubleValue()),
|
||||
arguments.getRotation());
|
||||
try {
|
||||
Vector3.Mutable set = Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
y.evaluate(implementationArguments, scope).doubleValue(),
|
||||
|
||||
@@ -9,12 +9,12 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.constants.ConstantExpression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
@@ -46,7 +46,8 @@ public class EntityFunction implements Function<Void> {
|
||||
public Void evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.evaluate(implementationArguments, scope).doubleValue(),
|
||||
z.evaluate(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
z.evaluate(implementationArguments, scope).doubleValue()),
|
||||
arguments.getRotation());
|
||||
|
||||
Entity entity = arguments.getWorld().spawnEntity(Vector3.of(xz.getX(), y.evaluate(implementationArguments, scope).doubleValue(),
|
||||
xz.getZ())
|
||||
|
||||
@@ -9,12 +9,12 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
@@ -35,7 +35,8 @@ public class GetMarkFunction implements Function<String> {
|
||||
public String evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.evaluate(implementationArguments, scope).doubleValue(),
|
||||
z.evaluate(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
z.evaluate(implementationArguments, scope).doubleValue()),
|
||||
arguments.getRotation());
|
||||
|
||||
String mark = arguments.getMark(Vector3.of(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(
|
||||
y.evaluate(implementationArguments, scope).doubleValue()),
|
||||
|
||||
@@ -13,13 +13,13 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
@@ -70,7 +70,7 @@ public class LootFunction implements Function<Void> {
|
||||
y.evaluate(implementationArguments, scope)
|
||||
.intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
|
||||
|
||||
try {
|
||||
BlockEntity data = arguments.getWorld().getBlockEntity(apply);
|
||||
if(!(data instanceof Container container)) {
|
||||
@@ -78,12 +78,12 @@ public class LootFunction implements Function<Void> {
|
||||
apply, data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LootPopulateEvent event = new LootPopulateEvent(container, table,
|
||||
arguments.getWorld().getPack(), script);
|
||||
platform.getEventManager().callEvent(event);
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
|
||||
event.getTable().fillInventory(container.getInventory(),
|
||||
new Random(apply.hashCode()));
|
||||
data.update(false);
|
||||
|
||||
@@ -9,14 +9,14 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.constants.ConstantExpression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
@@ -44,7 +44,8 @@ public class PullFunction implements Function<Void> {
|
||||
public Void evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.evaluate(implementationArguments, scope).doubleValue(),
|
||||
z.evaluate(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
z.evaluate(implementationArguments, scope).doubleValue()),
|
||||
arguments.getRotation());
|
||||
|
||||
Vector3.Mutable mutable = Vector3.of(FastMath.roundToInt(xz.getX()), y.evaluate(implementationArguments, scope).intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class RandomFunction implements Function<Integer> {
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
|
||||
|
||||
public class RecursionsFunction implements Function<Number> {
|
||||
|
||||
@@ -9,12 +9,12 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
@@ -25,7 +25,8 @@ public class SetMarkFunction implements Function<Void> {
|
||||
private final SourcePosition position;
|
||||
private final Expression<String> mark;
|
||||
|
||||
public SetMarkFunction(Expression<Number> x, Expression<Number> y, Expression<Number> z, Expression<String> mark, SourcePosition position) {
|
||||
public SetMarkFunction(Expression<Number> x, Expression<Number> y, Expression<Number> z, Expression<String> mark,
|
||||
SourcePosition position) {
|
||||
this.position = position;
|
||||
this.mark = mark;
|
||||
this.x = x;
|
||||
@@ -37,7 +38,8 @@ public class SetMarkFunction implements Function<Void> {
|
||||
public Void evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.evaluate(implementationArguments, scope).doubleValue(),
|
||||
z.evaluate(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
z.evaluate(implementationArguments, scope).doubleValue()),
|
||||
arguments.getRotation());
|
||||
|
||||
|
||||
arguments.setMark(Vector3.of(FastMath.floorToInt(xz.getX()),
|
||||
|
||||
@@ -11,12 +11,12 @@ import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
@@ -42,7 +42,8 @@ public class StateFunction implements Function<Void> {
|
||||
public Void evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.evaluate(implementationArguments, scope).doubleValue(),
|
||||
z.evaluate(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
z.evaluate(implementationArguments, scope).doubleValue()),
|
||||
arguments.getRotation());
|
||||
|
||||
|
||||
Vector3 origin = Vector3.of(FastMath.roundToInt(xz.getX()), y.evaluate(implementationArguments, scope).intValue(),
|
||||
|
||||
@@ -13,13 +13,13 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -62,7 +62,8 @@ public class StructureFunction implements Function<Boolean> {
|
||||
throw new RuntimeException("Structure recursion too deep: " + arguments.getRecursions());
|
||||
|
||||
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.evaluate(implementationArguments, scope).doubleValue(),
|
||||
z.evaluate(implementationArguments, scope).doubleValue()), arguments.getRotation());
|
||||
z.evaluate(implementationArguments, scope).doubleValue()),
|
||||
arguments.getRotation());
|
||||
|
||||
|
||||
String app = id.evaluate(implementationArguments, scope);
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.LookaheadStream;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.LookaheadStream;
|
||||
|
||||
|
||||
public class LookaheadStreamTest {
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class ParserTest {
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.script.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import com.dfsek.terra.addons.terrascript.parser.lang.Expression.ReturnType;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.constants.NumericConstant;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.constants.StringConstant;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.tokenizer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class SamplerFunctionBuilder implements FunctionBuilder<com.dfsek.terra.addons.terrascript.parser.lang.functions.Function<Number>> {
|
||||
|
||||
Reference in New Issue
Block a user