Skip to content

Commit

Permalink
🚀 Making function param rules stricter for the better (#6361)
Browse files Browse the repository at this point in the history
* Making function param rules stricter for the better

* Add start of line check

* Allow non-English characters use in variable name param

* Add basic tests

---------

Co-authored-by: Moderocky <admin@moderocky.com>
  • Loading branch information
AyhamAl-Ali and Moderocky committed May 8, 2024
1 parent c19f1f7 commit cecf0b4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/lang/function/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

public final class Parameter<T> {

public final static Pattern PARAM_PATTERN = Pattern.compile("\\s*(.+?)\\s*:(?=[^:]*$)\\s*(.+?)(?:\\s*=\\s*(.+))?\\s*");
public final static Pattern PARAM_PATTERN = Pattern.compile("^\\s*([^:(){}\",]+?)\\s*:\\s*([a-zA-Z ]+?)\\s*(?:\\s*=\\s*(.+))?\\s*$");

/**
* Name of this parameter. Will be used as name for the local variable
Expand Down
46 changes: 46 additions & 0 deletions src/test/skript/tests/regressions/pull-6361-function-param.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# TODO add these to tests once structure test parsing is implemented (https://github.com/SkriptLang/Skript/pull/6291)
# function testA(loc): location, previoustype(): text):
# broadcast "a"

# function testB(loc(: location, previoustype): text):
# broadcast "b"

# function testE(loc: location, previoustyp): returns text: object = (")")):
# broadcast "%{_loc}% %{_previoustyp): returns text}%"

# function this((function should(not: exist) returns text:) ? object : text) :: text:
# return {_(function should(not: exist) returns text:) ? object }


# function never(gonna: give = (you - up)): and function never(gonna: let, you: down) :: text):
# broadcast {@magic}

# function testA3(previoustyp): returns text: object = (")")):
# broadcast 2


function test_English(test: text) :: text:
return {_test}

function test_Arabic(تجربة: text) :: text:
return {_تجربة}

function test_Japanese(テスト: text) :: text:
return {_テスト}

function test_Greek(δοκιμή: text) :: text:
return {_δοκιμή}

function test_Thai(ทดสอบ: text) :: text:
return {_ทดสอบ}

function test_German(prüfen: text) :: text:
return {_prüfen}

test "function parameter names":
assert test_English("text") = "text" with "Function 'test_English' failed function parameter name test"
assert test_Arabic("text") = "text" with "Function 'test_Arabic' failed function parameter name test"
assert test_Japanese("text") = "text" with "Function 'test_Japanese' failed function parameter name test"
assert test_Greek("text") = "text" with "Function 'test_Greek' failed function parameter name test"
assert test_Thai("text") = "text" with "Function 'test_Thai' failed function parameter name test"
assert test_German("text") = "text" with "Function 'test_German' failed function parameter name test"

0 comments on commit cecf0b4

Please sign in to comment.