Implement field generation
This commit is contained in:
32
main.go
32
main.go
@@ -6,9 +6,11 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
@@ -30,6 +32,9 @@ func init() {
|
||||
Warning = log.New(io.MultiWriter(os.Stdout),
|
||||
fmt.Sprintf("%sWarning:%s ", "\033[0;93m", "\033[0m"),
|
||||
log.Lmicroseconds|log.Lshortfile)
|
||||
|
||||
spew.Config.Indent = " "
|
||||
spew.Config.SortKeys = true
|
||||
}
|
||||
|
||||
var fns = template.FuncMap{
|
||||
@@ -108,8 +113,8 @@ func ParseFile(filename string) (*Class, error) {
|
||||
|
||||
resConstructor := Constructor{}
|
||||
paramTypes.Each(func(i int, s *goquery.Selection) {
|
||||
pname := paramNames.Eq(i).Text()
|
||||
ptype := paramTypes.Eq(i).Text()
|
||||
pname := strings.TrimSpace(paramNames.Eq(i).Text())
|
||||
ptype := strings.TrimSpace(paramTypes.Eq(i).Text())
|
||||
ptype = MapType(ptype)
|
||||
|
||||
resConstructor.Params = append(resConstructor.Params, Param{
|
||||
@@ -120,9 +125,20 @@ func ParseFile(filename string) (*Class, error) {
|
||||
})
|
||||
res.Constructors = append(res.Constructors, resConstructor)
|
||||
|
||||
// constructorDetails := codeblocks.Eq(1)
|
||||
properties := doc.Find("div.floatright > div.codecontainer#Properties")
|
||||
properties.ChildrenFiltered("div").Each(func(i int, s *goquery.Selection) {
|
||||
property := Field{}
|
||||
property.Name = strings.TrimSpace(s.Find("span.property").Text())
|
||||
property.Type = strings.TrimSpace(s.Find("span.type").Text())
|
||||
property.Type = MapType(property.Type)
|
||||
comment := s.Find("td[align='right']").Text()
|
||||
if comment != "" {
|
||||
property.Comment = strings.TrimSpace(comment)
|
||||
}
|
||||
res.Fields = append(res.Fields, property)
|
||||
})
|
||||
|
||||
log.Printf("%#v", res)
|
||||
spew.Dump(res)
|
||||
|
||||
return &res, nil
|
||||
}
|
||||
@@ -135,12 +151,10 @@ func MapType(t string) string {
|
||||
return "number"
|
||||
case "float":
|
||||
return "number"
|
||||
case "string":
|
||||
return "string"
|
||||
case "boolean":
|
||||
case "bool":
|
||||
return "boolean"
|
||||
case "void":
|
||||
return "nil"
|
||||
case "table_t":
|
||||
return "table"
|
||||
default:
|
||||
return t
|
||||
}
|
||||
|
Reference in New Issue
Block a user