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... * exitWith...
* waitUntil... * waitUntil...
* !buildInFunc()()... * ~~!buildInFunc()()...~~

View File

@@ -33,7 +33,10 @@ if !(isNil()(_getunit)) {
call()(compile()(format()("_unit = %1", _getunit))); call()(compile()(format()("_unit = %1", _getunit)));
if local()(_unit) { if local()(_unit) {
// try...catch try {
execVM(_unit)(_file); execVM(_unit)(_file);
} catch {
// do nothing
}
} }
} }

View File

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

View File

@@ -36,7 +36,7 @@ func parseBlock() {
} else if accept("return") { } else if accept("return") {
parseReturn() parseReturn()
} else if accept("try") { } else if accept("try") {
parseTryCatch() parseTryCatch()
} else if accept("case") || accept("default") { } else if accept("case") || accept("default") {
return return
} else { } else {
@@ -235,17 +235,17 @@ func parseReturn() {
} }
func parseTryCatch() { func parseTryCatch() {
expect("try") expect("try")
expect("{") expect("{")
appendOut("try {", true) appendOut("try {", true)
parseBlock() parseBlock()
expect("}") expect("}")
expect("catch") expect("catch")
expect("{") expect("{")
appendOut("} catch {", true) appendOut("} catch {", true)
parseBlock() parseBlock()
expect("}") expect("}")
appendOut("};", true) appendOut("};", true)
} }
// Everything that does not start with a keyword. // Everything that does not start with a keyword.
@@ -361,9 +361,9 @@ func parseExpression(out bool) string {
output += "=" output += "="
next() next()
} else { } else {
next() next()
expect("=") expect("=")
output += "!=" output += "!="
} }
if accept("=") { if accept("=") {
@@ -391,13 +391,7 @@ func parseIdentifier() string {
} else if accept("!") || accept("-") { } else if accept("!") || accept("-") {
output = get().token output = get().token
next() next()
output += parseTerm()
if !accept("(") {
output += get().token
next()
} else {
output += parseTerm()
}
} else { } else {
output = get().token output = get().token
next() next()

View File

@@ -108,6 +108,13 @@ func TestParserTryCatch(t *testing.T) {
equal(t, got, want) 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 { func getCompiled(t *testing.T, file string) string {
code, err := ioutil.ReadFile(file) code, err := ioutil.ReadFile(file)

1
test/parser_negation.asl Normal file
View File

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