Fixed negation bug.

This commit is contained in:
Marvin Blum
2015-10-25 14:03:04 +01:00
parent c3c4ca6f7d
commit d542562022
6 changed files with 30 additions and 30 deletions

View File

@@ -16,4 +16,4 @@
* exitWith...
* waitUntil...
* !buildInFunc()()...
* ~~!buildInFunc()()...~~

View File

@@ -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
}
}
}

View File

@@ -1,6 +1 @@
try {
var x = 100;
doSomething(x);
} catch {
errorHandling();
}
var x = !foo();

View File

@@ -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()

View File

@@ -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)

1
test/parser_negation.asl Normal file
View File

@@ -0,0 +1 @@
var x = !foo();