This commit is contained in:
Marvin Blum
2015-10-28 18:12:20 +01:00
parent 0b26c5bdf8
commit 352bfd6a9b
4 changed files with 20 additions and 2 deletions

View File

@@ -1,3 +1,3 @@
func myFunc(a, b) {
func myFunc(a = 1, b = "string") {
// ...
}

View File

@@ -223,7 +223,15 @@ func parseFunctionParameter() {
for !accept(")") {
name := get().token
next()
if accept("=") {
next()
value := get().token
next()
appendOut("[\""+name+"\","+value+"]", false)
} else {
appendOut("\""+name+"\"", false)
}
if !accept(")") {
expect(",")

View File

@@ -139,6 +139,13 @@ func TestParserArray(t *testing.T) {
equal(t, got, want)
}
func TestParserFunctionParams(t *testing.T) {
got := getCompiled(t, "test/parser_func_params.asl")
want := "myFunc = {\r\nparams [[\"a\",1],[\"b\",2]];\r\nreturn a+b;\r\n};\r\n"
equal(t, got, want)
}
func getCompiled(t *testing.T, file string) string {
code, err := ioutil.ReadFile(file)

View File

@@ -0,0 +1,3 @@
func myFunc(a = 1, b = 2) {
return a+b;
}