Skip to content

Commit 554dd28

Browse files
committed
Improve debug and external hooks.
1 parent 6f3e6ec commit 554dd28

File tree

9 files changed

+85
-9
lines changed

9 files changed

+85
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.byteskript</groupId>
88
<artifactId>byteskript</artifactId>
9-
<version>1.0.6</version>
9+
<version>1.0.7</version>
1010
<name>ByteSkript</name>
1111

1212
<properties>

src/main/java/org/byteskript/skript/api/SyntaxElement.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.byteskript.skript.api.note.ForceInline;
1414
import org.byteskript.skript.compiler.*;
1515
import org.byteskript.skript.compiler.structure.PreVariable;
16+
import org.byteskript.skript.error.ScriptReassemblyError;
1617
import org.byteskript.skript.lang.handler.StandardHandlers;
1718

1819
import java.lang.reflect.Method;
@@ -156,4 +157,15 @@ default Method findMethod(Class<?> owner, String name, Class<?>... parameters) {
156157
}
157158
}
158159

160+
/**
161+
* For script reassembly - taking the post-parse structure and generating a (new) text script from it.
162+
*
163+
* @param inputs the (probably-expression) inputs that go into this line
164+
* @return the string that would parse as this syntax, containing the inputs
165+
* @throws ScriptReassemblyError if you do not wish to support this / the inputs are wrong
166+
*/
167+
default String assemble(int line, String... inputs) throws ScriptReassemblyError {
168+
throw new ScriptReassemblyError(line, "Not supported yet.");
169+
}
170+
159171
}

src/main/java/org/byteskript/skript/compiler/SimpleSkriptCompiler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public class SimpleSkriptCompiler extends SkriptCompiler implements SkriptParser
3030
final List<Library> libraries = new ArrayList<>();
3131

3232
public SimpleSkriptCompiler(Library... libraries) {
33-
this.libraries.add(SkriptLangSpec.LIBRARY);
3433
this.libraries.addAll(List.of(libraries));
34+
this.libraries.add(SkriptLangSpec.LIBRARY); // skript goes last so addons can override
3535
}
3636

3737
@Override
@@ -147,7 +147,8 @@ List<String> removeComments(final String string) {
147147
@Override
148148
public boolean addLibrary(Library library) {
149149
if (libraries.contains(library)) return false;
150-
return libraries.add(library);
150+
libraries.add(0, library); // need to make sure it goes before skript
151+
return true;
151152
}
152153

153154
@Override
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2021 ByteSkript org (Moderocky)
3+
* View the full licence information and permissions:
4+
* https://github.com/Moderocky/ByteSkript/blob/master/LICENSE
5+
*/
6+
7+
package org.byteskript.skript.error;
8+
9+
public class ScriptReassemblyError extends Error implements ScriptError {
10+
11+
private final boolean fill = true;
12+
private final int line;
13+
14+
public int getLine() {
15+
return line;
16+
}
17+
18+
public ScriptReassemblyError(int line) {
19+
super();
20+
this.line = line;
21+
}
22+
23+
public ScriptReassemblyError(int line, String message) {
24+
super(message);
25+
this.line = line;
26+
}
27+
28+
public ScriptReassemblyError(int line, String message, Throwable cause) {
29+
super(message, cause);
30+
this.line = line;
31+
}
32+
33+
public ScriptReassemblyError(int line, Throwable cause) {
34+
super(cause);
35+
this.line = line;
36+
}
37+
38+
protected ScriptReassemblyError(int line, String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
39+
super(message, cause, enableSuppression, writableStackTrace);
40+
this.line = line;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
String s = getClass().getSimpleName();
46+
String message = getLocalizedMessage();
47+
return ((message != null) ? (s + ": " + message) : s) + " (Line " + line + ")";
48+
}
49+
50+
@Override
51+
public synchronized Throwable fillInStackTrace() {
52+
if (fill && System.getProperty("debug_mode") != null)
53+
return super.fillInStackTrace();
54+
return this;
55+
}
56+
}

src/main/java/org/byteskript/skript/lang/syntax/event/AnyLoadEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class AnyLoadEvent extends EventHolder {
1515

1616
public AnyLoadEvent() {
17-
super(SkriptLangSpec.LIBRARY, "on any [script ]load");
17+
super(SkriptLangSpec.LIBRARY, "on any [script] load");
1818
}
1919

2020
@Override

src/main/java/org/byteskript/skript/runtime/Skript.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ public ScheduledExecutorService getScheduler() {
404404
return scheduler;
405405
}
406406

407+
public static ExecutorService getExecutor() {
408+
return executor;
409+
}
410+
407411
public Future<?> schedule(Runnable runnable, long millis) {
408412
return scheduler.schedule(runnable, millis, TimeUnit.MILLISECONDS);
409413
}

src/main/java/org/byteskript/skript/runtime/internal/InvokingScriptRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public record InvokingScriptRunner(Class<? extends CompiledScript> owner, Member
1313

1414
@Override
1515
public void start() {
16-
method.invoke(null, parameters);
16+
method.invoke(parameters);
1717
}
1818
}

src/main/java/org/byteskript/skript/runtime/threading/ScriptExceptionHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@
77
package org.byteskript.skript.runtime.threading;
88

99
import org.byteskript.skript.error.ScriptError;
10-
11-
import java.util.Arrays;
10+
import org.byteskript.skript.error.ScriptParseError;
1211

1312
public class ScriptExceptionHandler implements Thread.UncaughtExceptionHandler, ScriptError {
1413

1514
@Override
1615
public void uncaughtException(Thread source, Throwable throwable) {
1716
if (throwable instanceof ThreadDeath) return;
18-
if (source instanceof ScriptThread thread) {
17+
if (System.getProperty("debug_mode") != null)
18+
throwable.printStackTrace();
19+
if (throwable instanceof ScriptParseError error) {
20+
error.printStackTrace(System.err);
21+
} else if (source instanceof ScriptThread thread) {
1922
final Class<?> start = thread.initiator;
2023
System.err.println("An error occurred while running a script.");
2124
System.err.println("\t" + throwable.getMessage());

src/test/java/org/byteskript/skript/test/SyntaxCreationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function test_eff (name):
133133
trigger:
134134
assert true
135135
hello "hi"
136-
136+
137137
""";
138138
final Skript skript = new Skript();
139139
final PostCompileClass syntax = skript.compileScript(first, "skript.test_blob");

0 commit comments

Comments
 (0)