From bf283cb87a495ec384dd5e51f16b4c3fe0666293 Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Sun, 25 Oct 2015 18:34:45 +0100 Subject: [PATCH] Issue #2. --- in/complex.asl | 42 ------------------------------------------ in/simple.asl | 10 ++++------ in/sub/empty.asl | 0 in/sub/sub.asl | 8 -------- in/sub/test.txt | 0 out/complex.sqf | 15 --------------- out/simple.sqf | 8 +++----- out/sub/empty.sqf | 0 out/sub/sub.sqf | 8 -------- src/asl/parser.go | 6 ++++++ src/asl/parser_test.go | 7 +++++++ test/parser_array.asl | 2 ++ 12 files changed, 22 insertions(+), 84 deletions(-) delete mode 100644 in/complex.asl delete mode 100644 in/sub/empty.asl delete mode 100644 in/sub/sub.asl delete mode 100644 in/sub/test.txt delete mode 100644 out/complex.sqf delete mode 100644 out/sub/empty.sqf delete mode 100644 out/sub/sub.sqf create mode 100644 test/parser_array.asl diff --git a/in/complex.asl b/in/complex.asl deleted file mode 100644 index 82373cf..0000000 --- a/in/complex.asl +++ /dev/null @@ -1,42 +0,0 @@ -/* -if (!isServer && player != player) then { // wait until player is on the server - waitUntil {player == player}; -}; - -_getunit = _this select 0; -_file = _this select 1; - -if (!isNil _getunit) then { // unit exists? - _unit = objNull; - call compile format ["_unit = %1", _getunit]; - - if (local _unit) then { // test if local (player character) - try { - [_unit] execVM _file; - } - catch { - // do nothing - } - } -}; -*/ - -if !isServer && player != player { - waituntil(player == player); -} - -var _getunit = select(_this)(0); -var _file = select(_this)(1); - -if !isNil()(_getunit) { - var _unit = objNull; - call()(compile()(format()("_unit = %1", _getunit))); - - if local()(_unit) { - try { - execVM(_unit)(_file); - } catch { - // do nothing - } - } -} diff --git a/in/simple.asl b/in/simple.asl index e69ad58..e4e736e 100644 --- a/in/simple.asl +++ b/in/simple.asl @@ -1,8 +1,6 @@ -waituntil(x = x+1; x < 100); +var array = [1, 2, 3]; +var x = array[0]; -if timeIsOver { - exitwith { - foo(); - bar(); - } +if array[1] == 2 { + foo(); } diff --git a/in/sub/empty.asl b/in/sub/empty.asl deleted file mode 100644 index e69de29..0000000 diff --git a/in/sub/sub.asl b/in/sub/sub.asl deleted file mode 100644 index 54faa44..0000000 --- a/in/sub/sub.asl +++ /dev/null @@ -1,8 +0,0 @@ -var x = 1; -var y = 3; - -func foo(x, y) { - return x+y -} - -hint()(format()("%1", foo(x, y))); diff --git a/in/sub/test.txt b/in/sub/test.txt deleted file mode 100644 index e69de29..0000000 diff --git a/out/complex.sqf b/out/complex.sqf deleted file mode 100644 index f4620fd..0000000 --- a/out/complex.sqf +++ /dev/null @@ -1,15 +0,0 @@ -if (!isServer&&player!=player) then { -waitUntil {player==player}; -}; -_getunit = (_this select 0); -_file = (_this select 1); -if (!(isNil _getunit)) then { -_unit = objNull; -call (compile (format ["_unit = %1", _getunit])); -if ((local _unit)) then { -try { -_unit execVM _file; -} catch { -}; -}; -}; diff --git a/out/simple.sqf b/out/simple.sqf index ca0c81d..3798920 100644 --- a/out/simple.sqf +++ b/out/simple.sqf @@ -1,7 +1,5 @@ -waitUntil {x=x+1;x<100}; -if (timeIsOver) then { -if (true) exitWith { +array = [1,2,3]; +x = (array select 0); +if ((array select 1)==2) then { [] call foo; -[] call bar; -}; }; diff --git a/out/sub/empty.sqf b/out/sub/empty.sqf deleted file mode 100644 index e69de29..0000000 diff --git a/out/sub/sub.sqf b/out/sub/sub.sqf deleted file mode 100644 index b770bba..0000000 --- a/out/sub/sub.sqf +++ /dev/null @@ -1,8 +0,0 @@ -x = 1; -y = 3; -foo = { -x = _this select 0; -y = _this select 1; -return x+y; -}; -hint (format ["%1", ([x, y] call foo)]); diff --git a/src/asl/parser.go b/src/asl/parser.go index a95246b..541b184 100644 --- a/src/asl/parser.go +++ b/src/asl/parser.go @@ -420,6 +420,12 @@ func parseIdentifier() string { name := get().token next() output = "(" + parseFunctionCall(false, name) + ")" + } else if seek("[") { + output += "("+get().token + next() + expect("[") + output += " select "+parseExpression(false)+")" + expect("]") } else if accept("!") || accept("-") { output = get().token next() diff --git a/src/asl/parser_test.go b/src/asl/parser_test.go index f6a8df4..f115f6e 100644 --- a/src/asl/parser_test.go +++ b/src/asl/parser_test.go @@ -129,6 +129,13 @@ func TestParserWaitUntil(t *testing.T) { equal(t, got, want) } +func TestParserArray(t *testing.T) { + got := getCompiled(t, "test/parser_array.asl") + want := "x = [1,2,3];\ny = (x select 1);\n" + + equal(t, got, want) +} + func getCompiled(t *testing.T, file string) string { code, err := ioutil.ReadFile(file) diff --git a/test/parser_array.asl b/test/parser_array.asl new file mode 100644 index 0000000..3c12a4b --- /dev/null +++ b/test/parser_array.asl @@ -0,0 +1,2 @@ +var x = [1, 2, 3]; +var y = x[1];