Implement method description parser
This commit is contained in:
69
class.go
69
class.go
@@ -330,7 +330,8 @@ func parseMethod(s *goquery.Selection) (Method, error) {
|
|||||||
}
|
}
|
||||||
res.Name = id
|
res.Name = id
|
||||||
|
|
||||||
returns := s.Find("span.keyword")
|
signatureData := s.Children().Eq(0)
|
||||||
|
returns := signatureData.Find("span.keyword")
|
||||||
if returns.Length() != 0 {
|
if returns.Length() != 0 {
|
||||||
returnsText := CleanUp(returns.Text())
|
returnsText := CleanUp(returns.Text())
|
||||||
returnsText = strings.ReplaceAll(returnsText, "function", "")
|
returnsText = strings.ReplaceAll(returnsText, "function", "")
|
||||||
@@ -342,8 +343,8 @@ func parseMethod(s *goquery.Selection) (Method, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
types := s.Find("span.type")
|
types := signatureData.Find("span.type")
|
||||||
parameters := s.Find("span.parameter")
|
parameters := signatureData.Find("span.parameter")
|
||||||
types.Each(func(i int, s *goquery.Selection) {
|
types.Each(func(i int, s *goquery.Selection) {
|
||||||
res.Params = append(res.Params, Param{
|
res.Params = append(res.Params, Param{
|
||||||
Name: MapName(CleanUp(parameters.Eq(i).Text())),
|
Name: MapName(CleanUp(parameters.Eq(i).Text())),
|
||||||
@@ -352,18 +353,68 @@ func parseMethod(s *goquery.Selection) (Method, error) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// <div id="add" class="codecontainer">
|
// 0 nothing
|
||||||
// <div id="add" class="function">
|
// 1 parameters
|
||||||
|
// 2 returns
|
||||||
|
state := 0
|
||||||
|
signatureDetails := s.Children().Eq(1)
|
||||||
|
signatureDetailsChildren := signatureDetails.Children()
|
||||||
|
signatureDetailsChildrenLength := signatureDetailsChildren.Length()
|
||||||
|
signatureDetailsChildren.Each(func(i int, s *goquery.Selection) {
|
||||||
|
if s.Is("p") && i == 0 {
|
||||||
|
methodDescription := CleanUp(s.Text())
|
||||||
|
methodDescription = strings.ReplaceAll(methodDescription, "\n--", "<br>\n\t---")
|
||||||
|
res.Comment = methodDescription
|
||||||
|
}
|
||||||
|
if i == signatureDetailsChildrenLength-1 {
|
||||||
|
// For some stupid reason the last child is always a mispalced </p> tag that does not close any open <p>
|
||||||
|
// I assume this is a bug with their documentation generator
|
||||||
|
// So we just ignore it
|
||||||
|
return
|
||||||
|
}
|
||||||
|
text := CleanUp(s.Text())
|
||||||
|
if text == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if s.Is("p") {
|
||||||
|
switch text {
|
||||||
|
case "Parameters":
|
||||||
|
state = 1
|
||||||
|
case "Returns":
|
||||||
|
state = 2
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("%#v", state)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// <div id="addCargo" class="codecontainer">
|
||||||
|
// <div id="addCargo" class="function">
|
||||||
// <p>
|
// <p>
|
||||||
// <span class="keyword">function var</span> add(<span class="type">CargoBay</span> <span
|
// <span class="keyword">function unsigned int</span> addCargo(<span
|
||||||
// class="parameter">other</span>) <br />
|
// class="type">TradingGood</span>
|
||||||
|
// <span class="parameter">good</span>, <span class="type">int</span> <span
|
||||||
|
// class="parameter">amount</span>) <br />
|
||||||
// </p>
|
// </p>
|
||||||
// </div>
|
// </div>
|
||||||
// <div id="add" class="">
|
// <div id="addCargo" class="">
|
||||||
|
// <p>
|
||||||
|
// Adds cargo to the entity. If the amount specified exceeds the maximum capacity of the cargo
|
||||||
|
// bay, as
|
||||||
|
// much cargo as still fits in will be added.
|
||||||
|
// </p>
|
||||||
|
// <p><span class="docheader">Parameters</span></p>
|
||||||
|
// <div class="indented">
|
||||||
|
// <span class="parameter">good</span>
|
||||||
|
// TradingGood that is to be added. <br />
|
||||||
|
// <span class="parameter">amount</span>
|
||||||
|
// The amount of cargo that should be added. <br />
|
||||||
|
// </div>
|
||||||
// <p><span class="docheader">Returns</span></p>
|
// <p><span class="docheader">Returns</span></p>
|
||||||
// <div class="indented">
|
// <div class="indented">
|
||||||
// <p>
|
// <p>
|
||||||
// nothing
|
// How much was actually added (can be less than amount when cargo bay is full)
|
||||||
// </p>
|
// </p>
|
||||||
// </div>
|
// </div>
|
||||||
// </p>
|
// </p>
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
{{- end}}
|
{{- end}}
|
||||||
{{- range $ret := $method.Returns}}
|
{{- range $ret := $method.Returns}}
|
||||||
---@return {{.Type}}{{if ne .Comment ""}} #{{.Comment}}{{end}}
|
---@return {{.Type}}{{if ne .Comment ""}} #{{.Comment}}{{end}}
|
||||||
{{- end}}
|
{{- end}}{{if ne .Comment ""}}
|
||||||
|
---{{.Comment}}{{end}}
|
||||||
{{.Name}} = function(self{{if gt (len .Params) 0}}, {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}{{end}}{{end}}) 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}}
|
{{- if ne (plus1 $index) $n}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
Reference in New Issue
Block a user