Skip to content

Commit c219f77

Browse files
committed
Update literals.
1 parent bed19ac commit c219f77

File tree

13 files changed

+51
-29
lines changed

13 files changed

+51
-29
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ public void setStoredVariableName(String storedVariableName) {
103103

104104
public abstract void createTree(ProgrammaticSplitTree tree);
105105

106-
public abstract <Tree extends ProgrammaticSplitTree> Tree findTree(Class<Tree> type);
107-
108106
public abstract void closeAllTrees();
109107

110108
public abstract void removeTree(ProgrammaticSplitTree tree);
@@ -154,6 +152,14 @@ public SectionMeta getSection(int index) {
154152
return sections.get(index);
155153
}
156154

155+
public SectionMeta getTriggerSection() {
156+
final TriggerTree tree = this.findTree(TriggerTree.class);
157+
if (tree == null) return null;
158+
return tree.owner();
159+
}
160+
161+
public abstract <Tree extends ProgrammaticSplitTree> Tree findTree(Class<Tree> type);
162+
157163
public Section getParent() {
158164
if (sections.isEmpty()) return null;
159165
return sections.get(0).handler();

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,22 @@ public void disableCompilation() {
108108
}
109109
}
110110

111+
public void disableChildren() {
112+
for (final ElementTree tree : nested) {
113+
tree.disableCompilation();
114+
}
115+
}
116+
117+
public <Type> Type getLiteralValue() {
118+
if (current instanceof Literal<?> literal) {
119+
final Object meta = match.meta();
120+
if (meta instanceof String string)
121+
return (Type) literal.parse(string);
122+
return (Type) meta;
123+
}
124+
return null;
125+
}
126+
111127
public SyntaxElement current() {
112128
return current;
113129
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,6 @@ public void createTree(ProgrammaticSplitTree tree) {
288288
this.trees.add(0, tree);
289289
}
290290

291-
@Override
292-
public <Tree extends ProgrammaticSplitTree> Tree findTree(Class<Tree> type) {
293-
for (final ProgrammaticSplitTree tree : this.trees) {
294-
if (type.isInstance(tree)) return (Tree) tree;
295-
}
296-
return null;
297-
}
298-
299291
@Override
300292
public synchronized void closeAllTrees() {
301293
for (final ProgrammaticSplitTree tree : trees.toArray(new ProgrammaticSplitTree[0])) {
@@ -404,6 +396,14 @@ public ProgrammaticSplitTree getCurrentTree() {
404396
return trees.isEmpty() ? null : trees.get(0);
405397
}
406398

399+
@Override
400+
public <Tree extends ProgrammaticSplitTree> Tree findTree(Class<Tree> type) {
401+
for (final ProgrammaticSplitTree tree : this.trees) {
402+
if (type.isInstance(tree)) return (Tree) tree;
403+
}
404+
return null;
405+
}
406+
407407
@Override
408408
public ProgrammaticSplitTree getTree(SectionMeta meta) {
409409
for (final ProgrammaticSplitTree tree : trees) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public java.util.regex.Pattern[] getCompiledPatterns() {
119119
}
120120

121121
public Match match(final String thing, final Context context) {
122-
return match(thing, context, null);
122+
return match(thing, context, thing);
123123
}
124124

125125
public Match match(final String thing, final Context context, final Object meta) {

src/main/java/org/byteskript/skript/lang/syntax/dictionary/ImportFunctionEffect.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.byteskript.skript.compiler.*;
1313
import org.byteskript.skript.compiler.structure.Function;
1414
import org.byteskript.skript.lang.element.StandardElements;
15+
import org.byteskript.skript.lang.syntax.literal.StringLiteral;
1516

1617
@Documentation(
1718
name = "Import Function",
@@ -50,7 +51,7 @@ public Pattern.Match match(String thing, Context context) {
5051
@Override
5152
public void compile(Context context, Pattern.Match match) throws Throwable {
5253
final ElementTree tree = context.getCompileCurrent();
53-
final String name = tree.nested()[0].match().meta();
54+
final String name = new StringLiteral().parse(tree.nested()[0].match().meta());
5455
final Type type = tree.nested()[1].match().meta();
5556
context.registerFunction(new Function(name, type));
5657
context.setState(CompileState.CODE_BODY);

src/main/java/org/byteskript/skript/lang/syntax/literal/DoubleLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Pattern.Match match(String thing, Context context) {
6868
final char c = thing.charAt(0);
6969
if (c != '-' && (c < LOW || c > HIGH)) return null;
7070
final Matcher matcher = PATTERN.matcher(thing);
71-
if (matcher.find()) return new Pattern.Match(matcher);
71+
if (matcher.find()) return new Pattern.Match(matcher, thing);
7272
return null;
7373
}
7474

src/main/java/org/byteskript/skript/lang/syntax/literal/FloatLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Pattern.Match match(String thing, Context context) {
6767
final char c = thing.charAt(0);
6868
if (c != '-' && (c < LOW || c > HIGH)) return null;
6969
final Matcher matcher = PATTERN.matcher(thing);
70-
if (matcher.find()) return new Pattern.Match(matcher);
70+
if (matcher.find()) return new Pattern.Match(matcher, thing);
7171
return null;
7272
}
7373

src/main/java/org/byteskript/skript/lang/syntax/literal/IntegerLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public Pattern.Match match(String thing, Context context) {
7171
final char c = thing.charAt(0);
7272
if (c != '-' && (c < LOW || c > HIGH)) return null;
7373
final Matcher matcher = PATTERN.matcher(thing);
74-
if (matcher.find()) return new Pattern.Match(matcher);
74+
if (matcher.find()) return new Pattern.Match(matcher, thing);
7575
return null;
7676
}
7777

src/main/java/org/byteskript/skript/lang/syntax/literal/LongLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public Pattern.Match match(String thing, Context context) {
6868
final char c = thing.charAt(0);
6969
if (c != '-' && (c < LOW || c > HIGH)) return null;
7070
final Matcher matcher = PATTERN.matcher(thing);
71-
if (matcher.find()) return new Pattern.Match(matcher);
71+
if (matcher.find()) return new Pattern.Match(matcher, thing);
7272
return null;
7373
}
7474

src/main/java/org/byteskript/skript/lang/syntax/literal/RegexLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Pattern.Match match(String thing, Context context) {
6565
if (thing.charAt(0) != '/') return null;
6666
if (thing.charAt(thing.length() - 1) != '/') return null;
6767
final Matcher matcher = PATTERN.matcher(thing);
68-
if (matcher.find()) return new Pattern.Match(matcher);
68+
if (matcher.find()) return new Pattern.Match(matcher, thing);
6969
return null;
7070
}
7171

src/main/java/org/byteskript/skript/lang/syntax/literal/StringLiteral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Pattern.Match match(String thing, Context context) {
8484
if (thing.charAt(thing.length() - 1) != '"') return null;
8585
final String contents = thing.substring(1, thing.length() - 1);
8686
if (!matches(contents)) return null;
87-
return new Pattern.Match(Pattern.fakeMatcher(thing), contents);
87+
return new Pattern.Match(Pattern.fakeMatcher(thing), thing);
8888
}
8989

9090
@Override

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,16 +323,6 @@ public <From, To> Converter<From, To> getConverter(Class<From> from, Class<To> t
323323
return null;
324324
}
325325

326-
public <From, To> void registerConverter(Class<From> from, Class<To> to, Converter<From, To> converter) {
327-
final Converter.Data data = new Converter.Data(from, to);
328-
this.converters.put(data, converter);
329-
}
330-
331-
public <From, To> void unregisterConverter(Class<From> from, Class<To> to) {
332-
final Converter.Data data = new Converter.Data(from, to);
333-
this.converters.remove(data);
334-
}
335-
336326
@Description("""
337327
Gets the parent class-loader attached to this Skript runtime.
338328
This is used to search available libraries and scripts for classes.
@@ -555,6 +545,11 @@ public boolean registerLibrary(Library library) {
555545
return compiler.addLibrary(library);
556546
}
557547

548+
public <From, To> void registerConverter(Class<From> from, Class<To> to, Converter<From, To> converter) {
549+
final Converter.Data data = new Converter.Data(from, to);
550+
this.converters.put(data, converter);
551+
}
552+
558553
@Description("""
559554
Removes a library instance from the current compiler.
560555
""")
@@ -567,6 +562,11 @@ public boolean unregisterLibrary(Library library) {
567562
return compiler.removeLibrary(library);
568563
}
569564

565+
public <From, To> void unregisterConverter(Class<From> from, Class<To> to) {
566+
final Converter.Data data = new Converter.Data(from, to);
567+
this.converters.remove(data);
568+
}
569+
570570
@Description("""
571571
Returns the provided script compiler.
572572
""")

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class SyntaxTest extends SkriptTest {
2929
= new Skript();
3030
// = new Skript(new DebugSkriptCompiler(Stream.controller(System.out)));
3131

32-
3332
@Test
3433
public void all() throws Throwable {
3534
final URI uri = SyntaxTest.class.getClassLoader().getResource("tests").toURI();

0 commit comments

Comments
 (0)