astp

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2025 License: MIT Imports: 10 Imported by: 1

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parser

type Parser struct {
	*types.Project
	// contains filtered or unexported fields
}

func (*Parser) Parse

func (p *Parser) Parse() error

func (*Parser) VisitStructByName added in v0.3.1

func (p *Parser) VisitStructByName(name string, filter func(s *types.Struct) bool, handler func(s *types.Struct))

Directories

Path Synopsis
maybe some package description
maybe some package description

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL