diff --git a/class.go b/class.go index 346fecb..70be45a 100644 --- a/class.go +++ b/class.go @@ -161,6 +161,13 @@ func ParseClass(file string) (*Class, error) { } res.Fields = append(res.Fields, field) }) + } else { + method, err := parseMethod(s) + if err != nil { + Error.Printf("Error parsing method: %v", err) + return + } + res.Methods = append(res.Methods, method) } }) @@ -311,6 +318,58 @@ func parseField(s *goquery.Selection) (Field, error) { }) res.Comment = strings.ReplaceAll(res.Comment, "\n--", ". ") + return res, nil +} + +func parseMethod(s *goquery.Selection) (Method, error) { + res := Method{} + + id, ok := s.Attr("id") + if !ok { + return res, fmt.Errorf("no id found") + } + res.Name = id + + returns := s.Find("span.keyword") + if returns.Length() != 0 { + returnsText := CleanUp(returns.Text()) + returnsText = strings.ReplaceAll(returnsText, "function", "") + returnsText = CleanUp(returnsText) + + res.Returns = append(res.Returns, Return{ + Type: MapType(returnsText), + Comment: "", + }) + } + + types := s.Find("span.type") + parameters := s.Find("span.parameter") + types.Each(func(i int, s *goquery.Selection) { + res.Params = append(res.Params, Param{ + Name: CleanUp(parameters.Eq(i).Text()), + Type: MapType(CleanUp(types.Eq(i).Text())), + Comment: "", + }) + }) + + //
+ //
+ //

+ // function var add(CargoBay other)
+ //

+ //
+ //
+ //

Returns

+ //
+ //

+ // nothing + //

+ //
+ //

+ //
+ //
+ spew.Dump(res) return res, nil } diff --git a/class.tmpl b/class.tmpl index af788b2..47b52b8 100644 --- a/class.tmpl +++ b/class.tmpl @@ -16,8 +16,7 @@ {{- end}} {{.Name}} = function(self{{if gt (len .Params) 0}}, {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}{{end}}{{end}}) end, {{- if ne (plus1 $index) $n}} - - {{- end}} + {{end}} {{- end}} } diff --git a/main.go b/main.go index cdfc09f..93c46ba 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io" "log" "os" + "strings" "sync" "github.com/davecgh/go-spew/spew" @@ -61,20 +62,18 @@ func main() { } func MapType(t string) string { - switch t { - case "var": - return "any" - case "int": - return "number" - case "float": - return "number" - case "double": - return "number" - case "bool": - return "boolean" - case "table_t": - return "table" - default: - return t - } + t = strings.ReplaceAll(t, "var", "any") + t = strings.ReplaceAll(t, "int", "number") + t = strings.ReplaceAll(t, "unsigned", "") + t = strings.ReplaceAll(t, "float", "number") + t = strings.ReplaceAll(t, "double", "number") + t = strings.ReplaceAll(t, "bool", "boolean") + t = strings.ReplaceAll(t, "table_t", "table") + t = strings.ReplaceAll(t, "...", "[]") + return t } + +func MapName(s string) string { + s = strings.ReplaceAll(s, "in", "input") + return s +} \ No newline at end of file