dashast

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package dashast

Go语法树解析工具

Go AST(abstract syntax code) parsing tool

Index

Examples

Constants

View Source
const (
	Unsupport     = iota //未支持的类型
	Ident                //string int 非指针的结构体
	StructType           //结构体中的匿名结构体或 外面定义的结构体类型
	StarExpr             //指针类型的参数
	SelectorExpr         //别的包的类型或表达式类型参数
	Ellipsis             //...可变参数类型
	ArrayType            //切片或数组
	ChanType             //通道类型
	MapType              //map类型
	InterfaceType        //interface类型
	FuncType             //函数类型
)

Variables

This section is empty.

Functions

func CheckInnerStruct

func CheckInnerStruct(name string) bool

@Editor robotyang at 2023

CheckInnerStruct 检查是不是 内部使用的结构体

func FilterInnerField

func FilterInnerField(field *ast.Field) bool

FilterInnerField @Editor robotyang at 2023

FilterInnerField 过滤小写字段

func FilterInnerSt

func FilterInnerSt(st *ast.TypeSpec) bool

FilterInnerSt @Editor robotyang at 2023

func FilterProtoInner

func FilterProtoInner(field *ast.Field) bool

FilterProtoInner @Editor robotyang at 2023

func FilterProtoSt

func FilterProtoSt(st *ast.TypeSpec) bool

FilterProtoSt @Editor robotyang at 2023

Types

type Ast

type Ast struct {
	Package    string
	Imports    []Import
	Structs    []Struct
	Interfaces []Interface
	Funcs      []Func
	// contains filtered or unexported fields
}

func NewAst

func NewAst(options ...*Option) *Ast

NewAst @Editor robotyang at 2023

NewAst 用于实例化解析工具对象

@Param options:额外作用选项

NewAst Used for instance resolution tool objects

@Param options:Extra effect option

Example

ExampleNewAst is a ...

package main

import (
	"fmt"
	"log"

	"github.com/rbtyang/godash/dashast"
)

func main() {
	a := dashast.NewAst()
	err := a.ParseFile("../dasharr/arr.go")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(a.Package)
	fmt.Println(a.Imports[0].Name)
	fmt.Println(a.Funcs[0].Name)
}
Output:

dasharr
reflect
Contain

func (*Ast) ParseDecls

func (a *Ast) ParseDecls(Decls []ast.Decl) (err error)

ParseDecls @Editor robotyang at 2023

func (*Ast) ParseField

func (a *Ast) ParseField(field *ast.Field) (ret Field)

ParseField @Editor robotyang at 2023

func (*Ast) ParseFile

func (a *Ast) ParseFile(inputPath string) (err error)

ParseFile @Editor robotyang at 2023

ParseFile 解析指定路径的Go文件

@Param inputPath:输入文件路径

ParseFile Parses the Go file in the specified path

@Param inputPath:Input file path

func (*Ast) ParseFunc

func (a *Ast) ParseFunc(f *ast.FuncType) (ret Func)

ParseFunc @Editor robotyang at 2023

func (*Ast) ParseImport

func (a *Ast) ParseImport(i *ast.ImportSpec) (ret Import)

ParseImport @Editor robotyang at 2023

func (*Ast) ParseInterface

func (a *Ast) ParseInterface(typ *ast.TypeSpec) (ret Interface)

ParseInterface @Editor robotyang at 2023

func (*Ast) ParseScopes

func (a *Ast) ParseScopes(Scope *ast.Scope) (err error)

ParseScopes @Editor robotyang at 2023

func (*Ast) ParseStruct

func (a *Ast) ParseStruct(typ *ast.TypeSpec) (ret Struct)

ParseStruct @Editor robotyang at 2023

type Field

type Field struct {
	Name     string   //参数名
	Type     Type     //参数类型
	Comments []string //在后面的备注
	Docs     []string //在上方的备注
	Tag      string   //原来的tag
}

结构体字段

func (Field) Copy

func (t Field) Copy() (new Field)

Copy @Editor robotyang at 2023

type FieldFilter

type FieldFilter func(*ast.Field) bool

返回true 可以继续执行,返回false 过滤掉这个数据

type FilterFuncOpt

type FilterFuncOpt struct {
	FuncName string
	Recv     *Field
}

type Func

type Func struct {
	Name     string
	Recv     *Field   //接收器 func前的参数
	Docs     []string //在上方的备注
	Comments []string //在后面的备注
	Params   []Field  //入参
	Results  []Field  //返回参数
}

type FuncFilter

type FuncFilter func(*Func) bool

返回true 可以继续执行,返回false 过滤掉这个数据

func FilterFuncList

func FilterFuncList(funcList []FilterFuncOpt) FuncFilter

FilterFuncList @Editor robotyang at 2023

FilterFuncList 只返回 符合的 函数列表

type Import

type Import struct {
	Name     string   //路径的别名
	Path     string   //路径
	Comments []string //在后面的备注
	Docs     []string //在上方的备注
}

type Interface

type Interface struct {
	Name     string   //
	Comments []string //在后面的备注
	Docs     []string //在上方的备注
	Funcs    []Func   //函数列表
}

func (Interface) Copy

func (i Interface) Copy() (new Interface)

Copy @Editor robotyang at 2023

type Option

type Option struct {
	// contains filtered or unexported fields
}

func WithFieldFilter

func WithFieldFilter(filter ...FieldFilter) *Option

WithFieldFilter @Editor robotyang at 2023

func WithFuncFilter

func WithFuncFilter(filter ...FuncFilter) *Option

WithFuncFilter @Editor robotyang at 2023

func WithStructFilter

func WithStructFilter(filter ...StructFilter) *Option

WithStructFilter @Editor robotyang at 2023

type Struct

type Struct struct {
	Name     string   //结构体的名字
	Comments []string //在后面的备注
	Docs     []string //在上方的备注
	Fields   []Field  //字段
}

结构体

func (Struct) GetFieldWithName

func (s Struct) GetFieldWithName(name string) *Field

GetFieldWithName @Editor robotyang at 2023

type StructFilter

type StructFilter func(*ast.TypeSpec) bool

返回true 可以继续执行,返回false 过滤掉这个数据

type Type

type Type struct {
	Name  []string //如果是 a.b 则name 为 a,b
	Kind  int      //type类型
	Types []Type   //如果是复杂类型 则在Types中进行嵌套 如map
	Inner bool     //最低位如果为true则是内部结构体,需要修改名字,只针对结构体
}

func (Type) Cmp

func (t Type) Cmp(t2 Type) bool

Cmp @Editor robotyang at 2023

Cmp 比较是否类型相同

func (Type) Copy

func (t Type) Copy() (new Type)

Copy @Editor robotyang at 2023

func (Type) Fmt

func (t Type) Fmt() string

Fmt @Editor robotyang at 2023

func (Type) InnerAddSuffix

func (t Type) InnerAddSuffix(suffix string) Type

InnerAddSuffix @Editor robotyang at 2023

InnerAddSuffix 内部字段添加后缀

func (Type) IsInnerStruct

func (t Type) IsInnerStruct() bool

IsInnerStruct @Editor robotyang at 2023

func (Type) String

func (t Type) String() string

String @Editor robotyang at 2023

Jump to

Keyboard shortcuts

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