mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 12:00:25 +00:00
Fixed switch, something is wrong with function call parameters.
This commit is contained in:
4
ToDo.md
4
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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
const version = "0.1"
|
||||
|
||||
func usage() {
|
||||
fmt.Println("Usage: asl [-v|-r|-pretty] <input file/folder> [<output file/folder>]")
|
||||
fmt.Println("Usage: asl [-v|-r|-pretty] <input file/folder> [<output file/folder>]\n")
|
||||
fmt.Println("-v (optional) shows asl version")
|
||||
fmt.Println("-r (optional) recursivly compile all asl files in folder")
|
||||
fmt.Println("-pretty (optional) activates pretty printing")
|
||||
fmt.Println("-pretty (optional) activates pretty printing\n")
|
||||
fmt.Println("<input file/folder> file or directory to compile")
|
||||
fmt.Println("<output file/folder> (optional) output file/folder, if not set, files will be created alongside their asl files")
|
||||
}
|
||||
|
||||
5
test/parser_func_call.asl
Normal file
5
test/parser_func_call.asl
Normal file
@@ -0,0 +1,5 @@
|
||||
func myFunc(a, b) {
|
||||
return a > b;
|
||||
}
|
||||
|
||||
myFunc(1+3/4, 2-(66*22)/3-((123)));
|
||||
Reference in New Issue
Block a user