-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
198 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/org/byteskript/skript/app/ScriptDebugger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2022 ByteSkript org (Moderocky) | ||
* View the full licence information and permissions: | ||
* https://github.com/Moderocky/ByteSkript/blob/master/LICENSE | ||
*/ | ||
|
||
package org.byteskript.skript.app; | ||
|
||
import mx.kenzie.jupiter.stream.Stream; | ||
import org.byteskript.skript.compiler.DebugSkriptCompiler; | ||
import org.byteskript.skript.runtime.Skript; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
public class ScriptDebugger extends SkriptApp { | ||
|
||
public static void main(String... args) throws IOException { | ||
final File file = new File(ROOT, "debug.txt"); | ||
try (final FileOutputStream stream = new FileOutputStream(file)) { | ||
final Skript skript = new Skript(new DebugSkriptCompiler(Stream.controller(stream))); | ||
registerLibraries(skript); | ||
skript.compileScripts(SOURCE); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/org/byteskript/skript/compiler/DebugSkriptCompiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2022 ByteSkript org (Moderocky) | ||
* View the full licence information and permissions: | ||
* https://github.com/Moderocky/ByteSkript/blob/master/LICENSE | ||
*/ | ||
|
||
package org.byteskript.skript.compiler; | ||
|
||
import mx.kenzie.foundation.Type; | ||
import mx.kenzie.foundation.language.PostCompileClass; | ||
import mx.kenzie.jupiter.stream.OutputStreamController; | ||
import org.byteskript.skript.api.Library; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.function.Consumer; | ||
|
||
public class DebugSkriptCompiler extends SimpleSkriptCompiler { | ||
final OutputStreamController controller; | ||
|
||
public DebugSkriptCompiler(OutputStreamController controller, Library... libraries) { | ||
super(libraries); | ||
this.controller = controller; | ||
} | ||
|
||
@Override | ||
protected void compileLine(String line, FileContext context) { | ||
final ElementTree tree = this.parseLine(line, context); | ||
if (tree == null) return; | ||
this.debug(tree, context); | ||
tree.preCompile(context); | ||
tree.compile(context); | ||
for (final Consumer<Context> consumer : context.endOfLine) consumer.accept(context); | ||
context.endOfLine.clear(); | ||
context.currentEffect = null; | ||
context.sectionHeader = false; | ||
} | ||
|
||
@Override | ||
public PostCompileClass[] compile(InputStream stream, Type path) { | ||
try { | ||
this.controller.write("\n\n"); | ||
this.controller.write("--" + path.internalName()); | ||
this.controller.write("\n"); | ||
} catch (IOException ignored) {} | ||
return super.compile(stream, path); | ||
} | ||
|
||
@Override | ||
public PostCompileClass[] compile(String source, Type path) { | ||
try { | ||
this.controller.write("\n\n"); | ||
this.controller.write("--" + path.internalName()); | ||
this.controller.write("\n"); | ||
} catch (IOException ignored) {} | ||
return super.compile(source, path); | ||
} | ||
|
||
protected void debug(ElementTree tree, FileContext context) { | ||
try { | ||
this.controller.write("\n"); | ||
for (int i = 0; i < context.lineIndent; i++) { | ||
this.controller.write("\t"); | ||
} | ||
this.controller.write(tree.toString()); | ||
this.controller.write(";"); | ||
} catch (IOException ignored) {} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.