mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Fixed negation bug.
This commit is contained in:
2
ToDo.md
2
ToDo.md
@@ -16,4 +16,4 @@
|
|||||||
|
|
||||||
* exitWith...
|
* exitWith...
|
||||||
* waitUntil...
|
* waitUntil...
|
||||||
* !buildInFunc()()...
|
* ~~!buildInFunc()()...~~
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1 @@
|
|||||||
try {
|
var x = !foo();
|
||||||
var x = 100;
|
|
||||||
doSomething(x);
|
|
||||||
} catch {
|
|
||||||
errorHandling();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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
1
test/parser_negation.asl
Normal file
@@ -0,0 +1 @@
|
|||||||
|
var x = !foo();
|
||||||
Reference in New Issue
Block a user