parse ts
This commit is contained in:
parent
02b30e6ac0
commit
a4029e2399
@ -1,5 +1,8 @@
|
||||
/**
|
||||
* @kittenipc:api
|
||||
* kek
|
||||
* @readonly
|
||||
* lol
|
||||
* @kittenipc api
|
||||
*/
|
||||
class IpcApi {
|
||||
Mul(a: number, b: number): number {
|
||||
|
||||
@ -68,6 +68,10 @@ func (g *GoApiParser) Parse(sourceFile string) (Api, error) {
|
||||
return Api{}, fmt.Errorf("no api struct found")
|
||||
}
|
||||
|
||||
if len(apiStructs) > 1 {
|
||||
return Api{}, fmt.Errorf("multiple api struct found")
|
||||
}
|
||||
|
||||
for _, decl := range astFile.Decls {
|
||||
funcDecl, ok := decl.(*ast.FuncDecl)
|
||||
if !ok {
|
||||
|
||||
@ -2,33 +2,84 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/ast"
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/core"
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/parser"
|
||||
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/tspath"
|
||||
)
|
||||
|
||||
const TagName = "kittenipc"
|
||||
const TagComment = "api"
|
||||
|
||||
type TypescriptApiParser struct {
|
||||
}
|
||||
|
||||
type apiClass struct {
|
||||
}
|
||||
|
||||
func (t *TypescriptApiParser) Parse(sourceFilePath string) (Api, error) {
|
||||
|
||||
f, err := os.Open(sourceFilePath)
|
||||
if err != nil {
|
||||
return Api{}, fmt.Errorf("failed to open file: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
fileContents, err := io.ReadAll(f)
|
||||
if err != nil {
|
||||
return Api{}, fmt.Errorf("failed to read file: %w", err)
|
||||
}
|
||||
|
||||
sourceFile := parser.ParseSourceFile(ast.SourceFileParseOptions{
|
||||
FileName: sourceFilePath,
|
||||
Path: "",
|
||||
Path: tspath.Path(sourceFilePath),
|
||||
CompilerOptions: core.SourceFileAffectingCompilerOptions{},
|
||||
ExternalModuleIndicatorOptions: ast.ExternalModuleIndicatorOptions{},
|
||||
JSDocParsingMode: ast.JSDocParsingModeParseAll,
|
||||
}, "", core.ScriptKindTS)
|
||||
}, string(fileContents), core.ScriptKindTS)
|
||||
_ = sourceFile
|
||||
|
||||
var apiClasses []apiClass
|
||||
|
||||
sourceFile.ForEachChild(func(node *ast.Node) bool {
|
||||
if node.IsJSDoc() {
|
||||
jsDoc := node.AsJSDoc()
|
||||
_ = jsDoc
|
||||
fmt.Println("a")
|
||||
if node.Kind != ast.KindClassDeclaration {
|
||||
return false
|
||||
}
|
||||
cls := node.AsClassDeclaration()
|
||||
|
||||
jsDocNodes := cls.JSDoc(nil)
|
||||
if len(jsDocNodes) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, jsDocNode := range jsDocNodes {
|
||||
jsDoc := jsDocNode.AsJSDoc()
|
||||
for _, tag := range jsDoc.Tags.Nodes {
|
||||
if tag.TagName().Text() == TagName {
|
||||
for _, com := range tag.Comments() {
|
||||
if strings.TrimSpace(com.Text()) == TagComment {
|
||||
apiClasses = append(apiClasses, apiClass{})
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if len(apiClasses) == 0 {
|
||||
return Api{}, fmt.Errorf("no api class found")
|
||||
}
|
||||
|
||||
if len(apiClasses) > 1 {
|
||||
return Api{}, fmt.Errorf("multiple api classes found")
|
||||
}
|
||||
|
||||
return Api{}, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user