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
}
Exemple #2
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)
}