mirror of
https://github.com/Kugelschieber/asl.git
synced 2026-01-18 03:50:25 +00:00
Finished loading type file.
This commit is contained in:
1
ToDo.md
1
ToDo.md
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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, ",")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user