Commit 4a1a992e authored by EmreTr1's avatar EmreTr1
Browse files

use gradle kts, setup workflows & some improvements

parent 815e396d
name: Publish package
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
java-version: '16'
distribution: 'zulu'
- name: Publish package
run: gradle -Pversion=${{ github.event.release.tag_name }} build publish
env:
GITHUB_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
name: Java CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 16
uses: actions/setup-java@v2
with:
java-version: '16'
distribution: 'zulu'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
env:
GITHUB_USER: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
plugins {
id 'java'
id 'maven'
id 'maven-publish'
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
group 'com.bedrockk'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
test {
useJUnitPlatform()
maxHeapSize = '1G'
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/bedrockk/MoLang")
credentials {
username = "$GITHUB_PK_USER"
password = "$GITHUB_PK_TOKEN"
}
}
}
publications {
gpr(MavenPublication) {
from(components.java)
}
}
}
plugins {
java
`maven-publish`
}
java {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}
repositories {
mavenCentral()
}
dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.12.3")
implementation("com.bedrockk:molang:1.0-SNAPSHOT")
compileOnly("org.projectlombok:lombok:1.18.20")
annotationProcessor("org.projectlombok:lombok:1.18.20")
testImplementation("com.google.code.gson:gson:2.8.6")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
group = "com.bedrockk"
version = "1.0-SNAPSHOT"
tasks.named<Test>("test") {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
repositories {
maven {
name = "BedrockkPackages"
url = uri("https://maven.pkg.github.com/bedrockk/MoLang")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_USER")
password = project.findProperty("gpr.token") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
rootProject.name = 'molang'
rootProject.name = "molang"
package com.bedrockk.molang.parser; package com.bedrockk.molang;
import com.bedrockk.molang.parser.visitor.FindingVisitor; import com.bedrockk.molang.visitor.FindingVisitor;
import com.bedrockk.molang.parser.visitor.FirstFindingVisitor; import com.bedrockk.molang.visitor.FirstFindingVisitor;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
......
package com.bedrockk.molang.parser; package com.bedrockk.molang;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
...@@ -87,9 +87,7 @@ public class ExprTraverser { ...@@ -87,9 +87,7 @@ public class ExprTraverser {
field.setAccessible(true); field.setAccessible(true);
Object fieldValue = getFieldValue(field, expression); Object fieldValue = getFieldValue(field, expression);
if (fieldValue instanceof Expression) { if (fieldValue instanceof Expression subExpr) {
Expression subExpr = (Expression) fieldValue;
boolean removeCurrent = false; boolean removeCurrent = false;
boolean traverseChildren = true; boolean traverseChildren = true;
boolean traverseCurrent = true; boolean traverseCurrent = true;
......
package com.bedrockk.molang.parser; package com.bedrockk.molang;
import java.util.List; import java.util.List;
......
package com.bedrockk.molang.parser; package com.bedrockk.molang;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
......
...@@ -3,21 +3,34 @@ package com.bedrockk.molang; ...@@ -3,21 +3,34 @@ package com.bedrockk.molang;
import com.bedrockk.molang.parser.MoLangParser; import com.bedrockk.molang.parser.MoLangParser;
import com.bedrockk.molang.parser.tokenizer.TokenIterator; import com.bedrockk.molang.parser.tokenizer.TokenIterator;
import com.bedrockk.molang.runtime.MoLangRuntime; import com.bedrockk.molang.runtime.MoLangRuntime;
import com.bedrockk.molang.util.Util; import com.bedrockk.molang.utils.FileUtils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List;
public class MoLang { public class MoLang {
public static MoLangParser newParser(String code) { public static List<Expression> parse(String code) {
return (createParser(code)).parse();
}
public static List<Expression> parse(Path path) {
return (createParser(path)).parse();
}
public static List<Expression> parse(InputStream stream) throws IOException {
return (createParser(stream)).parse();
}
public static MoLangParser createParser(String code) {
return new MoLangParser(new TokenIterator(code)); return new MoLangParser(new TokenIterator(code));
} }
public static MoLangParser newParser(Path path) { public static MoLangParser createParser(Path path) {
byte[] fileBytes; byte[] fileBytes;
try { try {
fileBytes = Files.readAllBytes(path); fileBytes = Files.readAllBytes(path);
...@@ -28,11 +41,11 @@ public class MoLang { ...@@ -28,11 +41,11 @@ public class MoLang {
return new MoLangParser(new TokenIterator(new String(fileBytes, StandardCharsets.UTF_8))); return new MoLangParser(new TokenIterator(new String(fileBytes, StandardCharsets.UTF_8)));
} }
public static MoLangParser newParser(InputStream stream) throws IOException { public static MoLangParser createParser(InputStream stream) throws IOException {
return new MoLangParser(new TokenIterator(Util.readFile(stream))); return new MoLangParser(new TokenIterator(FileUtils.readFile(stream)));
} }
public static MoLangRuntime newRuntime() { public static MoLangRuntime createRuntime() {
return new MoLangRuntime(); return new MoLangRuntime();
} }
} }
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.MoValue; import com.bedrockk.molang.runtime.value.MoValue;
......
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue; import com.bedrockk.molang.runtime.value.DoubleValue;
...@@ -15,8 +15,8 @@ public class AssignExpression implements Expression { ...@@ -15,8 +15,8 @@ public class AssignExpression implements Expression {
@Override @Override
public MoValue evaluate(MoScope scope, MoLangEnvironment environment) { public MoValue evaluate(MoScope scope, MoLangEnvironment environment) {
variable.assign(scope, environment, expr.evaluate(scope, environment)); var value = expr.evaluate(scope, environment);
variable.assign(scope, environment, value);
return DoubleValue.ZERO; return value;
} }
} }
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
......
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue; import com.bedrockk.molang.runtime.value.DoubleValue;
......
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue; import com.bedrockk.molang.runtime.value.DoubleValue;
......
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue; import com.bedrockk.molang.runtime.value.DoubleValue;
......
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.value.DoubleValue; import com.bedrockk.molang.runtime.value.DoubleValue;
......
package com.bedrockk.molang.parser.expression; package com.bedrockk.molang.ast;
import com.bedrockk.molang.parser.Expression; import com.bedrockk.molang.Expression;
import com.bedrockk.molang.runtime.MoLangEnvironment; import com.bedrockk.molang.runtime.MoLangEnvironment;
import com.bedrockk.molang.runtime.MoScope; import com.bedrockk.molang.runtime.MoScope;
import com.bedrockk.molang.runtime.struct.ArrayStruct;
import com.bedrockk.molang.runtime.struct.MoStruct;
import com.bedrockk.molang.runtime.struct.VariableStruct; import com.bedrockk.molang.runtime.struct.VariableStruct;
import com.bedrockk.molang.runtime.value.DoubleValue; import com.bedrockk.molang.runtime.value.DoubleValue;
import com.bedrockk.molang.runtime.value.MoValue; import com.bedrockk.molang.runtime.value.MoValue;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment