diff --git a/ToDo.md b/ToDo.md index a8e5844..6a1df76 100644 --- a/ToDo.md +++ b/ToDo.md @@ -1,7 +1,6 @@ # ToDo * ~~assign to returned values~~ -* special cases (like if ... exitWith, waitUntil {...}) * ~~sqf: ... sqf whitespace~~ * ~~solution for build in commands which do not require left values~~ * ~~pretty/minified printing~~ @@ -11,3 +10,10 @@ * ~~inline buildin function call -> foo(a)(bar(x)(y));~~ * ~~negative values e.g. -1, operator !~~ * ~~tokenizer splits commands like "format" -> for, mat~~ +* try ... catch + +## Special cases + +* exitWith... +* waitUntil... +* !buildInFunc()()... diff --git a/in/complex.asl b/in/complex.asl index 2fe4670..9203afc 100644 --- a/in/complex.asl +++ b/in/complex.asl @@ -1,2 +1,39 @@ -//diag_log format ["easyHC: found headless client with ID %1.", easyHCpresent]; -diag_log () (format(xy)("asdf", "hjkl")); +/* +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 { + exit()(); // does not work for SQF, need to implement exitWith... +} + +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...catch + execVM(_unit)(_file); + } +} diff --git a/src/asl/parser.go b/src/asl/parser.go index 21a1b0b..4d5bb0a 100644 --- a/src/asl/parser.go +++ b/src/asl/parser.go @@ -326,7 +326,7 @@ func parseParameter(out bool) (string, int) { func parseExpression(out bool) string { output := parseArith() - for accept("<") || accept(">") || accept("&") || accept("|") || accept("=") { + for accept("<") || accept(">") || accept("&") || accept("|") || accept("=") || accept("!") { if accept("<") { output += "<" next() @@ -341,9 +341,13 @@ func parseExpression(out bool) string { next() expect("|") output += "||" - } else { + } else if accept("=") { output += "=" next() + } else { + next() + expect("=") + output += "!=" } if accept("=") { diff --git a/src/asl/parser_test.go b/src/asl/parser_test.go index af1e3e4..218cc35 100644 --- a/src/asl/parser_test.go +++ b/src/asl/parser_test.go @@ -94,6 +94,13 @@ func TestParserBuildinFunctionCall(t *testing.T) { equal(t, got, want) } +func TestParserOperator(t *testing.T) { + got := getCompiled(t, "test/parser_operator.asl") + want := "if (x==y&&x!=y&&x<=y&&x>=y&&xy) then {\n};\n" + + equal(t, got, want) +} + func getCompiled(t *testing.T, file string) string { code, err := ioutil.ReadFile(file) diff --git a/test/parser_operator.asl b/test/parser_operator.asl new file mode 100644 index 0000000..7d1482e --- /dev/null +++ b/test/parser_operator.asl @@ -0,0 +1,3 @@ +if x == y && x != y && x <= y && x >= y && x < y && x > y { + // ... +}