hylia/parser/parser.go

30 lines
No EOL
681 B
Go

package parser
import (
"errors"
"io/ioutil"
"strings"
)
// THE HYLIA PARSER
func ParseFile(filename string) ([]string error) {
// Hey, does the file we're trying to parse actually exist?
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
// Parse the file, and ask "Is this a Hylia file?"
content := string(data)
if !strings.Contains(content, "<hylia>")|| !strings.Contains(content, "</hylia>") {
return nil, errors.New("The structure of this file is invalid. Are you sure this is a Hylia (.hy) file?")
}
// Extract the custom elements, which are wrapped in <element> tags
elements := []string{}
// ... TODO
return elements, nil
}