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

View File

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

View File

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

View File

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