Categorygithub.com/linxlib/astp
modulepackage
0.3.0
Repository: https://github.com/linxlib/astp.git
Documentation: pkg.go.dev

# README

astp

A golang ast syntax tree parser

parse your source code, and describe them with json or yaml

Features

  • 解析一个项目代码,生成可序列化内容
  • 内置处理枚举写法
  • 内置处理泛型和对象继承写法

Usage

Common Use

package main

import (
	"flag"
	"fmt"
	"github.com/linxlib/astp"
)

var (
	outFile string
)

func init() {
	flag.StringVar(&outFile, "o", "default", "-o gen.json")
}
func main() {
	flag.Parse()
	p := astp.NewParser()
	p.Parse()
	if outFile == "" {
		outFile = "gen.json"
	}
	err := p.WriteOut(outFile)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("complete!")
}

Load

package main

import (
	"github.com/linxlib/astp"
)
func main() {
    parser := astp.NewParser()
    parser.Load("gen.json")
	// 循环
    parser.VisitStruct(func(element *astp.Element) bool {
		return true
	}, func(e *astp.Element) {
		
    })
}

Use it with go generate

//go:generate go run github.com/linxlib/astp/astpg -o gen.json

Examples

check fw and fw_example for details

# Packages

No description provided by the author
maybe some package description.

# Functions

CheckPackage 返回某个包是何种类型的包.
No description provided by the author
No description provided by the author
No description provided by the author
ParseIt 返回一个类型是否需要进行解析(第三方包 系统内置包).

# Constants

内建类型.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
当前模块的其他包.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
在相同包下, 待后续解析.
第三方包.

# Structs

AstHandler ast树解析类,一个代表一个go文件.
No description provided by the author
File 代表一个已解析的go文件.
Import 导入.
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author