mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-04 06:46:21 +00:00
Initial terrascript 2 commit
This commit is contained in:
@@ -12,4 +12,140 @@ dependencies {
|
||||
tasks.named<ShadowJar>("shadowJar") {
|
||||
relocate("org.apache.commons", "com.dfsek.terra.addons.terrascript.lib.commons")
|
||||
relocate("net.jafama", "com.dfsek.terra.addons.terrascript.lib.jafama")
|
||||
}
|
||||
}
|
||||
|
||||
val astSourceSet = buildDir.resolve("generated/ast")
|
||||
val astPackage = astSourceSet.resolve("com/dfsek/terra/addons/terrascript/ast")
|
||||
|
||||
// Auto generate AST classes rather than writing them by hand
|
||||
tasks.register("genTerrascriptAstClasses") {
|
||||
val packageName = astPackage.toRelativeString(astSourceSet).replace('/', '.')
|
||||
fun generateClass(name: String, imports: List<String>, nodes: List<Pair<String, List<String>>>) {
|
||||
val src = StringBuilder()
|
||||
src.appendLine("package $packageName;\n");
|
||||
for (imprt in imports) src.appendLine("import $imprt;")
|
||||
src.appendLine("""
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.Environment;
|
||||
|
||||
/**
|
||||
* Auto-generated class via genTerrascriptAstClasses gradle task
|
||||
*/
|
||||
public abstract class $name {
|
||||
|
||||
public final SourcePosition position;
|
||||
private Environment environment;
|
||||
|
||||
public $name(SourcePosition position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Environment getEnvironment() {
|
||||
if (this.environment == null) throw new RuntimeException("Compilation bug! environment has not been set yet for AST node");
|
||||
return environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(Environment environment) {
|
||||
if (this.environment != null) throw new RuntimeException("Compilation bug! environment has already been set for AST node and cannot be changed");
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public interface Visitor<R> {
|
||||
|
||||
""".trimIndent())
|
||||
for (node in nodes) {
|
||||
src.appendLine(" R visit${node.first}$name(${node.first} ${name.toLowerCase()});")
|
||||
}
|
||||
|
||||
src.appendLine("""
|
||||
|
|
||||
| }
|
||||
|
|
||||
| public abstract <R> R accept(Visitor<R> visitor);
|
||||
""".trimMargin())
|
||||
|
||||
for (node in nodes) {
|
||||
src.appendLine()
|
||||
// Inner class declaration
|
||||
src.appendLine(" public static class ${node.first} extends $name {\n")
|
||||
|
||||
// Add fields
|
||||
for (field in node.second) {
|
||||
src.appendLine(" public final $field;")
|
||||
}
|
||||
src.appendLine()
|
||||
|
||||
// Add constructor
|
||||
src.append(" public ${node.first}(")
|
||||
for (field in node.second)
|
||||
src.append("$field, ")
|
||||
src.appendLine("SourcePosition position) {\n super(position);")
|
||||
for (field in node.second) {
|
||||
val fieldName = field.split(' ').last()
|
||||
src.appendLine(" this.$fieldName = $fieldName;")
|
||||
}
|
||||
|
||||
src.appendLine("""
|
||||
| }
|
||||
|
|
||||
| @Override
|
||||
| public <R> R accept(Visitor<R> visitor) {
|
||||
| return visitor.visit${node.first}$name(this);
|
||||
| }
|
||||
| }
|
||||
""".trimMargin())
|
||||
}
|
||||
src.appendLine("}")
|
||||
val outputFile = astPackage.resolve("$name.java")
|
||||
outputFile.writeText(src.toString())
|
||||
}
|
||||
|
||||
doLast {
|
||||
astSourceSet.deleteRecursively()
|
||||
astPackage.mkdirs()
|
||||
generateClass("Expr", listOf(
|
||||
"com.dfsek.terra.addons.terrascript.Type",
|
||||
"com.dfsek.terra.addons.terrascript.parser.UnaryOperator",
|
||||
"com.dfsek.terra.addons.terrascript.parser.BinaryOperator",
|
||||
"java.util.List",
|
||||
),
|
||||
listOf(
|
||||
Pair("Binary", listOf("Expr left", "BinaryOperator operator", "Expr right",)),
|
||||
Pair("Grouping", listOf("Expr expression")),
|
||||
Pair("Literal", listOf("Object value", "Type type")),
|
||||
Pair("Unary", listOf("UnaryOperator operator", "Expr operand")),
|
||||
Pair("Call", listOf("String identifier", "List<Expr> arguments")),
|
||||
Pair("Variable", listOf("String identifier")),
|
||||
Pair("Assignment", listOf("Variable lValue", "Expr rValue")),
|
||||
Pair("Void", listOf()),
|
||||
))
|
||||
generateClass("Stmt", listOf(
|
||||
"com.dfsek.terra.addons.terrascript.Type",
|
||||
"com.dfsek.terra.api.util.generic.pair.Pair",
|
||||
"java.util.List",
|
||||
),
|
||||
listOf(
|
||||
Pair("Expression", listOf("Expr expression")),
|
||||
Pair("Block", listOf("List<Stmt> statements")),
|
||||
Pair("FunctionDeclaration", listOf("String identifier", "List<Pair<String, Type>> parameters", "Type type", "Block body")),
|
||||
Pair("VariableDeclaration", listOf("Type type", "String identifier", "Expr value")),
|
||||
Pair("Return", listOf("Expr value")),
|
||||
Pair("If", listOf("Expr condition", "Block trueBody", "List<Pair<Expr, Block>> elseIfClauses", "Block elseBody")),
|
||||
Pair("For", listOf("Stmt initializer", "Expr condition", "Expr incrementer", "Block body")),
|
||||
Pair("While", listOf("Expr condition", "Block body")),
|
||||
Pair("NoOp", listOf()),
|
||||
Pair("Break", listOf()),
|
||||
Pair("Continue", listOf()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.getByName("compileJava") {
|
||||
dependsOn("genTerrascriptAstClasses")
|
||||
}
|
||||
|
||||
sourceSets.getByName("main") {
|
||||
java {
|
||||
srcDirs(astSourceSet)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.dfsek.terra.addons.terrascript;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Environment.ScopeException.NonexistentSymbolException;
|
||||
import com.dfsek.terra.addons.terrascript.Environment.ScopeException.SymbolAlreadyExistsException;
|
||||
import com.dfsek.terra.addons.terrascript.Environment.ScopeException.SymbolTypeMismatchException;
|
||||
import com.dfsek.terra.addons.terrascript.Environment.Symbol.Function;
|
||||
import com.dfsek.terra.addons.terrascript.Environment.Symbol.Variable;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
public class Environment {
|
||||
|
||||
private final Environment outer;
|
||||
|
||||
private final boolean canAccessOuterVariables;
|
||||
|
||||
private final HashMap<String, Symbol> symbolTable = new HashMap<>();
|
||||
|
||||
private final boolean inLoop;
|
||||
|
||||
private Environment(@Nullable Environment outer, boolean canAccessOuterVariables, boolean inLoop) {
|
||||
this.outer = outer;
|
||||
this.canAccessOuterVariables = canAccessOuterVariables;
|
||||
this.inLoop = inLoop;
|
||||
}
|
||||
|
||||
public static Environment global() {
|
||||
return new Environment(null, false, false);
|
||||
}
|
||||
|
||||
public Environment lexicalInner() {
|
||||
return new Environment(this, true, inLoop);
|
||||
}
|
||||
|
||||
public Environment loopInner() {
|
||||
return new Environment(this, true, true);
|
||||
}
|
||||
|
||||
public Environment functionalInner() {
|
||||
return new Environment(this, false, inLoop);
|
||||
}
|
||||
|
||||
public Environment outer() {
|
||||
if(outer == null) throw new RuntimeException("Attempted to retrieve outer scope of global scope");
|
||||
return outer;
|
||||
}
|
||||
|
||||
public Function getFunction(String id) throws NonexistentSymbolException, SymbolTypeMismatchException {
|
||||
Function function;
|
||||
Symbol symbol = symbolTable.get(id);
|
||||
if(symbol == null) {
|
||||
if(outer == null) throw new NonexistentSymbolException();
|
||||
function = outer.getFunction(id);
|
||||
} else {
|
||||
if(!(symbol instanceof Function)) throw new SymbolTypeMismatchException();
|
||||
function = (Function) symbol;
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns symbol table entry for a variable identifier, includes enclosing scopes in lookup.
|
||||
* <br>
|
||||
* Does not factor context of lookup, checks for order of declaration should be done while
|
||||
* symbol tables are being populated.
|
||||
*
|
||||
* @param id identifier used in variable declaration
|
||||
*
|
||||
* @return variable symbol table entry
|
||||
*
|
||||
* @throws NonexistentSymbolException if symbol is not declared in symbol table
|
||||
* @throws SymbolTypeMismatchException if symbol is not a variable
|
||||
*/
|
||||
public Variable getVariable(String id) throws NonexistentSymbolException, SymbolTypeMismatchException {
|
||||
Variable variable;
|
||||
Symbol symbol = symbolTable.get(id);
|
||||
if(symbol == null) {
|
||||
if(!canAccessOuterVariables || outer == null) throw new NonexistentSymbolException();
|
||||
variable = outer.getVariable(id);
|
||||
} else {
|
||||
if(!(symbol instanceof Variable)) throw new SymbolTypeMismatchException();
|
||||
variable = (Variable) symbol;
|
||||
}
|
||||
return variable;
|
||||
}
|
||||
|
||||
public void put(String id, Symbol symbol) throws SymbolAlreadyExistsException {
|
||||
if(symbolTable.containsKey(id)) throw new SymbolAlreadyExistsException();
|
||||
symbolTable.put(id, symbol);
|
||||
}
|
||||
|
||||
public static abstract class Symbol {
|
||||
|
||||
public static class Function extends Symbol {
|
||||
|
||||
public final Type type;
|
||||
|
||||
public final List<Pair<String, Type>> parameters;
|
||||
|
||||
public Function(Type type, List<Pair<String, Type>> parameters) {
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Variable extends Symbol {
|
||||
|
||||
public final Type type;
|
||||
|
||||
public Variable(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ScopeException extends RuntimeException {
|
||||
|
||||
public static class SymbolAlreadyExistsException extends ScopeException {
|
||||
}
|
||||
|
||||
|
||||
public static class NonexistentSymbolException extends ScopeException {
|
||||
}
|
||||
|
||||
|
||||
public static class SymbolTypeMismatchException extends ScopeException {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dfsek.terra.addons.terrascript;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ErrorHandler {
|
||||
|
||||
private final List<Exception> exceptions = new ArrayList<>();
|
||||
|
||||
public void add(Exception e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
|
||||
public void throwAny() throws Exception {
|
||||
for(Exception e : exceptions) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@
|
||||
package com.dfsek.terra.addons.terrascript;
|
||||
|
||||
import com.dfsek.terra.addons.manifest.api.AddonInitializer;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.StructureScript;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
@@ -31,6 +31,7 @@ public class TerraScriptAddon implements AddonInitializer {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
platform.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(addon, ConfigPackPreLoadEvent.class)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.dfsek.terra.addons.terrascript;
|
||||
|
||||
// TODO - Make not enum
|
||||
public enum Type {
|
||||
NUMBER,
|
||||
STRING,
|
||||
BOOLEAN,
|
||||
VOID,
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class CompilationException extends Exception {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 6744390543046766386L;
|
||||
private final SourcePosition position;
|
||||
|
||||
public CompilationException(String message, SourcePosition position) {
|
||||
super(message);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "Error at " + position + ": " + super.getMessage();
|
||||
}
|
||||
|
||||
public SourcePosition getPosition() {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.lexer.exceptions;
|
||||
package com.dfsek.terra.addons.terrascript.exception.lexer;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.lexer.exceptions;
|
||||
package com.dfsek.terra.addons.terrascript.exception.lexer;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.lexer.exceptions;
|
||||
package com.dfsek.terra.addons.terrascript.exception.lexer;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.exceptions.ParseException;
|
||||
|
||||
|
||||
public abstract class TokenizerException extends ParseException {
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.dfsek.terra.addons.terrascript.exception.semanticanalysis;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.exception.CompilationException;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class IdentifierAlreadyDeclaredException extends CompilationException {
|
||||
public IdentifierAlreadyDeclaredException(String message, SourcePosition position) {
|
||||
super(message, position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.dfsek.terra.addons.terrascript.exception.semanticanalysis;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.exception.CompilationException;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class InvalidFunctionDeclarationException extends CompilationException {
|
||||
public InvalidFunctionDeclarationException(String message, SourcePosition position) {
|
||||
super(message, position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.dfsek.terra.addons.terrascript.exception.semanticanalysis;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.exception.CompilationException;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class InvalidTypeException extends CompilationException {
|
||||
public InvalidTypeException(String message, SourcePosition position) {
|
||||
super(message, position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.dfsek.terra.addons.terrascript.exception.semanticanalysis;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.exception.CompilationException;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class UndefinedReferenceException extends CompilationException {
|
||||
public UndefinedReferenceException(String message, SourcePosition position) {
|
||||
super(message, position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,585 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Executable;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.BooleanConstant;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.NumericConstant;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.StringConstant;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.UserDefinedFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow.BreakKeyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow.ContinueKeyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow.FailKeyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow.ReturnKeyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.looplike.ForKeyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.looplike.IfKeyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.looplike.WhileKeyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BooleanAndOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BooleanNotOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BooleanOrOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.ConcatenationOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.DivisionOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.ModuloOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.MultiplicationOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.NegationOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.NumberAdditionOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.SubtractionOperation;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements.EqualsStatement;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements.GreaterOrEqualsThanStatement;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements.GreaterThanStatement;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements.LessThanOrEqualsStatement;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements.LessThanStatement;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements.NotEqualsStatement;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign.BoolAssignmentNode;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign.NumAssignmentNode;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign.StrAssignmentNode;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign.VariableAssignmentNode;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.reference.BoolVariableReferenceNode;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.reference.NumVariableReferenceNode;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.reference.StrVariableReferenceNode;
|
||||
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.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
public class Parser {
|
||||
private final List<String> ignoredFunctions = new ArrayList<>();
|
||||
|
||||
private final Lexer lexer;
|
||||
|
||||
public Parser(Lexer lexer) {
|
||||
this.lexer = lexer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse input
|
||||
*
|
||||
* @return executable {@link Block}
|
||||
*
|
||||
* @throws ParseException If parsing fails.
|
||||
*/
|
||||
public Executable parse(Scope.ScopeBuilder scopeBuilder) {
|
||||
return new Executable(parseBlock(scopeBuilder, Type.VOID), scopeBuilder);
|
||||
}
|
||||
|
||||
private WhileKeyword parseWhileLoop(Scope.ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = lexer.consume("Expected 'while' keyword at beginning of while loop", TokenType.WHILE_LOOP).position();
|
||||
lexer.consume("Expected '(' proceeding 'while' keyword", TokenType.OPEN_PAREN);
|
||||
scopeBuilder = scopeBuilder.innerLoopScope();
|
||||
Expression<?> condition = parseExpression(scopeBuilder);
|
||||
ParserUtil.ensureReturnType(condition, Type.BOOLEAN);
|
||||
lexer.consume("Expected ')' proceeding while loop condition", TokenType.CLOSE_PAREN);
|
||||
return new WhileKeyword(parseStatementBlock(scopeBuilder, Type.VOID), (Expression<Boolean>) condition,
|
||||
start); // While loop
|
||||
}
|
||||
|
||||
private IfKeyword parseIfStatement(Scope.ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = lexer.consume("Expected 'if' keyword at beginning of if statement", TokenType.IF_STATEMENT).position();
|
||||
lexer.consume("Expected '(' proceeding 'if' keyword", TokenType.OPEN_PAREN);
|
||||
Expression<?> condition = parseExpression(scopeBuilder);
|
||||
ParserUtil.ensureReturnType(condition, Type.BOOLEAN);
|
||||
|
||||
lexer.consume("Expected ')' proceeding if statement condition", TokenType.CLOSE_PAREN);
|
||||
|
||||
Block elseBlock = null;
|
||||
Block statement = parseStatementBlock(scopeBuilder, Type.VOID);
|
||||
|
||||
List<Pair<Expression<Boolean>, Block>> elseIf = new ArrayList<>();
|
||||
|
||||
while(lexer.hasNext() && lexer.current().isType(TokenType.ELSE)) {
|
||||
lexer.consumeUnchecked(); // Consume else.
|
||||
if(lexer.current().isType(TokenType.IF_STATEMENT)) {
|
||||
lexer.consumeUnchecked(); // Consume if.
|
||||
Expression<?> elseCondition = parseExpression(scopeBuilder);
|
||||
ParserUtil.ensureReturnType(elseCondition, Type.BOOLEAN);
|
||||
elseIf.add(Pair.of((Expression<Boolean>) elseCondition, parseStatementBlock(scopeBuilder, Type.VOID)));
|
||||
} else {
|
||||
elseBlock = parseStatementBlock(scopeBuilder, Type.VOID);
|
||||
break; // Else must be last.
|
||||
}
|
||||
}
|
||||
|
||||
return new IfKeyword(statement, (Expression<Boolean>) condition, elseIf, elseBlock, start); // If statement
|
||||
}
|
||||
|
||||
private Block parseStatementBlock(Scope.ScopeBuilder scopeBuilder, Type blockReturnType) {
|
||||
if(lexer.current().isType(TokenType.BLOCK_BEGIN)) {
|
||||
lexer.consumeUnchecked();
|
||||
Block block = parseBlock(scopeBuilder, blockReturnType);
|
||||
lexer.consume("Expected block end '}' after block statements", TokenType.BLOCK_END);
|
||||
return block;
|
||||
} else {
|
||||
SourcePosition position = lexer.current().position();
|
||||
return new Block(Collections.singletonList(parseStatement(scopeBuilder)), position, blockReturnType);
|
||||
}
|
||||
}
|
||||
|
||||
private ForKeyword parseForLoop(Scope.ScopeBuilder scopeBuilder) {
|
||||
SourcePosition start = lexer.consume("Expected 'for' keyword at beginning of for loop", TokenType.FOR_LOOP).position();
|
||||
lexer.consume("Expected '(' after 'for' keyword", TokenType.OPEN_PAREN);
|
||||
scopeBuilder = scopeBuilder.innerLoopScope(); // new scope
|
||||
|
||||
Expression<?> initializer = switch(lexer.current().type()) {
|
||||
case TYPE_NUMBER, TYPE_STRING, TYPE_BOOLEAN -> {
|
||||
Token type = lexer.consume("Expected type before declaration", TokenType.TYPE_STRING, TokenType.TYPE_NUMBER,
|
||||
TokenType.TYPE_BOOLEAN, TokenType.TYPE_VOID);
|
||||
Token identifier = lexer.consume("Expected identifier after type", TokenType.IDENTIFIER);
|
||||
Expression<?> expr = parseVariableDeclaration(scopeBuilder, type, identifier);
|
||||
lexer.consume("Expected ';' after initializer within for loop", TokenType.STATEMENT_END);
|
||||
yield expr;
|
||||
}
|
||||
case IDENTIFIER -> {
|
||||
Expression<?> expr = parseAssignment(scopeBuilder);
|
||||
lexer.consume("Expected ';' after initializer within for loop", TokenType.STATEMENT_END);
|
||||
yield expr;
|
||||
}
|
||||
case STATEMENT_END -> {
|
||||
lexer.consumeUnchecked();
|
||||
yield Expression.NOOP;
|
||||
}
|
||||
default -> throw new ParseException("Unexpected token '" + lexer.current() + "', expected variable declaration or assignment",
|
||||
lexer.current().position());
|
||||
};
|
||||
|
||||
Expression<?> conditional;
|
||||
if(lexer.current().isType(TokenType.STATEMENT_END)) // If no conditional is provided, conditional defaults to true
|
||||
conditional = new BooleanConstant(true, lexer.current().position());
|
||||
else
|
||||
conditional = parseExpression(scopeBuilder);
|
||||
ParserUtil.ensureReturnType(conditional, Type.BOOLEAN);
|
||||
lexer.consume("Expected ';' separator after conditional within for loop", TokenType.STATEMENT_END);
|
||||
|
||||
Expression<?> incrementer;
|
||||
if(lexer.current().isType(TokenType.CLOSE_PAREN))
|
||||
// If no incrementer is provided, do nothing
|
||||
incrementer = Expression.NOOP;
|
||||
else if(scopeBuilder.containsVariable(lexer.current().lexeme())) // Assume variable assignment
|
||||
incrementer = parseAssignment(scopeBuilder);
|
||||
else
|
||||
incrementer = parseFunctionInvocation(
|
||||
lexer.consume("Expected function call within for loop incrementer, found '" + lexer.current().lexeme() + "' instead",
|
||||
TokenType.IDENTIFIER), scopeBuilder);
|
||||
lexer.consume("Expected ')' after for loop incrementer", TokenType.CLOSE_PAREN);
|
||||
|
||||
return new ForKeyword(parseStatementBlock(scopeBuilder, Type.VOID), initializer, (Expression<Boolean>) conditional,
|
||||
incrementer,
|
||||
start);
|
||||
}
|
||||
|
||||
private Expression<?> parseExpression(Scope.ScopeBuilder scopeBuilder) {
|
||||
return parseLogicOr(scopeBuilder);
|
||||
}
|
||||
|
||||
private Expression<?> parseLogicOr(Scope.ScopeBuilder scopeBuilder) {
|
||||
return parseLeftAssociativeBinaryOperation(this::parseLogicAnd, scopeBuilder, (op) -> {
|
||||
ParserUtil.ensureReturnType(op.left, Type.BOOLEAN);
|
||||
ParserUtil.ensureReturnType(op.right, Type.BOOLEAN);
|
||||
}, Map.of(TokenType.BOOLEAN_OR,
|
||||
(op) -> new BooleanOrOperation((Expression<Boolean>) op.left, (Expression<Boolean>) op.right, op.operator.position())));
|
||||
}
|
||||
|
||||
private Expression<?> parseLogicAnd(Scope.ScopeBuilder scopeBuilder) {
|
||||
return parseLeftAssociativeBinaryOperation(this::parseEquality, scopeBuilder, (op) -> {
|
||||
ParserUtil.ensureReturnType(op.left, Type.BOOLEAN);
|
||||
ParserUtil.ensureReturnType(op.right, Type.BOOLEAN);
|
||||
}, Map.of(TokenType.BOOLEAN_AND,
|
||||
(op) -> new BooleanAndOperation((Expression<Boolean>) op.left, (Expression<Boolean>) op.right, op.operator.position())));
|
||||
}
|
||||
|
||||
private Expression<?> parseEquality(Scope.ScopeBuilder scopeBuilder) {
|
||||
return parseLeftAssociativeBinaryOperation(this::parseComparison, scopeBuilder, Map.of(
|
||||
TokenType.EQUALS_EQUALS,
|
||||
(op) -> new EqualsStatement((Expression<Object>) op.left, (Expression<Object>) op.right, op.operator.position()),
|
||||
TokenType.BANG_EQUALS,
|
||||
(op) -> new NotEqualsStatement((Expression<Object>) op.left, (Expression<Object>) op.right, op.operator.position())
|
||||
));
|
||||
}
|
||||
|
||||
private Expression<?> parseComparison(Scope.ScopeBuilder scopeBuilder) {
|
||||
return parseLeftAssociativeBinaryOperation(this::parseTerm, scopeBuilder, (op) -> {
|
||||
ParserUtil.ensureReturnType(op.left, Type.NUMBER);
|
||||
ParserUtil.ensureReturnType(op.right, Type.NUMBER);
|
||||
}, Map.of(
|
||||
TokenType.LESS,
|
||||
(op) -> new LessThanStatement((Expression<Number>) op.left, (Expression<Number>) op.right, op.operator.position()),
|
||||
TokenType.LESS_EQUALS,
|
||||
(op) -> new LessThanOrEqualsStatement((Expression<Number>) op.left, (Expression<Number>) op.right, op.operator.position()),
|
||||
TokenType.GREATER,
|
||||
(op) -> new GreaterThanStatement((Expression<Number>) op.left, (Expression<Number>) op.right, op.operator.position()),
|
||||
TokenType.GREATER_EQUAL,
|
||||
(op) -> new GreaterOrEqualsThanStatement((Expression<Number>) op.left, (Expression<Number>) op.right,
|
||||
op.operator.position())
|
||||
));
|
||||
}
|
||||
|
||||
private Expression<?> parseTerm(Scope.ScopeBuilder scopeBuilder) {
|
||||
return parseLeftAssociativeBinaryOperation(this::parseFactor, scopeBuilder, Map.of(
|
||||
TokenType.MINUS, (op) -> {
|
||||
ParserUtil.ensureReturnType(op.left, Type.NUMBER);
|
||||
ParserUtil.ensureReturnType(op.right, Type.NUMBER);
|
||||
return new SubtractionOperation((Expression<Number>) op.left, (Expression<Number>) op.right, op.operator.position());
|
||||
},
|
||||
TokenType.PLUS, (op) -> {
|
||||
if(op.left.returnType() == Type.NUMBER && op.right.returnType() == Type.NUMBER)
|
||||
return new NumberAdditionOperation((Expression<Number>) op.left, (Expression<Number>) op.right,
|
||||
op.operator.position());
|
||||
else
|
||||
return new ConcatenationOperation((Expression<Object>) op.left, (Expression<Object>) op.right,
|
||||
op.operator.position());
|
||||
}));
|
||||
}
|
||||
|
||||
private Expression<?> parseFactor(Scope.ScopeBuilder scopeBuilder) {
|
||||
return parseLeftAssociativeBinaryOperation(this::parseUnary, scopeBuilder, (op) -> {
|
||||
ParserUtil.ensureReturnType(op.left, Type.NUMBER);
|
||||
ParserUtil.ensureReturnType(op.right, Type.NUMBER);
|
||||
}, Map.of(
|
||||
TokenType.STAR,
|
||||
(op) -> new MultiplicationOperation((Expression<Number>) op.left, (Expression<Number>) op.right, op.operator.position()),
|
||||
TokenType.FORWARD_SLASH,
|
||||
(op) -> new DivisionOperation((Expression<Number>) op.left, (Expression<Number>) op.right, op.operator.position()),
|
||||
TokenType.MODULO_OPERATOR,
|
||||
(op) -> new ModuloOperation((Expression<Number>) op.left, (Expression<Number>) op.right, op.operator.position())
|
||||
));
|
||||
}
|
||||
|
||||
private Expression<?> parseUnary(Scope.ScopeBuilder scopeBuilder) {
|
||||
if(lexer.current().isType(TokenType.BANG, TokenType.MINUS)) {
|
||||
Token operator = lexer.consumeUnchecked();
|
||||
Expression<?> right = parseUnary(scopeBuilder);
|
||||
return switch(operator.type()) {
|
||||
case BANG -> {
|
||||
ParserUtil.ensureReturnType(right, Type.BOOLEAN);
|
||||
yield new BooleanNotOperation((Expression<Boolean>) right, operator.position());
|
||||
}
|
||||
case MINUS -> {
|
||||
ParserUtil.ensureReturnType(right, Type.NUMBER);
|
||||
yield new NegationOperation((Expression<Number>) right, operator.position());
|
||||
}
|
||||
default -> throw new IllegalStateException();
|
||||
};
|
||||
}
|
||||
return parsePrimary(scopeBuilder);
|
||||
}
|
||||
|
||||
private Expression<?> parsePrimary(Scope.ScopeBuilder scopeBuilder) {
|
||||
Token token = lexer.consumeUnchecked();
|
||||
return switch(token.type()) {
|
||||
case NUMBER -> {
|
||||
String content = token.lexeme();
|
||||
yield new NumericConstant(content.contains(".") ? Double.parseDouble(content) : Integer.parseInt(content),
|
||||
token.position());
|
||||
}
|
||||
case STRING -> new StringConstant(token.lexeme(), token.position());
|
||||
case BOOLEAN -> new BooleanConstant(Boolean.parseBoolean(token.lexeme()), token.position());
|
||||
case OPEN_PAREN -> {
|
||||
Expression<?> expr = parseExpression(scopeBuilder);
|
||||
lexer.consume("Missing ')' at end of expression group", TokenType.CLOSE_PAREN);
|
||||
yield expr;
|
||||
}
|
||||
case IDENTIFIER -> {
|
||||
if(scopeBuilder.containsFunction(token.lexeme()))
|
||||
yield parseFunctionInvocation(token, scopeBuilder);
|
||||
else if(scopeBuilder.containsVariable(token.lexeme())) {
|
||||
Type variableType = scopeBuilder.getVaraibleType(token.lexeme());
|
||||
yield switch(variableType) {
|
||||
case NUMBER -> new NumVariableReferenceNode(token.position(), variableType, scopeBuilder.getIndex(token.lexeme()));
|
||||
case BOOLEAN -> new BoolVariableReferenceNode(token.position(), variableType,
|
||||
scopeBuilder.getIndex(token.lexeme()));
|
||||
case STRING -> new StrVariableReferenceNode(token.position(), variableType, scopeBuilder.getIndex(token.lexeme()));
|
||||
default -> throw new ParseException("Illegal type for variable reference: " + variableType, token.position());
|
||||
};
|
||||
}
|
||||
throw new ParseException("Identifier '" + token.lexeme() + "' is not defined in this scope", token.position());
|
||||
}
|
||||
default -> throw new ParseException("Unexpected token '" + token.lexeme() + "' when parsing expression", token.position());
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses expressions of higher precedence, then sequentially parses any binary operators of the same
|
||||
* precedence from left to right. Operands for each operation are parsed with the higher precedence rule first.
|
||||
* <p>
|
||||
* E.g. for expression <pre>'a * b + c - d * e + f'</pre> where - and + are at same precedence, and * at a higher precedence:
|
||||
* <pre>
|
||||
* 1. Start parsing higher precedence:
|
||||
* a ...
|
||||
*
|
||||
* 2. Higher precedence stops because +:
|
||||
* (a * b) + ...
|
||||
*
|
||||
* 3. Parse right of + at higher precedence until current precedence operator or end:
|
||||
* (a * b) + (c) - ...
|
||||
*
|
||||
* 4. Group as one expression:
|
||||
* ((a * b) + (c)) - ...
|
||||
*
|
||||
* 5. Repeat 3-4 until end of expression:
|
||||
* ((((a * b) + (c)) - (d * e)) + (f))
|
||||
* </pre>
|
||||
*
|
||||
* @param higherPrecedence Parsing rule for expression of higher precedence
|
||||
* @param scopeBuilder
|
||||
* @param init Initial code to run for any matching operands + operator
|
||||
* @param operators List of binary operators of this precedence mapped to how to parse them
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Expression<?> parseLeftAssociativeBinaryOperation(Function<Scope.ScopeBuilder, Expression<?>> higherPrecedence,
|
||||
Scope.ScopeBuilder scopeBuilder,
|
||||
Consumer<BinaryOperationInfo> init,
|
||||
Map<TokenType, Function<BinaryOperationInfo, Expression<?>>> operators) {
|
||||
Expression<?> expr = higherPrecedence.apply(scopeBuilder);
|
||||
TokenType[] opTypes = operators.keySet().toArray(new TokenType[0]);
|
||||
while(lexer.current().isType(opTypes)) { // Parse binary operator if a matching token of this precedence
|
||||
Token operator = lexer.consumeUnchecked();
|
||||
Expression<?> right = higherPrecedence.apply(scopeBuilder);
|
||||
BinaryOperationInfo op = new BinaryOperationInfo(expr, operator, right);
|
||||
init.accept(op);
|
||||
expr = operators.get(operator.type()).apply(op);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
|
||||
private Expression<?> parseLeftAssociativeBinaryOperation(Function<Scope.ScopeBuilder, Expression<?>> higherPrecedence,
|
||||
Scope.ScopeBuilder scopeBuilder,
|
||||
Map<TokenType, Function<BinaryOperationInfo, Expression<?>>> operators) {
|
||||
return parseLeftAssociativeBinaryOperation(higherPrecedence, scopeBuilder, (op) -> { }, operators);
|
||||
}
|
||||
|
||||
private record BinaryOperationInfo(Expression<?> left, Token operator, Expression<?> right) {
|
||||
}
|
||||
|
||||
private Expression<?> parseDeclaration(Scope.ScopeBuilder scopeBuilder) {
|
||||
Token type = lexer.consume("Expected type before declaration", TokenType.TYPE_STRING, TokenType.TYPE_NUMBER, TokenType.TYPE_BOOLEAN,
|
||||
TokenType.TYPE_VOID);
|
||||
Token identifier = lexer.consume("Expected identifier after type", TokenType.IDENTIFIER);
|
||||
|
||||
return switch(lexer.current().type()) {
|
||||
case ASSIGNMENT -> parseVariableDeclaration(scopeBuilder, type, identifier);
|
||||
case OPEN_PAREN -> parseFunctionDeclaration(scopeBuilder, type, identifier);
|
||||
default -> throw new ParseException(
|
||||
"Expected '=' for variable assignment or '(' for function declaration after identifier '" + identifier.lexeme() + "'",
|
||||
lexer.current().position());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private Expression<?> parseVariableDeclaration(Scope.ScopeBuilder scopeBuilder, Token type, Token identifier) {
|
||||
lexer.consume("Expected '=' after identifier '" + identifier.lexeme() + "' for variable declaration", TokenType.ASSIGNMENT);
|
||||
|
||||
if(!type.isVariableDeclaration()) throw new ParseException("Expected type specification at beginning of variable declaration",
|
||||
type.position());
|
||||
|
||||
if(scopeBuilder.containsVariable(identifier.lexeme()))
|
||||
throw new ParseException(identifier.lexeme() + " is already defined in this scope", identifier.position());
|
||||
|
||||
Expression<?> value = parseExpression(scopeBuilder);
|
||||
ParserUtil.ensureReturnType(value, ParserUtil.getVariableReturnType(type));
|
||||
|
||||
String variableName = identifier.lexeme();
|
||||
return switch(value.returnType()) {
|
||||
case NUMBER -> new NumAssignmentNode((Expression<Number>) value, identifier.position(),
|
||||
scopeBuilder.declareNum(variableName));
|
||||
case STRING -> new StrAssignmentNode((Expression<String>) value, identifier.position(),
|
||||
scopeBuilder.declareStr(variableName));
|
||||
case BOOLEAN -> new BoolAssignmentNode((Expression<Boolean>) value, identifier.position(),
|
||||
scopeBuilder.declareBool(variableName));
|
||||
default -> throw new ParseException("Illegal type for variable declaration: " + type, value.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
private Expression<?> parseFunctionDeclaration(Scope.ScopeBuilder scopeBuilder, Token type, Token identifier) {
|
||||
lexer.consume("Expected '(' after identifier '" + identifier.lexeme() + "' for function declaration", TokenType.OPEN_PAREN);
|
||||
|
||||
if(!(type.isType(TokenType.TYPE_STRING, TokenType.TYPE_BOOLEAN, TokenType.TYPE_NUMBER, TokenType.TYPE_VOID)))
|
||||
throw new ParseException("Invalid function declaration return type specification " + type.type(), type.position());
|
||||
|
||||
if(scopeBuilder.containsVariable(identifier.lexeme()))
|
||||
throw new ParseException(identifier.lexeme() + " is already defined in this scope", identifier.position());
|
||||
|
||||
Type returnType = ParserUtil.getVariableReturnType(type);
|
||||
|
||||
Scope.ScopeBuilder functionBodyScope = scopeBuilder.functionScope();
|
||||
|
||||
// Declare parameter names into function body scope
|
||||
List<Pair<Integer, Type>> parameterInfo = getFunctionParameterDeclaration().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 parameter type: " + arg.getRight());
|
||||
}, arg.getRight())).toList();
|
||||
|
||||
Block body = parseStatementBlock(functionBodyScope, returnType);
|
||||
|
||||
FunctionBuilder<?> functionBuilder = new UserDefinedFunctionBuilder<>(returnType, parameterInfo, body, functionBodyScope);
|
||||
|
||||
scopeBuilder.registerFunction(identifier.lexeme(), functionBuilder);
|
||||
return Expression.NOOP;
|
||||
}
|
||||
|
||||
private List<Pair<String, Type>> getFunctionParameterDeclaration() {
|
||||
List<Pair<String, Type>> parameters = new ArrayList<>();
|
||||
while(lexer.current().type() != TokenType.CLOSE_PAREN) {
|
||||
// Parse parameter type
|
||||
Token typeToken = lexer.consume("Expected function parameter type declaration", TokenType.TYPE_BOOLEAN, TokenType.TYPE_STRING,
|
||||
TokenType.TYPE_NUMBER);
|
||||
Type type = ParserUtil.getVariableReturnType(typeToken);
|
||||
|
||||
// Parse parameter name
|
||||
Token identifierToken = lexer.consume("Expected function parameter identifier", TokenType.IDENTIFIER);
|
||||
String name = identifierToken.lexeme();
|
||||
|
||||
parameters.add(Pair.of(name, type));
|
||||
|
||||
// Consume separator if present, trailing separators are allowed
|
||||
if(lexer.current().isType(TokenType.SEPARATOR)) lexer.consumeUnchecked();
|
||||
}
|
||||
lexer.consume("Expected ')' after function parameter declaration", TokenType.CLOSE_PAREN);
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private Block parseBlock(Scope.ScopeBuilder scopeBuilder, Type blockReturnType) {
|
||||
List<Expression<?>> expressions = new ArrayList<>();
|
||||
scopeBuilder = scopeBuilder.innerScope(); // Create new inner scope for the block
|
||||
SourcePosition startPosition = lexer.current().position();
|
||||
|
||||
boolean hasReturn = false;
|
||||
|
||||
// Parse each statement
|
||||
while(lexer.hasNext() && !lexer.current().isType(TokenType.BLOCK_END)) {
|
||||
Expression<?> expression = parseStatement(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(blockReturnType != Type.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(Scope.ScopeBuilder scopeBuilder) {
|
||||
Token token = lexer.current();
|
||||
Expression<?> expression = switch(token.type()) {
|
||||
case FOR_LOOP -> parseForLoop(scopeBuilder);
|
||||
case IF_STATEMENT -> parseIfStatement(scopeBuilder);
|
||||
case WHILE_LOOP -> parseWhileLoop(scopeBuilder);
|
||||
case IDENTIFIER -> {
|
||||
if(scopeBuilder.containsVariable(token.lexeme())) yield parseAssignment(scopeBuilder); // Assume variable assignment
|
||||
else yield parseFunctionInvocation(lexer.consumeUnchecked(), scopeBuilder);
|
||||
}
|
||||
case TYPE_NUMBER, TYPE_STRING, TYPE_BOOLEAN, TYPE_VOID -> parseDeclaration(scopeBuilder);
|
||||
case RETURN -> parseReturn(scopeBuilder);
|
||||
case BREAK -> {
|
||||
if(!scopeBuilder.isInLoop()) throw new ParseException("Break statements can only be defined inside loops",
|
||||
token.position());
|
||||
yield new BreakKeyword(lexer.consumeUnchecked().position());
|
||||
}
|
||||
case CONTINUE -> {
|
||||
if(!scopeBuilder.isInLoop()) throw new ParseException("Continue statements can only be defined inside loops",
|
||||
token.position());
|
||||
yield new ContinueKeyword(lexer.consumeUnchecked().position());
|
||||
}
|
||||
case FAIL -> new FailKeyword(lexer.consumeUnchecked().position());
|
||||
case STATEMENT_END -> Expression.NOOP;
|
||||
default -> throw new ParseException("Unexpected token '" + token.lexeme() + "' while parsing statement", token.position());
|
||||
};
|
||||
if(!token.isControlStructure() && expression != Expression.NOOP) lexer.consume("Expected ';' at end of statement",
|
||||
TokenType.STATEMENT_END);
|
||||
return expression;
|
||||
}
|
||||
|
||||
private ReturnKeyword parseReturn(Scope.ScopeBuilder scopeBuilder) {
|
||||
Token returnToken = lexer.consume("Expected 'return' keyword at beginning of return statement", TokenType.RETURN);
|
||||
Expression<?> data = null;
|
||||
if(!lexer.current().isType(TokenType.STATEMENT_END)) {
|
||||
data = parseExpression(scopeBuilder);
|
||||
}
|
||||
return new ReturnKeyword(data, returnToken.position());
|
||||
}
|
||||
|
||||
private VariableAssignmentNode<?> parseAssignment(Scope.ScopeBuilder scopeBuilder) {
|
||||
Token identifier = lexer.consume("Expected identifier at beginning of assignment", TokenType.IDENTIFIER);
|
||||
|
||||
lexer.consume("Expected '=' after identifier for variable assignment", TokenType.ASSIGNMENT);
|
||||
|
||||
Expression<?> value = parseExpression(scopeBuilder);
|
||||
|
||||
String id = identifier.lexeme();
|
||||
|
||||
ParserUtil.ensureReturnType(value, scopeBuilder.getVaraibleType(id));
|
||||
|
||||
Type type = value.returnType();
|
||||
|
||||
return switch(type) {
|
||||
case NUMBER -> new NumAssignmentNode((Expression<Number>) value, identifier.position(), scopeBuilder.getIndex(id));
|
||||
case STRING -> new StrAssignmentNode((Expression<String>) value, identifier.position(), scopeBuilder.getIndex(id));
|
||||
case BOOLEAN -> new BoolAssignmentNode((Expression<Boolean>) value, identifier.position(), scopeBuilder.getIndex(id));
|
||||
default -> throw new ParseException("Illegal type for variable assignment: " + type, value.getPosition());
|
||||
};
|
||||
}
|
||||
|
||||
private Expression<?> parseFunctionInvocation(Token identifier, Scope.ScopeBuilder scopeBuilder) {
|
||||
if(!scopeBuilder.containsFunction(identifier.lexeme()))
|
||||
throw new ParseException("Function '" + identifier.lexeme() + "' is not defined in this scope", identifier.position());
|
||||
|
||||
FunctionBuilder<?> builder = scopeBuilder.getFunction(identifier.lexeme());
|
||||
|
||||
lexer.consume("Expected '(' after identifier " + identifier.lexeme(), TokenType.OPEN_PAREN); // Invocation starts with open paren
|
||||
|
||||
List<Expression<?>> args = new ArrayList<>();
|
||||
while(!lexer.current().isType(TokenType.CLOSE_PAREN)) {
|
||||
args.add(parseExpression(scopeBuilder));
|
||||
if(lexer.current().isType(TokenType.CLOSE_PAREN)) break;
|
||||
lexer.consume("Expected ',' between function parameters", TokenType.SEPARATOR);
|
||||
}
|
||||
lexer.consume("Expected ')' after function parameters", TokenType.CLOSE_PAREN);
|
||||
|
||||
if(ignoredFunctions.contains(identifier.lexeme())) {
|
||||
return Expression.NOOP;
|
||||
}
|
||||
|
||||
if(builder.argNumber() != -1 && args.size() != builder.argNumber())
|
||||
throw new ParseException("Expected " + builder.argNumber() + " parameters, found " + args.size(), identifier.position());
|
||||
|
||||
for(int i = 0; i < args.size(); i++) {
|
||||
Expression<?> argument = args.get(i);
|
||||
if(builder.getArgument(i) == null)
|
||||
throw new ParseException("Unexpected argument at position " + i + " in function " + identifier.lexeme(),
|
||||
identifier.position());
|
||||
ParserUtil.ensureReturnType(argument, builder.getArgument(i));
|
||||
}
|
||||
return builder.build(args, identifier.position());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Polyhedral Development
|
||||
*
|
||||
* The Terra Core Addons are licensed under the terms of the MIT License. For more details,
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Token;
|
||||
|
||||
|
||||
public class ParserUtil {
|
||||
|
||||
// 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());
|
||||
// }
|
||||
|
||||
public static void ensureReturnType(Expression<?> returnable, Type... types) {
|
||||
for(Type type : types) if(returnable.returnType().equals(type)) return;
|
||||
throw new ParseException("Invalid type " + returnable.returnType() + ", expected " +
|
||||
(types.length == 1 ? types[0].toString() : "one of " + Arrays.toString(types)), returnable.getPosition());
|
||||
}
|
||||
|
||||
public static Type getVariableReturnType(Token varToken) {
|
||||
return switch(varToken.type()) {
|
||||
case TYPE_NUMBER -> Type.NUMBER;
|
||||
case TYPE_STRING -> Type.STRING;
|
||||
case TYPE_BOOLEAN -> Type.BOOLEAN;
|
||||
case TYPE_VOID -> Type.VOID;
|
||||
default -> throw new ParseException("Unexpected token " + varToken.type() + "; expected type",
|
||||
varToken.position());
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.exceptions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.exceptions;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
@@ -5,27 +5,28 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block.EvaluationInfo;
|
||||
|
||||
|
||||
public class Block implements Expression<EvaluationInfo<?>> {
|
||||
private final List<Expression<?>> items;
|
||||
private final SourcePosition position;
|
||||
private final ReturnType returnType;
|
||||
private final Type returnType;
|
||||
|
||||
public Block(List<Expression<?>> items, SourcePosition position, ReturnType returnType) {
|
||||
public Block(List<Expression<?>> items, SourcePosition position, Type returnType) {
|
||||
this.items = items;
|
||||
this.position = position;
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
public Type returnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@@ -37,7 +38,7 @@ public class Block implements Expression<EvaluationInfo<?>> {
|
||||
if(!evalInfo.level().equals(EvaluationLevel.NONE)) return evalInfo;
|
||||
}
|
||||
}
|
||||
return new EvaluationInfo<>(EvaluationLevel.NONE, Expression.NOOP);
|
||||
return new EvaluationInfo<>(EvaluationLevel.NONE, NOOP);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope.ScopeBuilder;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang;
|
||||
|
||||
|
||||
public class Executable {
|
||||
private final Block script;
|
||||
private final ThreadLocal<Scope> scope;
|
||||
|
||||
public Executable(Block script, ScopeBuilder scopeBuilder) {
|
||||
public Executable(Block script, Scope.ScopeBuilder scopeBuilder) {
|
||||
this.script = script;
|
||||
this.scope = ThreadLocal.withInitial(scopeBuilder::build);
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public interface Expression<T> {
|
||||
Expression<Void> NOOP = new Expression<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,7 +29,7 @@ public interface Expression<T> {
|
||||
}
|
||||
};
|
||||
|
||||
ReturnType returnType();
|
||||
Type returnType();
|
||||
|
||||
T evaluate(ImplementationArguments implementationArguments, Scope scope);
|
||||
|
||||
@@ -43,21 +44,4 @@ public interface Expression<T> {
|
||||
SourcePosition getPosition();
|
||||
|
||||
|
||||
enum ReturnType {
|
||||
NUMBER(true),
|
||||
STRING(true),
|
||||
BOOLEAN(false),
|
||||
VOID(false),
|
||||
OBJECT(false);
|
||||
|
||||
private final boolean comparable;
|
||||
|
||||
ReturnType(boolean comparable) {
|
||||
this.comparable = comparable;
|
||||
}
|
||||
|
||||
public boolean isComparable() {
|
||||
return comparable;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang;
|
||||
|
||||
/**
|
||||
* Arguments passed to {@link Expression}s by the implementation
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang;
|
||||
|
||||
public interface Keyword<T> extends Expression<T> {
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang;
|
||||
|
||||
|
||||
import net.jafama.FastMath;
|
||||
@@ -6,9 +6,9 @@ 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.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Scope {
|
||||
public static final class ScopeBuilder {
|
||||
|
||||
private final Map<String, FunctionBuilder<? extends Function<?>>> functions;
|
||||
private final Map<String, Pair<Integer, ReturnType>> indices;
|
||||
private final Map<String, Pair<Integer, Type>> indices;
|
||||
private int numSize, boolSize, strSize = 0;
|
||||
private ScopeBuilder parent;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class Scope {
|
||||
|
||||
public int declareNum(String id) {
|
||||
int num = numSize;
|
||||
indices.put(check(id), Pair.of(num, ReturnType.NUMBER));
|
||||
indices.put(check(id), Pair.of(num, Type.NUMBER));
|
||||
numSize++;
|
||||
updateNumSize(numSize);
|
||||
return num;
|
||||
@@ -122,7 +122,7 @@ public class Scope {
|
||||
|
||||
public int declareStr(String id) {
|
||||
int str = strSize;
|
||||
indices.put(check(id), Pair.of(str, ReturnType.STRING));
|
||||
indices.put(check(id), Pair.of(str, Type.STRING));
|
||||
strSize++;
|
||||
updateStrSize(strSize);
|
||||
return str;
|
||||
@@ -130,7 +130,7 @@ public class Scope {
|
||||
|
||||
public int declareBool(String id) {
|
||||
int bool = boolSize;
|
||||
indices.put(check(id), Pair.of(bool, ReturnType.BOOLEAN));
|
||||
indices.put(check(id), Pair.of(bool, Type.BOOLEAN));
|
||||
boolSize++;
|
||||
updateBoolSize(boolSize);
|
||||
return bool;
|
||||
@@ -161,7 +161,7 @@ public class Scope {
|
||||
return indices.get(id).getLeft();
|
||||
}
|
||||
|
||||
public ReturnType getVaraibleType(String id) {
|
||||
public Type getVaraibleType(String id) {
|
||||
return indices.get(id).getRight();
|
||||
}
|
||||
|
||||
@@ -5,11 +5,12 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class BooleanConstant extends ConstantExpression<Boolean> {
|
||||
@@ -26,7 +27,7 @@ public class BooleanConstant extends ConstantExpression<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,12 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public abstract class ConstantExpression<T> implements Expression<T> {
|
||||
@@ -5,12 +5,12 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class NumericConstant extends ConstantExpression<Number> {
|
||||
@@ -27,7 +27,7 @@ public class NumericConstant extends ConstantExpression<Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.constants;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public class StringConstant extends ConstantExpression<String> {
|
||||
@@ -17,7 +17,7 @@ public class StringConstant extends ConstantExpression<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.STRING;
|
||||
public Type returnType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,11 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions;
|
||||
|
||||
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.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
|
||||
|
||||
public interface Function<T> extends Expression<T> {
|
||||
@@ -5,21 +5,22 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public interface FunctionBuilder<T extends Function<?>> {
|
||||
T build(List<Expression<?>> argumentList, SourcePosition position);
|
||||
|
||||
/**
|
||||
* @return Number of function arguments, -1 if the function uses a vararg at the end
|
||||
* @return Number of function parameters, -1 if the function uses a vararg at the end
|
||||
*/
|
||||
int argNumber();
|
||||
|
||||
Expression.ReturnType getArgument(int position);
|
||||
Type getArgument(int position);
|
||||
}
|
||||
@@ -1,26 +1,25 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
public class UserDefinedFunctionBuilder<T extends Function<?>> implements FunctionBuilder<T> {
|
||||
|
||||
private final ReturnType returnType;
|
||||
private final List<Pair<Integer, ReturnType>> parameterInfo;
|
||||
private final ScopeBuilder bodyScopeBuilder;
|
||||
private final Type returnType;
|
||||
private final List<Pair<Integer, Type>> parameterInfo;
|
||||
private final Scope.ScopeBuilder bodyScopeBuilder;
|
||||
private final Block body;
|
||||
|
||||
public UserDefinedFunctionBuilder(ReturnType returnType, List<Pair<Integer, ReturnType>> parameterInfo, Block body,
|
||||
ScopeBuilder functionBodyScope) {
|
||||
public UserDefinedFunctionBuilder(Type returnType, List<Pair<Integer, Type>> parameterInfo, Block body,
|
||||
Scope.ScopeBuilder functionBodyScope) {
|
||||
this.returnType = returnType;
|
||||
this.bodyScopeBuilder = functionBodyScope;
|
||||
this.body = body;
|
||||
@@ -35,21 +34,22 @@ public class UserDefinedFunctionBuilder<T extends Function<?>> implements Functi
|
||||
private final ThreadLocal<Scope> threadLocalScope = ThreadLocal.withInitial(bodyScopeBuilder::build);
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
public Type returnType() {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
Scope bodyScope = threadLocalScope.get();
|
||||
// Pass arguments into scope of function body
|
||||
// Pass parameters into scope of function body
|
||||
for(int i = 0; i < argumentList.size(); i++) {
|
||||
Pair<Integer, ReturnType> paramInfo = parameterInfo.get(i);
|
||||
Pair<Integer, Type> paramInfo = parameterInfo.get(i);
|
||||
Expression<?> argExpression = argumentList.get(i);
|
||||
switch(paramInfo.getRight()) {
|
||||
case NUMBER -> bodyScope.setNum(paramInfo.getLeft(), argExpression.applyDouble(implementationArguments, scope));
|
||||
case BOOLEAN -> bodyScope.setBool(paramInfo.getLeft(), argExpression.applyBoolean(implementationArguments, scope));
|
||||
case STRING -> bodyScope.setStr(paramInfo.getLeft(), (String) argExpression.evaluate(implementationArguments, scope));
|
||||
case STRING -> bodyScope.setStr(paramInfo.getLeft(),
|
||||
(String) argExpression.evaluate(implementationArguments, scope));
|
||||
}
|
||||
}
|
||||
return body.evaluate(implementationArguments, bodyScope).data().evaluate(implementationArguments, scope);
|
||||
@@ -68,7 +68,7 @@ public class UserDefinedFunctionBuilder<T extends Function<?>> implements Functi
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return parameterInfo.get(position).getRight();
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class BreakKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
@@ -33,7 +34,7 @@ public class BreakKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class ContinueKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
@@ -33,7 +34,7 @@ public class ContinueKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class FailKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
@@ -33,7 +34,7 @@ public class FailKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,18 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.flow;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.flow;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class ReturnKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
@@ -39,15 +40,15 @@ public class ReturnKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
|
||||
public ReturnType dataReturnType() {
|
||||
public Type dataReturnType() {
|
||||
if(data != null) {
|
||||
return data.returnType();
|
||||
} else {
|
||||
return ReturnType.VOID;
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,16 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.looplike;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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.Scope;
|
||||
|
||||
|
||||
public class ForKeyword implements Keyword<Block.EvaluationInfo<?>> {
|
||||
@@ -50,7 +51,7 @@ public class ForKeyword implements Keyword<Block.EvaluationInfo<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,20 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.looplike;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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.Scope;
|
||||
import com.dfsek.terra.api.util.generic.pair.Pair;
|
||||
|
||||
|
||||
@@ -57,7 +58,7 @@ public class IfKeyword implements Keyword<Block.EvaluationInfo<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.keywords.looplike;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.keywords.looplike;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationInfo;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Block.EvaluationLevel;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Keyword;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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.Scope;
|
||||
|
||||
|
||||
public class WhileKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
@@ -44,7 +45,7 @@ public class WhileKeyword implements Keyword<EvaluationInfo<?>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public abstract class BinaryOperation<I, O> implements Expression<O> {
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class BooleanAndOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
@@ -19,8 +20,8 @@ public class BooleanAndOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class BooleanNotOperation extends UnaryOperation<Boolean> {
|
||||
@@ -29,7 +30,7 @@ public class BooleanNotOperation extends UnaryOperation<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
@@ -29,7 +30,7 @@ public class BooleanOrOperation extends BinaryOperation<Boolean, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class ConcatenationOperation extends BinaryOperation<Object, Object> {
|
||||
@@ -30,8 +31,8 @@ public class ConcatenationOperation extends BinaryOperation<Object, Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.STRING;
|
||||
public Type returnType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class DivisionOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -19,8 +20,8 @@ public class DivisionOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class ModuloOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -29,7 +30,7 @@ public class ModuloOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class MultiplicationOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -29,7 +30,7 @@ public class MultiplicationOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class NegationOperation extends UnaryOperation<Number> {
|
||||
@@ -19,8 +20,8 @@ public class NegationOperation extends UnaryOperation<Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class NumberAdditionOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -29,7 +30,7 @@ public class NumberAdditionOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class SubtractionOperation extends BinaryOperation<Number, Number> {
|
||||
@@ -29,7 +30,7 @@ public class SubtractionOperation extends BinaryOperation<Number, Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public abstract class UnaryOperation<T> implements Expression<T> {
|
||||
@@ -5,15 +5,16 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BinaryOperation;
|
||||
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 static com.dfsek.terra.api.util.MathUtil.EPSILON;
|
||||
|
||||
@@ -26,8 +27,8 @@ public class EqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,13 +5,14 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BinaryOperation;
|
||||
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;
|
||||
|
||||
|
||||
public class GreaterOrEqualsThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
@@ -20,8 +21,8 @@ public class GreaterOrEqualsThanStatement extends BinaryOperation<Number, Boolea
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,13 +5,14 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BinaryOperation;
|
||||
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;
|
||||
|
||||
|
||||
public class GreaterThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
@@ -31,7 +32,7 @@ public class GreaterThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,14 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BinaryOperation;
|
||||
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;
|
||||
|
||||
|
||||
public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean> {
|
||||
@@ -31,7 +32,7 @@ public class LessThanOrEqualsStatement extends BinaryOperation<Number, Boolean>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,14 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BinaryOperation;
|
||||
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;
|
||||
|
||||
|
||||
public class LessThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
@@ -31,7 +32,7 @@ public class LessThanStatement extends BinaryOperation<Number, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,16 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.operations.statements;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.statements;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.operations.BinaryOperation;
|
||||
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 static com.dfsek.terra.api.util.MathUtil.EPSILON;
|
||||
|
||||
@@ -40,7 +41,7 @@ public class NotEqualsStatement extends BinaryOperation<Object, Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType returnType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public class BooleanVariable implements Variable<Boolean> {
|
||||
@@ -31,8 +31,8 @@ public class BooleanVariable implements Variable<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getType() {
|
||||
return Expression.ReturnType.BOOLEAN;
|
||||
public Type getType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public class NumberVariable implements Variable<Number> {
|
||||
@@ -31,8 +31,8 @@ public class NumberVariable implements Variable<Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getType() {
|
||||
return Expression.ReturnType.NUMBER;
|
||||
public Type getType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public class StringVariable implements Variable<String> {
|
||||
@@ -31,8 +31,8 @@ public class StringVariable implements Variable<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getType() {
|
||||
return Expression.ReturnType.STRING;
|
||||
public Type getType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public interface Variable<T> {
|
||||
@@ -16,7 +16,7 @@ public interface Variable<T> {
|
||||
|
||||
void setValue(T value);
|
||||
|
||||
Expression.ReturnType getType();
|
||||
Type getType();
|
||||
|
||||
SourcePosition getPosition();
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class BoolAssignmentNode extends VariableAssignmentNode<Boolean> {
|
||||
@@ -12,8 +13,8 @@ public class BoolAssignmentNode extends VariableAssignmentNode<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class NumAssignmentNode extends VariableAssignmentNode<Number> {
|
||||
@@ -12,8 +13,8 @@ public class NumAssignmentNode extends VariableAssignmentNode<Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class StrAssignmentNode extends VariableAssignmentNode<String> {
|
||||
@@ -12,8 +13,8 @@ public class StrAssignmentNode extends VariableAssignmentNode<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.STRING;
|
||||
public Type returnType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,10 +5,10 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.assign;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.assign;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public abstract class VariableAssignmentNode<T> implements Expression<T> {
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.reference;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class BoolVariableReferenceNode extends VariableReferenceNode<Boolean> {
|
||||
public BoolVariableReferenceNode(SourcePosition position, ReturnType type, int index) {
|
||||
public BoolVariableReferenceNode(SourcePosition position, Type type, int index) {
|
||||
super(position, type, index);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.reference;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
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;
|
||||
|
||||
|
||||
public class NumVariableReferenceNode extends VariableReferenceNode<Number> {
|
||||
public NumVariableReferenceNode(SourcePosition position, ReturnType type, int index) {
|
||||
public NumVariableReferenceNode(SourcePosition position, Type type, int index) {
|
||||
super(position, type, index);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
|
||||
|
||||
public class StrVariableReferenceNode extends VariableReferenceNode<String> {
|
||||
public StrVariableReferenceNode(SourcePosition position, Type type, int index) {
|
||||
super(position, type, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String evaluate(ImplementationArguments implementationArguments, Scope scope) {
|
||||
return scope.getStr(index);
|
||||
}
|
||||
}
|
||||
@@ -5,25 +5,26 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.parser.lang.variables.reference;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.parser.lang.variables.reference;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.SourcePosition;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Expression;
|
||||
|
||||
|
||||
public abstract class VariableReferenceNode<T> implements Expression<T> {
|
||||
protected final int index;
|
||||
private final SourcePosition position;
|
||||
private final ReturnType type;
|
||||
private final Type type;
|
||||
|
||||
public VariableReferenceNode(SourcePosition position, ReturnType type, int index) {
|
||||
public VariableReferenceNode(SourcePosition position, Type type, int index) {
|
||||
this.position = position;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
public Type returnType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Lexer;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@@ -19,28 +17,29 @@ import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
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;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.BlockFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.CheckBlockFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.EntityFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.GetMarkFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.LootFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.PullFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.RandomFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.RecursionsFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.SetMarkFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.StateFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.StructureFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.UnaryBooleanFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.UnaryNumberFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.UnaryStringFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.script.builders.ZeroArgFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.Parser;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Executable;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope.ScopeBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.BinaryNumberFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.BiomeFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.BlockFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.CheckBlockFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.EntityFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.GetMarkFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.LootFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.PullFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.RandomFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.RecursionsFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.SetMarkFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.StateFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.StructureFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.UnaryBooleanFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.UnaryNumberFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.UnaryStringFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.builders.ZeroArgFunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Lexer;
|
||||
import com.dfsek.terra.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.registry.key.Keyed;
|
||||
@@ -82,7 +81,6 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
|
||||
.registerFunction("block", new BlockFunctionBuilder(platform))
|
||||
.registerFunction("debugBlock", new BlockFunctionBuilder(platform))
|
||||
.registerFunction("structure", new StructureFunctionBuilder(structureRegistry, platform))
|
||||
.registerFunction("randomInt", new RandomFunctionBuilder())
|
||||
.registerFunction("recursions", new RecursionsFunctionBuilder())
|
||||
.registerFunction("setMark", new SetMarkFunctionBuilder())
|
||||
.registerFunction("getMark", new GetMarkFunctionBuilder())
|
||||
@@ -94,17 +92,20 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
|
||||
.registerFunction("state", new StateFunctionBuilder(platform))
|
||||
.registerFunction("setWaterlog", new UnaryBooleanFunctionBuilder((waterlog, args) -> args.setWaterlog(waterlog)))
|
||||
.registerFunction("originX", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getOrigin().getX(),
|
||||
Expression.ReturnType.NUMBER))
|
||||
Type.NUMBER))
|
||||
.registerFunction("originY", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getOrigin().getY(),
|
||||
Expression.ReturnType.NUMBER))
|
||||
Type.NUMBER))
|
||||
.registerFunction("originZ", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getOrigin().getZ(),
|
||||
Expression.ReturnType.NUMBER))
|
||||
Type.NUMBER))
|
||||
.registerFunction("rotation", new ZeroArgFunctionBuilder<>(arguments -> arguments.getRotation().toString(),
|
||||
Expression.ReturnType.STRING))
|
||||
Type.STRING))
|
||||
.registerFunction("rotationDegrees", new ZeroArgFunctionBuilder<>(arguments -> arguments.getRotation().getDegrees(),
|
||||
Expression.ReturnType.NUMBER))
|
||||
Type.NUMBER))
|
||||
|
||||
|
||||
.registerFunction("print",
|
||||
new UnaryStringFunctionBuilder(string -> LOGGER.info("[TerraScript:{}] {}", id, string)))
|
||||
.registerFunction("randomInt", new RandomFunctionBuilder())
|
||||
.registerFunction("abs", new UnaryNumberFunctionBuilder(number -> FastMath.abs(number.doubleValue())))
|
||||
.registerFunction("pow2", new UnaryNumberFunctionBuilder(number -> FastMath.pow2(number.doubleValue())))
|
||||
.registerFunction("pow", new BinaryNumberFunctionBuilder(
|
||||
@@ -5,13 +5,13 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
@@ -5,17 +5,18 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
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;
|
||||
|
||||
|
||||
public class BinaryNumberFunctionBuilder implements FunctionBuilder<Function<Number>> {
|
||||
@@ -30,8 +31,8 @@ public class BinaryNumberFunctionBuilder implements FunctionBuilder<Function<Num
|
||||
public Function<Number> build(List<Expression<?>> argumentList, SourcePosition position) {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -54,8 +55,8 @@ public class BinaryNumberFunctionBuilder implements FunctionBuilder<Function<Num
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
if(position == 0 || position == 1) return Expression.ReturnType.NUMBER;
|
||||
public Type getArgument(int position) {
|
||||
if(position == 0 || position == 1) return Type.NUMBER;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.BiomeFunction;
|
||||
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.api.Platform;
|
||||
|
||||
|
||||
@@ -36,9 +37,9 @@ public class BiomeFunctionBuilder implements FunctionBuilder<BiomeFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,17 +5,18 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.BooleanConstant;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.StringConstant;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.BlockFunction;
|
||||
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.api.Platform;
|
||||
|
||||
|
||||
@@ -48,11 +49,11 @@ public class BlockFunctionBuilder implements FunctionBuilder<BlockFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 3 -> Expression.ReturnType.STRING;
|
||||
case 4 -> Expression.ReturnType.BOOLEAN;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
case 3 -> Type.STRING;
|
||||
case 4 -> Type.BOOLEAN;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.CheckBlockFunction;
|
||||
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;
|
||||
|
||||
|
||||
public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunction> {
|
||||
@@ -29,9 +30,9 @@ public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunc
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.EntityFunction;
|
||||
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.api.Platform;
|
||||
|
||||
|
||||
@@ -36,10 +37,10 @@ public class EntityFunctionBuilder implements FunctionBuilder<EntityFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 3 -> Expression.ReturnType.STRING;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
case 3 -> Type.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.GetMarkFunction;
|
||||
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;
|
||||
|
||||
|
||||
public class GetMarkFunctionBuilder implements FunctionBuilder<GetMarkFunction> {
|
||||
@@ -33,9 +34,9 @@ public class GetMarkFunctionBuilder implements FunctionBuilder<GetMarkFunction>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,15 +5,16 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.LootFunction;
|
||||
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.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
@@ -44,10 +45,10 @@ public class LootFunctionBuilder implements FunctionBuilder<LootFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 3 -> Expression.ReturnType.STRING;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
case 3 -> Type.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.PullFunction;
|
||||
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.api.Platform;
|
||||
|
||||
|
||||
@@ -36,10 +37,10 @@ public class PullFunctionBuilder implements FunctionBuilder<PullFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 3 -> Expression.ReturnType.STRING;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
case 3 -> Type.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.RandomFunction;
|
||||
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;
|
||||
|
||||
|
||||
public class RandomFunctionBuilder implements FunctionBuilder<RandomFunction> {
|
||||
@@ -28,8 +29,8 @@ public class RandomFunctionBuilder implements FunctionBuilder<RandomFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
if(position == 0) return Expression.ReturnType.NUMBER;
|
||||
public Type getArgument(int position) {
|
||||
if(position == 0) return Type.NUMBER;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.RecursionsFunction;
|
||||
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;
|
||||
|
||||
|
||||
public class RecursionsFunctionBuilder implements FunctionBuilder<RecursionsFunction> {
|
||||
@@ -27,7 +28,7 @@ public class RecursionsFunctionBuilder implements FunctionBuilder<RecursionsFunc
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.SetMarkFunction;
|
||||
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;
|
||||
|
||||
|
||||
public class SetMarkFunctionBuilder implements FunctionBuilder<SetMarkFunction> {
|
||||
@@ -33,10 +34,10 @@ public class SetMarkFunctionBuilder implements FunctionBuilder<SetMarkFunction>
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 3 -> Expression.ReturnType.STRING;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
case 3 -> Type.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,15 +5,16 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.StateFunction;
|
||||
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.api.Platform;
|
||||
|
||||
|
||||
@@ -38,10 +39,10 @@ public class StateFunctionBuilder implements FunctionBuilder<StateFunction> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
case 3 -> Expression.ReturnType.STRING;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
case 3 -> Type.STRING;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.functions.StructureFunction;
|
||||
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.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -46,10 +47,10 @@ public class StructureFunctionBuilder implements FunctionBuilder<StructureFuncti
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
return switch(position) {
|
||||
case 0, 1, 2 -> Expression.ReturnType.NUMBER;
|
||||
default -> Expression.ReturnType.STRING;
|
||||
case 0, 1, 2 -> Type.NUMBER;
|
||||
default -> Type.STRING;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,19 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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;
|
||||
|
||||
|
||||
public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Void>> {
|
||||
@@ -31,8 +32,8 @@ public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Voi
|
||||
public Function<Void> build(List<Expression<?>> argumentList, SourcePosition position) {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -56,8 +57,8 @@ public class UnaryBooleanFunctionBuilder implements FunctionBuilder<Function<Voi
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
if(position == 0) return Expression.ReturnType.BOOLEAN;
|
||||
public Type getArgument(int position) {
|
||||
if(position == 0) return Type.BOOLEAN;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
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;
|
||||
|
||||
|
||||
public class UnaryNumberFunctionBuilder implements FunctionBuilder<Function<Number>> {
|
||||
@@ -29,8 +30,8 @@ public class UnaryNumberFunctionBuilder implements FunctionBuilder<Function<Numb
|
||||
public Function<Number> build(List<Expression<?>> argumentList, SourcePosition position) {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -52,8 +53,8 @@ public class UnaryNumberFunctionBuilder implements FunctionBuilder<Function<Numb
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
if(position == 0) return Expression.ReturnType.NUMBER;
|
||||
public Type getArgument(int position) {
|
||||
if(position == 0) return Type.NUMBER;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
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;
|
||||
|
||||
|
||||
public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void>> {
|
||||
@@ -29,8 +30,8 @@ public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void
|
||||
public Function<Void> build(List<Expression<?>> argumentList, SourcePosition position) {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -53,8 +54,8 @@ public class UnaryStringFunctionBuilder implements FunctionBuilder<Function<Void
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
if(position == 0) return Expression.ReturnType.STRING;
|
||||
public Type getArgument(int position) {
|
||||
if(position == 0) return Type.STRING;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,25 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.builders;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.builders;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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;
|
||||
|
||||
|
||||
public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
private final java.util.function.Function<TerraImplementationArguments, T> function;
|
||||
private final Expression.ReturnType type;
|
||||
private final Type type;
|
||||
|
||||
public ZeroArgFunctionBuilder(java.util.function.Function<TerraImplementationArguments, T> function, Expression.ReturnType type) {
|
||||
public ZeroArgFunctionBuilder(java.util.function.Function<TerraImplementationArguments, T> function, Type type) {
|
||||
this.function = function;
|
||||
this.type = type;
|
||||
}
|
||||
@@ -31,7 +32,7 @@ public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
public Function<T> build(List<Expression<?>> argumentList, SourcePosition position) {
|
||||
return new Function<>() {
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
public Type returnType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -53,7 +54,7 @@ public class ZeroArgFunctionBuilder<T> implements FunctionBuilder<Function<T>> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression.ReturnType getArgument(int position) {
|
||||
public Type getArgument(int position) {
|
||||
if(position == 0) return type;
|
||||
return null;
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
@@ -59,7 +60,7 @@ public class BiomeFunction implements Function<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.STRING;
|
||||
public Type returnType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
@@ -14,13 +14,14 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.StringConstant;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
@@ -62,8 +63,8 @@ public class BlockFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
|
||||
void setBlock(ImplementationArguments implementationArguments, Scope scope,
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
@@ -59,7 +60,7 @@ public class CheckBlockFunction implements Function<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.STRING;
|
||||
public Type returnType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.ConstantExpression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.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.api.Platform;
|
||||
import com.dfsek.terra.api.entity.Entity;
|
||||
import com.dfsek.terra.api.entity.EntityType;
|
||||
@@ -65,7 +66,7 @@ public class EntityFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
@@ -53,7 +54,7 @@ public class GetMarkFunction implements Function<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.STRING;
|
||||
public Type returnType() {
|
||||
return Type.STRING;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
@@ -13,13 +13,14 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.Platform;
|
||||
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.block.entity.Container;
|
||||
@@ -102,7 +103,7 @@ public class LootFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,19 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.constants.ConstantExpression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.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.api.Platform;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
@@ -65,7 +66,7 @@ public class PullFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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;
|
||||
|
||||
|
||||
public class RandomFunction implements Function<Integer> {
|
||||
@@ -26,8 +27,8 @@ public class RandomFunction implements Function<Integer> {
|
||||
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,13 +5,14 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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;
|
||||
|
||||
|
||||
public class RecursionsFunction implements Function<Number> {
|
||||
@@ -22,8 +23,8 @@ public class RecursionsFunction implements Function<Number> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.NUMBER;
|
||||
public Type returnType() {
|
||||
return Type.NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,16 +5,17 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
@@ -56,7 +57,7 @@ public class SetMarkFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,18 +5,19 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.block.entity.BlockEntity;
|
||||
import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
@@ -65,7 +66,7 @@ public class StateFunction implements Function<Void> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.VOID;
|
||||
public Type returnType() {
|
||||
return Type.VOID;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* reference the LICENSE file in this module's root directory.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
package com.dfsek.terra.addons.terrascript.legacy.script.functions;
|
||||
|
||||
import net.jafama.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
@@ -13,13 +13,14 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.Type;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Expression;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.Scope;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.lang.functions.Function;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.script.TerraImplementationArguments;
|
||||
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.api.Platform;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -50,8 +51,8 @@ public class StructureFunction implements Function<Boolean> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnType returnType() {
|
||||
return ReturnType.BOOLEAN;
|
||||
public Type returnType() {
|
||||
return Type.BOOLEAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -9,22 +9,23 @@ package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.exception.lexer.EOFException;
|
||||
import com.dfsek.terra.addons.terrascript.exception.lexer.FormatException;
|
||||
import com.dfsek.terra.addons.terrascript.exception.lexer.TokenizerException;
|
||||
import com.dfsek.terra.addons.terrascript.legacy.parser.exceptions.ParseException;
|
||||
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;
|
||||
|
||||
|
||||
public class Lexer {
|
||||
public static final Set<Character> syntaxSignificant = Sets.newHashSet(';', '(', ')', '"', ',', '\\', '=', '{', '}', '+', '-', '*', '/',
|
||||
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 Lexer(String data) {
|
||||
@@ -32,6 +33,15 @@ public class Lexer {
|
||||
current = tokenize();
|
||||
}
|
||||
|
||||
public List<Token> analyze() {
|
||||
List<Token> tokens = new ArrayList<>();
|
||||
while(hasNext()) {
|
||||
tokens.add(consumeUnchecked());
|
||||
}
|
||||
tokens.add(current()); // Add EOF token
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first token.
|
||||
*
|
||||
@@ -51,12 +61,13 @@ public class Lexer {
|
||||
* @throws ParseException If token does not exist
|
||||
*/
|
||||
public Token consume(String wrongTypeMessage, TokenType expected, TokenType... more) {
|
||||
if(!current.isType(expected) && Arrays.stream(more).noneMatch(t -> t == current.getType())) throw new ParseException(wrongTypeMessage, current.getPosition());
|
||||
if(!current.isType(expected) && Arrays.stream(more).noneMatch(t -> t == current.type())) throw new ParseException(wrongTypeMessage,
|
||||
current.position());
|
||||
return consumeUnchecked();
|
||||
}
|
||||
|
||||
public Token consumeUnchecked() {
|
||||
if(current.getType() == TokenType.END_OF_FILE) return current;
|
||||
if(current.type() == TokenType.END_OF_FILE) return current;
|
||||
Token temp = current;
|
||||
current = tokenize();
|
||||
return temp;
|
||||
@@ -68,7 +79,7 @@ public class Lexer {
|
||||
* @return {@code true} if more tokens are present, otherwise {@code false}
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return current.getType() != TokenType.END_OF_FILE;
|
||||
return current.type() != TokenType.END_OF_FILE;
|
||||
}
|
||||
|
||||
private Token tokenize() throws TokenizerException {
|
||||
@@ -82,10 +93,7 @@ public class Lexer {
|
||||
if(reader.matchesString("/*", true)) skipTo("*/");
|
||||
|
||||
// Reached end of file
|
||||
if(reader.current().isEOF()) {
|
||||
if(!bracketStack.isEmpty()) throw new ParseException("Dangling open brace", bracketStack.peek().getPosition());
|
||||
return new Token(reader.consume().toString(), TokenType.END_OF_FILE, position);
|
||||
}
|
||||
if(reader.current().isEOF()) return new Token(reader.consume().toString(), TokenType.END_OF_FILE, position);
|
||||
|
||||
// Check if operator token
|
||||
if(reader.matchesString("==", true))
|
||||
@@ -140,21 +148,15 @@ public class Lexer {
|
||||
return new Token(reader.consume().toString(), TokenType.OPEN_PAREN, position);
|
||||
if(reader.current().is(')'))
|
||||
return new Token(reader.consume().toString(), TokenType.CLOSE_PAREN, position);
|
||||
if(reader.current().is(':'))
|
||||
return new Token(reader.consume().toString(), TokenType.COLON, position);
|
||||
if(reader.current().is(';'))
|
||||
return new Token(reader.consume().toString(), TokenType.STATEMENT_END, position);
|
||||
if(reader.current().is(','))
|
||||
return new Token(reader.consume().toString(), TokenType.SEPARATOR, position);
|
||||
|
||||
if(reader.current().is('{')) {
|
||||
Token token = new Token(reader.consume().toString(), TokenType.BLOCK_BEGIN, position);
|
||||
bracketStack.push(token);
|
||||
return token;
|
||||
}
|
||||
if(reader.current().is('}')) {
|
||||
if(bracketStack.isEmpty()) throw new ParseException("Dangling close brace", position);
|
||||
bracketStack.pop();
|
||||
return new Token(reader.consume().toString(), TokenType.BLOCK_END, position);
|
||||
}
|
||||
if(reader.current().is('{')) return new Token(reader.consume().toString(), TokenType.BLOCK_BEGIN, position);
|
||||
if(reader.current().is('}')) return new Token(reader.consume().toString(), TokenType.BLOCK_END, position);
|
||||
|
||||
if(reader.current().is('='))
|
||||
return new Token(reader.consume().toString(), TokenType.ASSIGNMENT, position);
|
||||
@@ -197,6 +199,9 @@ public class Lexer {
|
||||
if(tokenString.equals("void"))
|
||||
return new Token(tokenString, TokenType.TYPE_VOID, position);
|
||||
|
||||
if(tokenString.equals("fun"))
|
||||
return new Token(tokenString, TokenType.FUNCTION, position);
|
||||
|
||||
if(tokenString.equals("if"))
|
||||
return new Token(tokenString, TokenType.IF_STATEMENT, position);
|
||||
if(tokenString.equals("else"))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
|
||||
|
||||
public class LookaheadStream {
|
||||
|
||||
private final String source;
|
||||
@@ -39,20 +38,21 @@ public class LookaheadStream {
|
||||
*/
|
||||
public Char peek() {
|
||||
int index = this.index + 1;
|
||||
if (index + 1 >= source.length()) return null;
|
||||
if(index + 1 >= source.length()) return null;
|
||||
return new Char(source.charAt(index), getPositionAfter(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the contained sequence of characters matches the string
|
||||
*
|
||||
* @param check Input string to check against
|
||||
* @param check Input string to check against
|
||||
* @param consumeIfMatched Whether to consume the string if there is a match
|
||||
*
|
||||
* @return If the string matches
|
||||
*/
|
||||
public boolean matchesString(String check, boolean consumeIfMatched) {
|
||||
boolean matches = check.equals(source.substring(index, Math.min(index + check.length(), source.length())));
|
||||
if (matches && consumeIfMatched) incrementIndex(check.length());
|
||||
if(matches && consumeIfMatched) incrementIndex(check.length());
|
||||
return matches;
|
||||
}
|
||||
|
||||
@@ -69,11 +69,11 @@ public class LookaheadStream {
|
||||
}
|
||||
|
||||
private SourcePosition getPositionAfter(int chars) {
|
||||
if (chars < 0) throw new IllegalArgumentException("Negative values are not allowed");
|
||||
if(chars < 0) throw new IllegalArgumentException("Negative values are not allowed");
|
||||
int line = position.line();
|
||||
int column = position.column();
|
||||
for (int i = index; i < Math.min(index + chars, source.length() - 1); i++) {
|
||||
if (source.charAt(i) == '\n') {
|
||||
for(int i = index; i < Math.min(index + chars, source.length() - 1); i++) {
|
||||
if(source.charAt(i) == '\n') {
|
||||
line++;
|
||||
column = 0;
|
||||
}
|
||||
|
||||
@@ -7,44 +7,65 @@
|
||||
|
||||
package com.dfsek.terra.addons.terrascript.lexer;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.BinaryOperator;
|
||||
import com.dfsek.terra.addons.terrascript.parser.UnaryOperator;
|
||||
|
||||
|
||||
public class Token {
|
||||
private final String content;
|
||||
private final String lexeme;
|
||||
private final TokenType type;
|
||||
private final SourcePosition start;
|
||||
|
||||
public Token(String content, TokenType type, SourcePosition start) {
|
||||
this.content = content;
|
||||
public Token(String lexeme, TokenType type, SourcePosition start) {
|
||||
this.lexeme = type == TokenType.END_OF_FILE ? "END OF FILE" : lexeme;
|
||||
this.type = type;
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type + ": '" + content + "'";
|
||||
public boolean equals(Object o) {
|
||||
if(this == o) return true;
|
||||
if(o == null || getClass() != o.getClass()) return false;
|
||||
Token token = (Token) o;
|
||||
return Objects.equals(lexeme, token.lexeme) && type == token.type && Objects.equals(start, token.start);
|
||||
}
|
||||
|
||||
public TokenType getType() {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(lexeme, type, start);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type + ": '" + lexeme + "'";
|
||||
}
|
||||
|
||||
public TokenType type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
public String lexeme() {
|
||||
return lexeme;
|
||||
}
|
||||
|
||||
public SourcePosition getPosition() {
|
||||
public SourcePosition position() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public boolean isConstant() {
|
||||
return this.type.equals(TokenType.NUMBER) || this.type.equals(TokenType.STRING) || this.type.equals(TokenType.BOOLEAN);
|
||||
}
|
||||
|
||||
public boolean isType(TokenType type) {
|
||||
return type == getType();
|
||||
}
|
||||
|
||||
public boolean isType(TokenType... types) {
|
||||
for (TokenType t : types) if (isType(t)) return true;
|
||||
for(TokenType t : types) if(t == type) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOperator(BinaryOperator... operators) {
|
||||
for(BinaryOperator o : operators) if(o.tokenType == type) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isOperator(UnaryOperator... operators) {
|
||||
for(UnaryOperator o : operators) if(o.tokenType == type) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -210,6 +231,11 @@ public class Token {
|
||||
* Void type declaration
|
||||
*/
|
||||
TYPE_VOID,
|
||||
/**
|
||||
* Function declaration
|
||||
*/
|
||||
FUNCTION,
|
||||
COLON,
|
||||
/**
|
||||
* If statement declaration
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user