diff --git a/in/simple.asl b/in/simple.asl index aff052d..a2589de 100644 --- a/in/simple.asl +++ b/in/simple.asl @@ -1,3 +1,3 @@ -func myFunc(a, b) { +func myFunc(a = 1, b = "string") { // ... } diff --git a/src/asl/parser.go b/src/asl/parser.go index ae03fd9..6aab297 100644 --- a/src/asl/parser.go +++ b/src/asl/parser.go @@ -223,7 +223,15 @@ func parseFunctionParameter() { for !accept(")") { name := get().token next() - appendOut("\""+name+"\"", false) + + if accept("=") { + next() + value := get().token + next() + appendOut("[\""+name+"\","+value+"]", false) + } else { + appendOut("\""+name+"\"", false) + } if !accept(")") { expect(",") diff --git a/src/asl/parser_test.go b/src/asl/parser_test.go index 84913f3..5657977 100644 --- a/src/asl/parser_test.go +++ b/src/asl/parser_test.go @@ -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) diff --git a/test/parser_func_params.asl b/test/parser_func_params.asl new file mode 100644 index 0000000..352b44a --- /dev/null +++ b/test/parser_func_params.asl @@ -0,0 +1,3 @@ +func myFunc(a = 1, b = 2) { + return a+b; +}