Implement field generation
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
---@diagnostic disable: missing-return, lowercase-global
|
||||
---@class {{.ClassName}}
|
||||
{{range .Fields -}}
|
||||
---@field {{.Name}} {{.Type}} {{.Comment}}
|
||||
{{end -}}
|
||||
---@class {{.ClassName}}
|
||||
{{.ClassName}} = {
|
||||
{{$n := len .Methods -}}
|
||||
{{$methods := len .Methods -}}
|
||||
|
5
go.mod
5
go.mod
@@ -2,7 +2,10 @@ module avorion-docparser
|
||||
|
||||
go 1.23.0
|
||||
|
||||
require github.com/PuerkitoBio/goquery v1.10.0
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.10.0
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/cascadia v1.3.2 // indirect
|
||||
|
2
go.sum
2
go.sum
@@ -2,6 +2,8 @@ github.com/PuerkitoBio/goquery v1.10.0 h1:6fiXdLuUvYs2OJSvNRqlNPoBm6YABE226xrbav
|
||||
github.com/PuerkitoBio/goquery v1.10.0/go.mod h1:TjZZl68Q3eGHNBA8CWaxAN7rOU1EbDz3CWuolcO5Yu4=
|
||||
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
|
||||
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
|
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