This commit is contained in:
Marvin Blum
2015-10-25 13:04:30 +01:00
parent 276dd2c1e9
commit 2e7e198047
6 changed files with 317 additions and 317 deletions

View File

@@ -188,12 +188,12 @@ func parseForeach() {
appendOut("{", true)
parseBlock()
expect("}")
appendOut("} forEach (" + expr + ");", true)
appendOut("} forEach ("+expr+");", true)
}
func parseFunction() {
expect("func")
appendOut(get().token + " = {", true)
appendOut(get().token+" = {", true)
next()
expect("(")
parseFunctionParameter()
@@ -215,7 +215,7 @@ func parseFunctionParameter() {
for !accept(")") {
name := get().token
next()
appendOut(name + " = _this select " + strconv.FormatInt(i, 10) + ";", true)
appendOut(name+" = _this select "+strconv.FormatInt(i, 10)+";", true)
i++
if !accept(")") {
@@ -279,20 +279,20 @@ func parseFunctionCall(out bool, name string) string {
expect(")")
if leftParamCount > 1 {
leftParams = "["+leftParams+"]"
leftParams = "[" + leftParams + "]"
}
if rightParamCount > 1 {
rightParams = "["+rightParams+"]"
rightParams = "[" + rightParams + "]"
}
if leftParamCount > 0 {
output = leftParams+" "+name+" "+rightParams
output = leftParams + " " + name + " " + rightParams
} else {
output = name+" "+rightParams
output = name + " " + rightParams
}
} else {
output = "["+leftParams+"] call "+name
output = "[" + leftParams + "] call " + name
}
if out {
@@ -367,7 +367,7 @@ func parseIdentifier() string {
if seek("(") && !accept("!") && !accept("-") {
name := get().token
next()
output = "("+parseFunctionCall(false, name)+")"
output = "(" + parseFunctionCall(false, name) + ")"
} else if accept("!") || accept("-") {
output = get().token
next()
@@ -389,7 +389,7 @@ func parseIdentifier() string {
func parseTerm() string {
if accept("(") {
expect("(")
output := "("+parseExpression(false)+")"
output := "(" + parseExpression(false) + ")"
expect(")")
return output

View File

@@ -1,9 +1,9 @@
package asl_test
import (
"testing"
"io/ioutil"
"asl"
"io/ioutil"
"testing"
)
func TestParserDeclaration(t *testing.T) {
@@ -98,7 +98,7 @@ func getCompiled(t *testing.T, file string) string {
code, err := ioutil.ReadFile(file)
if err != nil {
t.Error("Could not read test file: "+file)
t.Error("Could not read test file: " + file)
t.FailNow()
}

View File

@@ -1,8 +1,8 @@
package asl
import (
"testing"
"io/ioutil"
"testing"
)
func TestTokenizerVar(t *testing.T) {
@@ -83,11 +83,11 @@ func compareLength(t *testing.T, got *[]Token, want *[]string) {
gotlist, wantlist := "", ""
for i := range *got {
gotlist += (*got)[i].token+" "
gotlist += (*got)[i].token + " "
}
for i := range *want {
wantlist += (*want)[i]+" "
wantlist += (*want)[i] + " "
}
t.Log(gotlist)
@@ -100,7 +100,7 @@ func compareLength(t *testing.T, got *[]Token, want *[]string) {
func compareTokens(t *testing.T, got *[]Token, want *[]string) {
for i := range *got {
if (*got)[i].token != (*want)[i] {
t.Error("Tokens do not match: "+(*got)[i].token+" != "+(*want)[i])
t.Error("Tokens do not match: " + (*got)[i].token + " != " + (*want)[i])
}
}
}
@@ -109,7 +109,7 @@ func getTokens(t *testing.T, file string) []Token {
code, err := ioutil.ReadFile(file)
if err != nil {
t.Error("Could not read test file: "+file)
t.Error("Could not read test file: " + file)
t.FailNow()
}

View File

@@ -23,5 +23,5 @@ func main() {
token := asl.Tokenize(code)
out := asl.Parse(token, true)
fmt.Print("OUTPUT:\n-------\n"+out)
fmt.Print("OUTPUT:\n-------\n" + out)
}