Finished loading type file.

This commit is contained in:
Marvin Blum
2016-01-06 21:43:17 +01:00
parent 3f6b854a09
commit 9d909a0b8a
2 changed files with 18 additions and 8 deletions

View File

@@ -14,6 +14,7 @@
* ~~better error reporting~~ * ~~better error reporting~~
- ~~recover panic~~ - ~~recover panic~~
- ~~line, column~~ - ~~line, column~~
* type check for functions
## Special cases ## Special cases

View File

@@ -48,6 +48,7 @@ func LoadTypes(path string) error {
} }
data := strings.Replace(win_new_line, unix_new_line, string(content), -1) // make this work on windows and unix data := strings.Replace(win_new_line, unix_new_line, string(content), -1) // make this work on windows and unix
functions = make([]FunctionType, 0)
parseTypes(data) parseTypes(data)
return nil return nil
@@ -73,29 +74,37 @@ func parseTypes(content string) {
func parseNullFunction(line string) { func parseNullFunction(line string) {
parts := getParts(line) parts := getParts(line)
functions = append(functions, FunctionType{parts[0], NULL, 0})
for _, part := range parts {
}
} }
func parseUnaryFunction(line string) { func parseUnaryFunction(line string) {
parts := getParts(line) parts := getParts(line)
for _, part := range parts { if len(parts) < 2 {
return
} }
args := getArgs(parts[1])
functions = append(functions, FunctionType{parts[0], UNARY, len(args)})
} }
func parseBinaryFunction(line string) { func parseBinaryFunction(line string) {
parts := getParts(line) parts := getParts(line)
for _, part := range parts { if len(parts) < 3 {
return
} }
argsLeft := getArgs(parts[0])
argsRight := getArgs(parts[2])
functions = append(functions, FunctionType{parts[1], BINARY, len(argsLeft) + len(argsRight)})
} }
func getParts(line string) []string { func getParts(line string) []string {
line = line[2:] line = line[2:]
return strings.Split(line, " ") return strings.Split(line, " ")
} }
func getArgs(part string) []string {
return strings.Split(part, ",")
}