diff --git a/src/tokenizer/tokenizer.go b/src/tokenizer/tokenizer.go index 003b89f..dba1423 100644 --- a/src/tokenizer/tokenizer.go +++ b/src/tokenizer/tokenizer.go @@ -11,50 +11,52 @@ type Token struct { Column int } -var delimiter = []byte{ - '=', - ';', - '{', - '}', - '(', - ')', - '[', - ']', - '<', - '>', - '!', - ',', - ':', - '&', - '|', - '+', - '-', - '*', - '/'} // TODO: modulo? +var ( + delimiter = []byte{ + '=', + ';', + '{', + '}', + '(', + ')', + '[', + ']', + '<', + '>', + '!', + ',', + ':', + '&', + '|', + '+', + '-', + '*', + '/'} // TODO: modulo? -var keywords = []string{ - "var", - "if", - "while", - "switch", - "for", - "foreach", - "func", - "true", - "false", - "case", - "default", - "return", - "try", - "catch", - "exitwith", - "waituntil", - "code"} + keywords = []string{ + "var", + "if", + "while", + "switch", + "for", + "foreach", + "func", + "true", + "false", + "case", + "default", + "return", + "try", + "catch", + "exitwith", + "waituntil", + "code"} -var whitespace = []byte{' ', '\n', '\t', '\r'} -var identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" -var preprocessor = byte('#') -var new_line = []byte{'\r', '\n'} + whitespace = []byte{' ', '\n', '\t', '\r'} + identifier = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" + preprocessor = byte('#') + new_line = []byte{'\r', '\n'} +) // Tokenizes the given byte array into syntax tokens, // which can be parsed later. diff --git a/src/types/loader.go b/src/types/loader.go index 5120e83..f608d41 100644 --- a/src/types/loader.go +++ b/src/types/loader.go @@ -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, " ") }