Initial commit
This commit is contained in:
24
class.tmpl
Normal file
24
class.tmpl
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
---@diagnostic disable: missing-return
|
||||||
|
{{range .Fields}}
|
||||||
|
---@field {{.Name}} {{.Type}} {{.Comment}}
|
||||||
|
{{end}}
|
||||||
|
{{.ClassName}} = {
|
||||||
|
{{$n := len .Methods}}
|
||||||
|
{{$methods := len .Methods}}
|
||||||
|
{{range $index, $method := .Methods}}
|
||||||
|
---@param self {{$.ClassName}}
|
||||||
|
{{range $param := $method.Params}}
|
||||||
|
---@param {{.Name}} {{.Type}} {{.Comment}}
|
||||||
|
{{end}}
|
||||||
|
{{range $ret := $method.Returns}}
|
||||||
|
---@return {{.Type}} {{if ne .Comment ""}}#{{.Comment}}{{end}}
|
||||||
|
{{end}}
|
||||||
|
{{.Name}} = function(self{{if gt (len .Params) 0}}, {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}{{end}}{{end}}) end,
|
||||||
|
{{if eq (plus1 $index) $n}}
|
||||||
|
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
---@type ({{$.ClassName}} | fun(): {{$.ClassName}})
|
||||||
|
{{$.ClassName}} = nil
|
75
main.go
Normal file
75
main.go
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
_ "embed"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed class.tmpl
|
||||||
|
var templatestr string
|
||||||
|
|
||||||
|
var Error *log.Logger
|
||||||
|
var Warning *log.Logger
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||||
|
logger := io.MultiWriter(os.Stdout)
|
||||||
|
log.SetOutput(logger)
|
||||||
|
|
||||||
|
Error = log.New(io.MultiWriter(os.Stderr, os.Stdout),
|
||||||
|
fmt.Sprintf("%sERROR:%s ", "\033[0;101m", "\033[0m"),
|
||||||
|
log.Lmicroseconds|log.Lshortfile)
|
||||||
|
Warning = log.New(io.MultiWriter(os.Stdout),
|
||||||
|
fmt.Sprintf("%sWarning:%s ", "\033[0;93m", "\033[0m"),
|
||||||
|
log.Lmicroseconds|log.Lshortfile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
files := flag.Args()
|
||||||
|
// if len(files) == 0 {
|
||||||
|
// Error.Printf("No files specified")
|
||||||
|
// flag.Usage()
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
test := Class{
|
||||||
|
ClassName: "Test",
|
||||||
|
Fields: []Field{
|
||||||
|
{Name: "a", Type: "int", Comment: "test"},
|
||||||
|
{Name: "b", Type: "string", Comment: "test"},
|
||||||
|
},
|
||||||
|
Methods: []Method{
|
||||||
|
{
|
||||||
|
Name: "test",
|
||||||
|
Params: []Param{
|
||||||
|
{Name: "a", Type: "int", Comment: "test"},
|
||||||
|
{Name: "b", Type: "string", Comment: "test"},
|
||||||
|
},
|
||||||
|
Returns: []Return{
|
||||||
|
{Type: "int", Comment: "test"},
|
||||||
|
{Type: "string", Comment: "test"},
|
||||||
|
},
|
||||||
|
Comment: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ltemplate, err := template.New("class").Parse(templatestr)
|
||||||
|
if err != nil {
|
||||||
|
Error.Printf("Error parsing template: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("%#v", ltemplate)
|
||||||
|
ltemplate.Execute(os.Stdout, test)
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
fmt.Println(file)
|
||||||
|
}
|
||||||
|
}
|
29
types.go
Normal file
29
types.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type (
|
||||||
|
Class struct {
|
||||||
|
ClassName string
|
||||||
|
Fields []Field
|
||||||
|
Methods []Method
|
||||||
|
}
|
||||||
|
Field struct {
|
||||||
|
Name string
|
||||||
|
Type string
|
||||||
|
Comment string
|
||||||
|
}
|
||||||
|
Method struct {
|
||||||
|
Name string
|
||||||
|
Params []Param
|
||||||
|
Returns []Return
|
||||||
|
Comment string
|
||||||
|
}
|
||||||
|
Param struct {
|
||||||
|
Name string
|
||||||
|
Type string
|
||||||
|
Comment string
|
||||||
|
}
|
||||||
|
Return struct {
|
||||||
|
Type string
|
||||||
|
Comment string
|
||||||
|
}
|
||||||
|
)
|
Reference in New Issue
Block a user