Skip to content

Commit 2247d8c

Browse files
committed
Fix regex literals.
1 parent cc3172e commit 2247d8c

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ private SkriptLangSpec() {
178178
new TernaryOtherwiseExpression(),
179179
new BinaryOtherwiseExpression(),
180180
new StringLiteral(),
181+
new RegexLiteral(),
181182
new SupplierSection(),
182183
new RunnableSection(),
183184
new ThreadExpression(),

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import mx.kenzie.foundation.MethodBuilder;
1010
import mx.kenzie.foundation.Type;
1111
import mx.kenzie.foundation.WriteInstruction;
12+
import org.byteskript.skript.api.note.ForceExtract;
1213
import org.byteskript.skript.api.syntax.Literal;
1314
import org.byteskript.skript.compiler.CommonTypes;
1415
import org.byteskript.skript.compiler.Context;
@@ -21,7 +22,7 @@
2122

2223
public class RegexLiteral extends Literal<java.util.regex.Pattern> {
2324

24-
private static final java.util.regex.Pattern PATTERN = java.util.regex.Pattern.compile("^\\/[^\\/\\\\\\r\\n]*(?:\\\\.[^\\/\\\\\\r\\n]*)*\\/\n");
25+
private static final java.util.regex.Pattern PATTERN = java.util.regex.Pattern.compile("^\\/[^\\/\\\\\\r\\n]*(?:\\\\.[^\\/\\\\\\r\\n]*)*\\/");
2526

2627
public RegexLiteral() {
2728
super(SkriptLangSpec.LIBRARY, StandardElements.EXPRESSION, "string literal");
@@ -45,8 +46,9 @@ public void compile(Context context, Pattern.Match match) throws Throwable {
4546
}
4647

4748
@Override
49+
@ForceExtract
4850
public java.util.regex.Pattern parse(String input) {
49-
return java.util.regex.Pattern.compile(input.substring(1, input.length() - 1));
51+
return java.util.regex.Pattern.compile(input);
5052
}
5153

5254
@Override

src/test/resources/generic.bsk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ function generic_expressions:
1313
assert {var} is "a": "Ternary otherwise (long form) failed."
1414
set {var} to (false ? "a" : "b")
1515
assert {var} is "b": "Ternary otherwise (short form) failed."
16+
assert ("hi" ? "bye") is "hi": "Binary otherwise (short form) failed."
17+
assert (null ? "bye") is "bye": "Binary otherwise (short form) failed."
18+
assert (null ? null) is null: "Binary otherwise (short form) failed."
1619
assert newline is a string: "New line is not a string."
20+
set {regex} to /hello there/
21+
assert {regex} exists: "Regex literal failed to load."
22+
set {regex} to /.+/
23+
assert {regex} exists: "Regex literal failed to load."
24+
1725

1826
function test_system:
1927
trigger:

0 commit comments

Comments
 (0)