Skip to content

Commit f8aa5d0

Browse files
committed
Refactoring of relational expressions to support extra handlers by default.
1 parent a9317d6 commit f8aa5d0

File tree

17 files changed

+56
-4
lines changed

17 files changed

+56
-4
lines changed

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

Lines changed: 2 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.lang.handler.StandardHandlers;
1617

1718
import java.lang.reflect.Method;
1819
import java.lang.reflect.Modifier;
@@ -62,6 +63,7 @@ default CompileState getSubState() {
6263
}
6364

6465
default boolean allowAsInputFor(Type type) {
66+
if (CommonTypes.REFERENT.equals(type) && hasHandler(StandardHandlers.SET)) return true;
6567
return type.equals(CommonTypes.OBJECT) || type.equals(getReturnType());
6668
}
6769

src/main/java/org/byteskript/skript/api/syntax/RelationalExpression.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.byteskript.skript.compiler.CompileState;
1515
import org.byteskript.skript.compiler.Context;
1616
import org.byteskript.skript.compiler.Pattern;
17-
import org.byteskript.skript.lang.handler.StandardHandlers;
1817

1918
import java.lang.reflect.Method;
2019

@@ -28,12 +27,17 @@ public RelationalExpression(final Library provider, final LanguageElement type,
2827
public void compile(Context context, Pattern.Match match) throws Throwable {
2928
final MethodBuilder method = context.getMethod();
3029
assert method != null;
31-
final Method target = handlers.get(StandardHandlers.FIND);
32-
assert target != null;
30+
final Method target = handlers.get(context.getHandlerMode());
31+
assert target != null : "" + context.getHandlerMode();
3332
this.writeCall(method, target, context);
3433
context.setState(CompileState.STATEMENT);
3534
}
3635

36+
@Override
37+
public Pattern.Match match(String thing, Context context) {
38+
return super.match(thing, context);
39+
}
40+
3741
@Override
3842
public boolean allowedIn(State state, Context context) {
3943
return state == CompileState.STATEMENT && context.hasCurrentUnit();

src/main/java/org/byteskript/skript/lang/syntax/comparison/GT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public GT() {
2020
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object% (is greater than|>) ?%Object%");
2121
try {
2222
handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("gt", Object.class, Object.class));
23+
handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("gt", Object.class, Object.class));
2324
} catch (NoSuchMethodException e) {
2425
e.printStackTrace();
2526
}

src/main/java/org/byteskript/skript/lang/syntax/comparison/GTEQ.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public GTEQ() {
2020
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object% (is greater than or equal to|>=) ?%Object%");
2121
try {
2222
handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("gteq", Object.class, Object.class));
23+
handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("gteq", Object.class, Object.class));
2324
} catch (NoSuchMethodException e) {
2425
e.printStackTrace();
2526
}

src/main/java/org/byteskript/skript/lang/syntax/comparison/IsArray.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public IsArray() {
2424
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object% (is|are) a[n] array");
2525
try {
2626
handlers.put(StandardHandlers.FIND, this.getClass().getMethod("check", Object.class));
27+
handlers.put(StandardHandlers.GET, this.getClass().getMethod("check", Object.class));
2728
} catch (NoSuchMethodException e) {
2829
e.printStackTrace();
2930
}

src/main/java/org/byteskript/skript/lang/syntax/comparison/IsOfType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public IsOfType() {
2424
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object% (is|are) a[n] %Type%");
2525
try {
2626
handlers.put(StandardHandlers.FIND, this.getClass().getMethod("check", Object.class, Object.class));
27+
handlers.put(StandardHandlers.GET, this.getClass().getMethod("check", Object.class, Object.class));
2728
} catch (NoSuchMethodException e) {
2829
e.printStackTrace();
2930
}

src/main/java/org/byteskript/skript/lang/syntax/comparison/LT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public LT() {
2020
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object% (is less than|<) ?%Object%");
2121
try {
2222
handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("lt", Object.class, Object.class));
23+
handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("lt", Object.class, Object.class));
2324
} catch (NoSuchMethodException e) {
2425
e.printStackTrace();
2526
}

src/main/java/org/byteskript/skript/lang/syntax/comparison/LTEQ.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public LTEQ() {
2020
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object% (is less than or equal to|<=) ?%Object%");
2121
try {
2222
handlers.put(StandardHandlers.FIND, OperatorHandler.class.getMethod("lteq", Object.class, Object.class));
23+
handlers.put(StandardHandlers.GET, OperatorHandler.class.getMethod("lteq", Object.class, Object.class));
2324
} catch (NoSuchMethodException e) {
2425
e.printStackTrace();
2526
}

src/main/java/org/byteskript/skript/lang/syntax/list/IndexOfList.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public Pattern.Match match(String thing, Context context) {
3838
return super.match(thing, context);
3939
}
4040

41+
@Override
42+
public boolean allowAsInputFor(Type type) {
43+
return super.allowAsInputFor(type);
44+
}
45+
46+
@Override
47+
public Type getReturnType() {
48+
return CommonTypes.OBJECT;
49+
}
50+
4151
@Override
4252
public Type getHolderType() {
4353
return CommonTypes.LIST;

src/main/java/org/byteskript/skript/lang/syntax/map/KeyInMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class KeyInMap extends RelationalExpression implements Referent {
2424

2525
public KeyInMap() {
26-
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "[key ]%Object% in [map ]%Map%");
26+
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "%Object% in [map ]%Map%");
2727
try {
2828
handlers.put(StandardHandlers.GET, ExtractedSyntaxCalls.class.getMethod("getMapValue", Object.class, Object.class));
2929
handlers.put(StandardHandlers.SET, ExtractedSyntaxCalls.class.getMethod("setMapValue", Object.class, Object.class, Object.class));

0 commit comments

Comments
 (0)