parsy

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As added in v1.2.0

func As[T ast.Node](n ast.Node) (T, bool)

As casts an ast.Node to a specific Node Type.

func AsBasicLit added in v1.2.0

func AsBasicLit(n ast.Node) (*ast.BasicLit, bool)

AsBasicLit casts an ast.Node to *ast.BasicLit

func AsCompositeLit added in v1.2.0

func AsCompositeLit(n ast.Node) (*ast.CompositeLit, bool)

AsCompositeLit casts an ast.Node to *ast.CompositeLit

func AsIdent added in v1.2.0

func AsIdent(n ast.Node) (*ast.Ident, bool)

AsIdent casts an ast.Node to *ast.Ident

func AsStarExpr added in v1.2.0

func AsStarExpr(n ast.Node) (*ast.StarExpr, bool)

AsStarExpr casts an ast.Node to *ast.StarExpr

func AsUnaryExpr added in v1.2.0

func AsUnaryExpr(n ast.Node) (*ast.UnaryExpr, bool)

AsUnaryExpr casts an ast.Node to *ast.UnaryExpr

func GetFuncName added in v1.2.0

func GetFuncName(fn *ast.FuncDecl) (string, bool)

func InspectNode

func InspectNode(i *Inspector, n ast.Node)

InspectNode inspects a node recursive

func ParseFile added in v1.1.2

func ParseFile(i *Inspector, p string) error

func ParseString

func ParseString(i *Inspector, s string) error

Types

type CastExpr added in v1.2.0

type CastExpr struct {
	Expr ast.Expr
}

func (*CastExpr) ToBasicLit added in v1.2.0

func (c *CastExpr) ToBasicLit() (*ast.BasicLit, bool)

func (*CastExpr) ToCompositeLit added in v1.2.0

func (c *CastExpr) ToCompositeLit() (*ast.CompositeLit, bool)

func (*CastExpr) ToIdent added in v1.2.0

func (c *CastExpr) ToIdent() (*ast.Ident, bool)

func (*CastExpr) ToStarExpr added in v1.2.0

func (c *CastExpr) ToStarExpr() (*ast.StarExpr, bool)

func (*CastExpr) ToUnaryExpr added in v1.2.0

func (c *CastExpr) ToUnaryExpr() (*ast.UnaryExpr, bool)

type FuncInfo added in v1.2.0

type FuncInfo struct {
	Name      string
	Receivers []*FuncRecv
	Returns   *FuncReturns
}

func GetFuncInfo added in v1.2.0

func GetFuncInfo(fn *ast.FuncDecl) *FuncInfo

type FuncRecv added in v1.2.0

type FuncRecv struct {
	IsPointer bool
	Name      string
	Ident     *ast.Ident
}

func GetFuncReceivers added in v1.2.0

func GetFuncReceivers(fn *ast.FuncDecl) ([]*FuncRecv, bool)

type FuncReturnCase added in v1.2.0

type FuncReturnCase struct {
	Results []*CastExpr
}

func GetFuncReturnCases added in v1.2.0

func GetFuncReturnCases(fn *ast.FuncDecl) ([]*FuncReturnCase, bool)

type FuncReturnType added in v1.2.0

type FuncReturnType struct {
	IsPointer bool
	Ident     *ast.Ident
}

func GetFuncReturnTypes added in v1.2.0

func GetFuncReturnTypes(fn *ast.FuncDecl) ([]*FuncReturnType, bool)

type FuncReturns added in v1.2.0

type FuncReturns struct {
	Types       []*FuncReturnType
	ReturnCases []*FuncReturnCase
}

type Inspector

type Inspector struct {
	All           listeners[ast.Node]
	ArrayType     listeners[*ast.ArrayType]
	AssignStmt    listeners[*ast.AssignStmt]
	BadDecl       listeners[*ast.BadDecl]
	BadExpr       listeners[*ast.BadExpr]
	BadStmt       listeners[*ast.BadStmt]
	BasicLit      listeners[*ast.BasicLit]
	BinaryExpr    listeners[*ast.BinaryExpr]
	BlockStmt     listeners[*ast.BlockStmt]
	BranchStmt    listeners[*ast.BranchStmt]
	CallExpr      listeners[*ast.CallExpr]
	CaseClause    listeners[*ast.CaseClause]
	ChanType      listeners[*ast.ChanType]
	CommClause    listeners[*ast.CommClause]
	Comment       listeners[*ast.Comment]
	CommentGroup  listeners[*ast.CommentGroup]
	CompositeLit  listeners[*ast.CompositeLit]
	DeclStmt      listeners[*ast.DeclStmt]
	DeferStmt     listeners[*ast.DeferStmt]
	Ellipsis      listeners[*ast.Ellipsis]
	EmptyStmt     listeners[*ast.EmptyStmt]
	ExprStmt      listeners[*ast.ExprStmt]
	Field         listeners[*ast.Field]
	FieldList     listeners[*ast.FieldList]
	File          listeners[*ast.File]
	ForStmt       listeners[*ast.ForStmt]
	FuncDecl      listeners[*ast.FuncDecl]
	FuncLit       listeners[*ast.FuncLit]
	FuncType      listeners[*ast.FuncType]
	GenDecl       listeners[*ast.GenDecl]
	GoStmt        listeners[*ast.GoStmt]
	Ident         listeners[*ast.Ident]
	IfStmt        listeners[*ast.IfStmt]
	ImportSpec    listeners[*ast.ImportSpec]
	IncDecStmt    listeners[*ast.IncDecStmt]
	IndexExpr     listeners[*ast.IndexExpr]
	IndexListExpr listeners[*ast.IndexListExpr]
	InterfaceType listeners[*ast.InterfaceType]
	KeyValueExpr  listeners[*ast.KeyValueExpr]
	LabeledStmt   listeners[*ast.LabeledStmt]
	MapType       listeners[*ast.MapType]

	ParenExpr      listeners[*ast.ParenExpr]
	RangeStmt      listeners[*ast.RangeStmt]
	ReturnStmt     listeners[*ast.ReturnStmt]
	SelectStmt     listeners[*ast.SelectStmt]
	SelectorExpr   listeners[*ast.SelectorExpr]
	SendStmt       listeners[*ast.SendStmt]
	SliceExpr      listeners[*ast.SliceExpr]
	StarExpr       listeners[*ast.StarExpr]
	StructType     listeners[*ast.StructType]
	SwitchStmt     listeners[*ast.SwitchStmt]
	TypeAssertExpr listeners[*ast.TypeAssertExpr]
	TypeSpec       listeners[*ast.TypeSpec]
	TypeSwitchStmt listeners[*ast.TypeSwitchStmt]
	UnaryExpr      listeners[*ast.UnaryExpr]
	ValueSpec      listeners[*ast.ValueSpec]
	// contains filtered or unexported fields
}

func NewInspector

func NewInspector(ops *InspectorOptions) *Inspector

NewInspector creates a new Inspector pointer with the given options

func (*Inspector) Visit

func (i *Inspector) Visit(n ast.Node) ast.Visitor

type InspectorOptions

type InspectorOptions struct {
	AvoidNil bool
}

type Listener

type Listener[T ast.Node] func(T)

Listener type is the callback that it will execute when the T node is detected

type ReturnCaseType added in v1.2.0

type ReturnCaseType int

Jump to

Keyboard shortcuts

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