mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Issue #9.
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
func myFunc(a, b) {
|
func myFunc(a = 1, b = "string") {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,15 @@ func parseFunctionParameter() {
|
|||||||
for !accept(")") {
|
for !accept(")") {
|
||||||
name := get().token
|
name := get().token
|
||||||
next()
|
next()
|
||||||
appendOut("\""+name+"\"", false)
|
|
||||||
|
if accept("=") {
|
||||||
|
next()
|
||||||
|
value := get().token
|
||||||
|
next()
|
||||||
|
appendOut("[\""+name+"\","+value+"]", false)
|
||||||
|
} else {
|
||||||
|
appendOut("\""+name+"\"", false)
|
||||||
|
}
|
||||||
|
|
||||||
if !accept(")") {
|
if !accept(")") {
|
||||||
expect(",")
|
expect(",")
|
||||||
|
|||||||
@@ -139,6 +139,13 @@ func TestParserArray(t *testing.T) {
|
|||||||
equal(t, got, want)
|
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 {
|
func getCompiled(t *testing.T, file string) string {
|
||||||
code, err := ioutil.ReadFile(file)
|
code, err := ioutil.ReadFile(file)
|
||||||
|
|
||||||
|
|||||||
3
test/parser_func_params.asl
Normal file
3
test/parser_func_params.asl
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
func myFunc(a = 1, b = 2) {
|
||||||
|
return a+b;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user