mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Issue #11.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package asl
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
)
|
||||
|
||||
const TAB = " "
|
||||
@@ -217,19 +217,21 @@ func parseFunctionParameter() {
|
||||
if accept("{") {
|
||||
return
|
||||
}
|
||||
|
||||
i := int64(0)
|
||||
|
||||
appendOut("params [", false)
|
||||
|
||||
for !accept(")") {
|
||||
name := get().token
|
||||
next()
|
||||
appendOut(name+" = _this select "+strconv.FormatInt(i, 10)+";", true)
|
||||
i++
|
||||
appendOut("\""+name+"\"", false)
|
||||
|
||||
if !accept(")") {
|
||||
expect(",")
|
||||
appendOut(",", false)
|
||||
}
|
||||
}
|
||||
|
||||
appendOut("];", true)
|
||||
}
|
||||
|
||||
func parseReturn() {
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestParserSwitch(t *testing.T) {
|
||||
|
||||
func TestParserFunction(t *testing.T) {
|
||||
got := getCompiled(t, "test/tokenizer_func.asl")
|
||||
want := "TestFunction = {\r\nparam0 = _this select 0;\r\nparam1 = _this select 1;\r\nreturn true;\r\n};\r\n"
|
||||
want := "TestFunction = {\r\nparams [\"param0\",\"param1\"];\r\nreturn true;\r\n};\r\n"
|
||||
|
||||
equal(t, got, want)
|
||||
}
|
||||
@@ -85,7 +85,7 @@ func TestParserExpression2(t *testing.T) {
|
||||
|
||||
func TestParserFunctionCall(t *testing.T) {
|
||||
got := getCompiled(t, "test/parser_func_call.asl")
|
||||
want := "myFunc = {\r\na = _this select 0;\r\nb = _this select 1;\r\nreturn a>b;\r\n};\r\n[1+3/4, 2-(66*22)/3-((123))] call myFunc;\r\n"
|
||||
want := "myFunc = {\r\nparams [\"a\",\"b\"];\r\nreturn a>b;\r\n};\r\n[1+3/4, 2-(66*22)/3-((123))] call myFunc;\r\n"
|
||||
|
||||
equal(t, got, want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user