Now splits by windows and unix new lines, added parsing structure.

This commit is contained in:
Marvin Blum
2015-12-17 23:23:49 +01:00
parent 05e6937201
commit 3f6b854a09
2 changed files with 122 additions and 51 deletions

View File

@@ -1,12 +1,45 @@
package types
import (
"fmt"
"io/ioutil"
"strings"
)
const (
// type for object types
TYPE = 1
// types for functions
NULL = 2
UNARY = 3
BINARY = 4
win_new_line = "\r\n"
unix_new_line = "\n"
)
type FunctionType struct {
Name string
Type int // one of the constants NULL, UNARY, BINARY
ArgsCount int
}
var functions []FunctionType
// Returns function type information by name.
// If not found, the first parameter will be false.
func GetFunction(name string) (bool, FunctionType) {
for _, function := range functions {
if function.Name == name {
return true, function
}
}
return false, FunctionType{}
}
// Loads type information from file.
// The format is specified by 'supportInfo' command: https://community.bistudio.com/wiki/supportInfo
func LoadTypes(path string) error {
content, err := ioutil.ReadFile(path)
@@ -14,19 +47,55 @@ func LoadTypes(path string) error {
return err
}
if err := parseTypes(string(content)); err != nil {
return err
}
data := strings.Replace(win_new_line, unix_new_line, string(content), -1) // make this work on windows and unix
parseTypes(data)
return nil
}
func parseTypes(content string) error {
lines := strings.Split(content, "\\n")
func parseTypes(content string) {
lines := strings.Split(content, unix_new_line)
for _, line := range lines {
fmt.Println(line)
}
if len(line) < 3 {
continue
}
return nil
if line[0] == 'n' {
parseNullFunction(line)
} else if line[0] == 'u' {
parseUnaryFunction(line)
} else if line[0] == 'b' {
parseBinaryFunction(line)
}
}
}
func parseNullFunction(line string) {
parts := getParts(line)
for _, part := range parts {
}
}
func parseUnaryFunction(line string) {
parts := getParts(line)
for _, part := range parts {
}
}
func parseBinaryFunction(line string) {
parts := getParts(line)
for _, part := range parts {
}
}
func getParts(line string) []string {
line = line[2:]
return strings.Split(line, " ")
}