Implement parsing methods

This commit is contained in:
2024-09-15 13:50:10 +02:00
parent 2a7be40f09
commit 6ee7a4b2dc
3 changed files with 75 additions and 18 deletions

View File

@@ -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: "",
})
})
// <div id="add" class="codecontainer">
// <div id="add" class="function">
// <p>
// <span class="keyword">function var</span> add(<span class="type">CargoBay</span> <span
// class="parameter">other</span>) <br />
// </p>
// </div>
// <div id="add" class="">
// <p><span class="docheader">Returns</span></p>
// <div class="indented">
// <p>
// nothing
// </p>
// </div>
// </p>
// </div>
// </div>
spew.Dump(res)
return res, nil
}