From d542562022758276852e6724cbf866f7a7816d17 Mon Sep 17 00:00:00 2001 From: Marvin Blum Date: Sun, 25 Oct 2015 14:03:04 +0100 Subject: [PATCH] Fixed negation bug. --- ToDo.md | 2 +- in/complex.asl | 5 ++++- in/simple.asl | 7 +------ src/asl/parser.go | 38 ++++++++++++++++---------------------- src/asl/parser_test.go | 7 +++++++ test/parser_negation.asl | 1 + 6 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 test/parser_negation.asl diff --git a/ToDo.md b/ToDo.md index 97a12fc..ab4d1f9 100644 --- a/ToDo.md +++ b/ToDo.md @@ -16,4 +16,4 @@ * exitWith... * waitUntil... -* !buildInFunc()()... +* ~~!buildInFunc()()...~~ diff --git a/in/complex.asl b/in/complex.asl index 9203afc..5c0eb52 100644 --- a/in/complex.asl +++ b/in/complex.asl @@ -33,7 +33,10 @@ if !(isNil()(_getunit)) { call()(compile()(format()("_unit = %1", _getunit))); if local()(_unit) { - // try...catch + try { execVM(_unit)(_file); + } catch { + // do nothing + } } } diff --git a/in/simple.asl b/in/simple.asl index f11ba71..cac616b 100644 --- a/in/simple.asl +++ b/in/simple.asl @@ -1,6 +1 @@ -try { - var x = 100; - doSomething(x); -} catch { - errorHandling(); -} +var x = !foo(); diff --git a/src/asl/parser.go b/src/asl/parser.go index b85cc7b..e50bb25 100644 --- a/src/asl/parser.go +++ b/src/asl/parser.go @@ -36,7 +36,7 @@ func parseBlock() { } else if accept("return") { parseReturn() } else if accept("try") { - parseTryCatch() + parseTryCatch() } else if accept("case") || accept("default") { return } else { @@ -235,17 +235,17 @@ func parseReturn() { } func parseTryCatch() { - expect("try") - expect("{") - appendOut("try {", true) - parseBlock() - expect("}") - expect("catch") - expect("{") - appendOut("} catch {", true) - parseBlock() - expect("}") - appendOut("};", true) + expect("try") + expect("{") + appendOut("try {", true) + parseBlock() + expect("}") + expect("catch") + expect("{") + appendOut("} catch {", true) + parseBlock() + expect("}") + appendOut("};", true) } // Everything that does not start with a keyword. @@ -361,9 +361,9 @@ func parseExpression(out bool) string { output += "=" next() } else { - next() - expect("=") - output += "!=" + next() + expect("=") + output += "!=" } if accept("=") { @@ -391,13 +391,7 @@ func parseIdentifier() string { } else if accept("!") || accept("-") { output = get().token next() - - if !accept("(") { - output += get().token - next() - } else { - output += parseTerm() - } + output += parseTerm() } else { output = get().token next() diff --git a/src/asl/parser_test.go b/src/asl/parser_test.go index 80b3c76..9bb246b 100644 --- a/src/asl/parser_test.go +++ b/src/asl/parser_test.go @@ -108,6 +108,13 @@ func TestParserTryCatch(t *testing.T) { equal(t, got, want) } +func TestParserNegationFunctionCall(t *testing.T) { + got := getCompiled(t, "test/parser_negation.asl") + want := "x = !([] call foo);\n" + + equal(t, got, want) +} + func getCompiled(t *testing.T, file string) string { code, err := ioutil.ReadFile(file) diff --git a/test/parser_negation.asl b/test/parser_negation.asl new file mode 100644 index 0000000..cac616b --- /dev/null +++ b/test/parser_negation.asl @@ -0,0 +1 @@ +var x = !foo();