diff --git a/ToDo.md b/ToDo.md
index a8cabc7..4c106f7 100644
--- a/ToDo.md
+++ b/ToDo.md
@@ -1,10 +1,10 @@
# ToDo
-* assign to returned values
+* ~~assign to returned values~~
* special cases (like if ... exitWith)
* sqf: ... sqf whitespace
* solution for build in commands which do not require left values
* ~~pretty/minified printing~~
-* usage
+* ~~usage~~
* recursive compiling
* concurrent compiling
diff --git a/in/simple.asl b/in/simple.asl
index 27c2872..64411ab 100644
--- a/in/simple.asl
+++ b/in/simple.asl
@@ -1,8 +1,7 @@
-/*switch somevar {
- case 1:
- x = 1;
- case 2:
- x = 2;
-}*/
+func myFunc(a, b) {
+ return a > b;
+}
-var array = [1, 2, 3];
+myFunc(1+3/4, 2-(66*22)/3-((123)));
+
+foo();
diff --git a/src/asl/parser.go b/src/asl/parser.go
index f540efa..81ff07f 100644
--- a/src/asl/parser.go
+++ b/src/asl/parser.go
@@ -2,7 +2,6 @@ package asl
import (
"strconv"
- "fmt" // TODO: remove
)
const TAB = " "
@@ -10,8 +9,6 @@ const TAB = " "
// Parses tokens, validates code to a specific degree
// and writes SQF code into desired location.
func Parse(token []Token, prettyPrinting bool) string {
- fmt.Print("")
-
initParser(token, prettyPrinting)
for tokenIndex < len(token) {
@@ -40,6 +37,8 @@ func parseBlock() {
parseReturn()
} else if accept("sqf") {
parseSqf()
+ } else if accept("case") || accept("default") {
+ return
} else {
parseStatement()
}
@@ -129,7 +128,6 @@ func parseSwitch() {
appendOut("};", true)
}
-// FIXME
func parseSwitchBlock() {
if accept("}") {
return
@@ -142,7 +140,7 @@ func parseSwitchBlock() {
expect(":")
appendOut(":", true)
- if !accept("case") && !accept("}") {
+ if !accept("case") && !accept("}") && !accept("default") {
appendOut("{", true)
parseBlock()
appendOut("};", true)
@@ -289,13 +287,13 @@ func parseFunctionCall(out bool) string {
output := "["
expect("(")
- //output += parseParameter()
+ output += parseParameter(false)
expect(")")
- //expect(";")
+ expect(";")
output += "] call "
if out {
- appendOut(output, true)
+ appendOut(output, false)
}
return output
@@ -305,26 +303,34 @@ func parseBuildinFunctionCall(name string) {
// FIXME: does not work for all kind of commands
expect("(")
appendOut("[", false)
- parseParameter()
+ parseParameter(true)
expect(")")
appendOut("] ", false)
expect("(")
appendOut(name + " [", false)
- parseParameter()
+ parseParameter(true)
expect(")")
expect(";")
appendOut("];", true)
}
-func parseParameter() {
+func parseParameter(out bool) string {
+ output := ""
+
for !accept(")") {
- parseExpression(true)
+ output += parseExpression(out)
if !accept(")") {
expect(",")
- appendOut(", ", false)
+ output += ", "
}
}
+
+ if out {
+ appendOut(output, false)
+ }
+
+ return output
}
func parseExpression(out bool) string {
diff --git a/src/asl/parser_test.go b/src/asl/parser_test.go
index f0788ab..45c8514 100644
--- a/src/asl/parser_test.go
+++ b/src/asl/parser_test.go
@@ -59,13 +59,12 @@ func TestParserFunction(t *testing.T) {
equal(t, got, want)
}
-// TODO
-/*func TestParserAssignResult(t *testing.T) {
+func TestParserAssignResult(t *testing.T) {
got := getCompiled(t, "test/parser_assign_result.asl")
want := "x = [1, 2, 3] call foo;\ny = [1, 2, 3] call bar;"
equal(t, got, want)
-}*/
+}
func TestExpression(t *testing.T) {
got := getCompiled(t, "test/parser_expression.asl")
@@ -81,6 +80,13 @@ func TestExpression2(t *testing.T) {
equal(t, got, want)
}
+func TestFunctionCall(t *testing.T) {
+ got := getCompiled(t, "test/parser_func_call.asl")
+ want := "myFunc = {\na = _this select 0;\nb = _this select 1;\nreturn a>b;\n};\n[1+3/4, 2-(66*22)/3-((123))] call myFunc;\n"
+
+ equal(t, got, want)
+}
+
func getCompiled(t *testing.T, file string) string {
code, err := ioutil.ReadFile(file)
diff --git a/src/main/asl.go b/src/main/asl.go
index 236d9ad..e084ada 100644
--- a/src/main/asl.go
+++ b/src/main/asl.go
@@ -9,10 +9,10 @@ import (
const version = "0.1"
func usage() {
- fmt.Println("Usage: asl [-v|-r|-pretty] [