Exemple #1
0
// Compiles a single ASL file.
func compileFile(path string, file ASLFile, waiter chan bool) {
	defer recoverCompileError(file.in, waiter)

	// read file
	out := filepath.FromSlash(path + PathSeparator + file.out + PathSeparator + file.newname + sqfextension)
	fmt.Println(file.in + " -> " + out)
	code, err := ioutil.ReadFile(file.in)

	if err != nil {
		fmt.Println("Error reading file: " + file.in)
		return
	}

	// compile
	token := tokenizer.Tokenize(code, false)
	compiler := parser.Compiler{}
	sqf := compiler.Parse(token, pretty)

	os.MkdirAll(filepath.FromSlash(path+PathSeparator+file.out), 0777)
	err = ioutil.WriteFile(out, []byte(sqf), 0666)

	if err != nil {
		fmt.Println("Error writing file: " + file.out)
		fmt.Println(err)
	}

	waiter <- true // done
}
func getTokens(t *testing.T, file string) []tokenizer.Token {
	code, err := ioutil.ReadFile(file)

	if err != nil {
		t.Error("Could not read test file: " + file)
		t.FailNow()
	}

	return tokenizer.Tokenize(code, false)
}
Exemple #3
0
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.FailNow()
	}

	tokens := tokenizer.Tokenize(code, false)
	compiler := parser.Compiler{}

	return compiler.Parse(tokens, true)
}
Exemple #4
0
func (c *Compiler) parseInlineCode() string {
	c.expect("code")
	c.expect("(")

	code := c.get().Token
	c.next()
	output := "{}"

	if len(code) > 2 {
		compiler := Compiler{}
		output = "{" + compiler.Parse(tokenizer.Tokenize([]byte(code[1:len(code)-1]), true), false) + "}"
	}

	c.expect(")")

	return output
}