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

0 commit comments

Comments
 (0)