diff --git a/README.md b/README.md index 377347f..c88a670 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,12 @@ var number = 123; var floatingPointNumber = 1.23; var string = "string"; var array = [1, 2, 3]; + +// accessing array elements: +var one = array[0]; + +// accessing using a statement: +var zwo = array[33/3-2]; ``` ### Control structures diff --git a/in/simple.asl b/in/simple.asl index e4e736e..794feaa 100644 --- a/in/simple.asl +++ b/in/simple.asl @@ -1,6 +1,6 @@ var array = [1, 2, 3]; var x = array[0]; -if array[1] == 2 { +if array[(1-1)+10/10] == 2 { foo(); } diff --git a/out/simple.sqf b/out/simple.sqf index 3798920..abcbe28 100644 --- a/out/simple.sqf +++ b/out/simple.sqf @@ -1,5 +1,5 @@ array = [1,2,3]; x = (array select 0); -if ((array select 1)==2) then { +if ((array select (1-1)+10/10)==2) then { [] call foo; }; diff --git a/src/asl/parser.go b/src/asl/parser.go index 541b184..e17bbf6 100644 --- a/src/asl/parser.go +++ b/src/asl/parser.go @@ -424,7 +424,7 @@ func parseIdentifier() string { output += "("+get().token next() expect("[") - output += " select "+parseExpression(false)+")" + output += " select ("+parseExpression(false)+"))" expect("]") } else if accept("!") || accept("-") { output = get().token diff --git a/src/asl/parser_test.go b/src/asl/parser_test.go index f115f6e..6c7e1c0 100644 --- a/src/asl/parser_test.go +++ b/src/asl/parser_test.go @@ -131,7 +131,7 @@ func TestParserWaitUntil(t *testing.T) { func TestParserArray(t *testing.T) { got := getCompiled(t, "test/parser_array.asl") - want := "x = [1,2,3];\ny = (x select 1);\n" + want := "x = [1,2,3];\ny = (x select (1));\n" equal(t, got, want) }