Documentation
¶
Overview ¶
Package dashast
Go语法树解析工具 ¶
Go AST(abstract syntax code) parsing tool
Index ¶
- Constants
- func CheckInnerStruct(name string) bool
- func FilterInnerField(field *ast.Field) bool
- func FilterInnerSt(st *ast.TypeSpec) bool
- func FilterProtoInner(field *ast.Field) bool
- func FilterProtoSt(st *ast.TypeSpec) bool
- type Ast
- func (a *Ast) ParseDecls(Decls []ast.Decl) (err error)
- func (a *Ast) ParseField(field *ast.Field) (ret Field)
- func (a *Ast) ParseFile(inputPath string) (err error)
- func (a *Ast) ParseFunc(f *ast.FuncType) (ret Func)
- func (a *Ast) ParseImport(i *ast.ImportSpec) (ret Import)
- func (a *Ast) ParseInterface(typ *ast.TypeSpec) (ret Interface)
- func (a *Ast) ParseScopes(Scope *ast.Scope) (err error)
- func (a *Ast) ParseStruct(typ *ast.TypeSpec) (ret Struct)
- type Field
- type FieldFilter
- type FilterFuncOpt
- type Func
- type FuncFilter
- type Import
- type Interface
- type Option
- type Struct
- type StructFilter
- type Type
Examples ¶
Constants ¶
const ( Unsupport = iota //未支持的类型 Ident //string int 非指针的结构体 StructType //结构体中的匿名结构体或 外面定义的结构体类型 StarExpr //指针类型的参数 SelectorExpr //别的包的类型或表达式类型参数 Ellipsis //...可变参数类型 ArrayType //切片或数组 ChanType //通道类型 MapType //map类型 InterfaceType //interface类型 FuncType //函数类型 )
Variables ¶
This section is empty.
Functions ¶
func FilterInnerSt ¶
FilterInnerSt @Editor robotyang at 2023
func FilterProtoInner ¶
FilterProtoInner @Editor robotyang at 2023
func FilterProtoSt ¶
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 ¶
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 ¶
ParseDecls @Editor robotyang at 2023
func (*Ast) ParseField ¶
ParseField @Editor robotyang at 2023
func (*Ast) ParseFile ¶
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) ParseImport ¶
func (a *Ast) ParseImport(i *ast.ImportSpec) (ret Import)
ParseImport @Editor robotyang at 2023
func (*Ast) ParseInterface ¶
ParseInterface @Editor robotyang at 2023
func (*Ast) ParseScopes ¶
ParseScopes @Editor robotyang at 2023
type Field ¶
type Field struct {
Name string //参数名
Type Type //参数类型
Comments []string //在后面的备注
Docs []string //在上方的备注
Tag string //原来的tag
}
结构体字段
type FilterFuncOpt ¶
type FuncFilter ¶
返回true 可以继续执行,返回false 过滤掉这个数据
func FilterFuncList ¶
func FilterFuncList(funcList []FilterFuncOpt) FuncFilter
FilterFuncList @Editor robotyang at 2023
FilterFuncList 只返回 符合的 函数列表 ¶
type Interface ¶
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 ¶
GetFieldWithName @Editor robotyang at 2023
type Type ¶
type Type struct {
Name []string //如果是 a.b 则name 为 a,b
Kind int //type类型
Types []Type //如果是复杂类型 则在Types中进行嵌套 如map
Inner bool //最低位如果为true则是内部结构体,需要修改名字,只针对结构体
}
func (Type) IsInnerStruct ¶
IsInnerStruct @Editor robotyang at 2023