gopq

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GopPackage = true
)

Variables

View Source
var (
	// ErrBreak - break
	ErrBreak = syscall.ELOOP

	// ErrNotFound - not found
	ErrNotFound = errors.New("not found")

	// ErrTooManyNodes - too may nodes
	ErrTooManyNodes = errors.New("too many nodes")

	// ErrUnexpectedNode - unexpected node
	ErrUnexpectedNode = errors.New("unexpected node")
)

Functions

func CodeOf added in v1.3.2

func CodeOf(fset *token.FileSet, f *ast.File, start, end token.Pos) string

func NameOf

func NameOf(node Node) string

NameOf returns name of an ast node.

Types

type Node

type Node interface {
	ast.Node
	ForEach(filter func(node Node) error) error
	Obj() any
}

Node - node interface

type NodeEnum

type NodeEnum interface {
	ForEach(filter func(node Node) error) error
}

NodeEnum - node enumerator

type NodeSet

type NodeSet struct {
	Data NodeEnum
	Err  error
}

NodeSet - node set

func FromDir added in v1.3.2

func FromDir(
	fset *token.FileSet, path string,
	filter func(fs.FileInfo) bool, mode parser.Mode) (doc NodeSet, err error)

FromDir calls ParseFile for all files with names ending in ".gop" in the directory specified by path and returns a map of package name -> package AST with all the packages found.

If filter != nil, only the files with fs.FileInfo entries passing through the filter (and ending in ".gop") are considered. The mode bits are passed to ParseFile unchanged. Position information is recorded in fset, which must not be nil.

If the directory couldn't be read, a nil map and the respective error are returned. If a parse error occurred, a non-nil but incomplete map and the first error encountered are returned.

func FromFSDir added in v1.3.2

func FromFSDir(
	fset *token.FileSet, fs parser.FileSystem, path string,
	filter func(fs.FileInfo) bool, mode parser.Mode) (doc NodeSet, err error)

FromFSDir calls ParseFile for all files with names ending in ".gop" in the directory specified by path and returns a map of package name -> package AST with all the packages found.

If filter != nil, only the files with fs.FileInfo entries passing through the filter (and ending in ".gop") are considered. The mode bits are passed to ParseFile unchanged. Position information is recorded in fset, which must not be nil.

If the directory couldn't be read, a nil map and the respective error are returned. If a parse error occurred, a non-nil but incomplete map and the first error encountered are returned.

func FromFSFile added in v1.3.2

func FromFSFile(
	fset *token.FileSet, fs fsx.FileSystem,
	filename string, src any, mode parser.Mode) (doc NodeSet, err error)

FromFSFile calls ParseFSFile for a single file and returns *ast.File node set.

func FromFile added in v1.3.2

func FromFile(fset *token.FileSet, filename string, src any, mode parser.Mode) (doc NodeSet, err error)

FromFile calls ParseFile for a single file and returns *ast.File node set.

func Nodes

func Nodes(nodes ...Node) NodeSet

Nodes creates a fixed node set.

func One__0 added in v1.3.2

func One__0(node Node) NodeSet

One creates a node set that only contains a signle node.

func One__1 added in v1.3.2

func One__1(f *ast.File) NodeSet

One creates a node set that only contains a signle node.

func One__2 added in v1.3.2

func One__2(pkg *ast.Package) NodeSet

One creates a node set that only contains a signle node.

func (NodeSet) Any

func (p NodeSet) Any() (ret NodeSet)

Any returns deeply visiting node set.

func (NodeSet) Arg added in v1.3.2

func (p NodeSet) Arg(i int) NodeSet

Arg returns args[i] node set.

func (NodeSet) AssignStmt added in v1.3.2

func (p NodeSet) AssignStmt() NodeSet

AssignStmt returns *ast.AssignStmt node set.

func (NodeSet) Body added in v1.3.2

func (p NodeSet) Body() NodeSet

Body returns body node set.

func (NodeSet) Cache

func (p NodeSet) Cache() NodeSet

Cache caches node set.

func (NodeSet) CallExpr__0 added in v1.3.2

func (p NodeSet) CallExpr__0() NodeSet

CallExpr returns *ast.CallExpr node set.

func (NodeSet) CallExpr__1 added in v1.3.2

func (p NodeSet) CallExpr__1(name string) NodeSet

CallExpr returns *ast.CallExpr node set.

func (NodeSet) Child

func (p NodeSet) Child() NodeSet

Child returns child node set.

func (NodeSet) Collect

func (p NodeSet) Collect() (items []Node, err error)

Collect collects all nodes of the node set.

func (NodeSet) CollectOne__0 added in v1.3.2

func (p NodeSet) CollectOne__0() (item Node, err error)

CollectOne returns the first node.

func (NodeSet) CollectOne__1 added in v1.3.2

func (p NodeSet) CollectOne__1(exactly bool) (item Node, err error)

CollectOne collects one node of a node set. If exactly is true, it returns ErrTooManyNodes when node set is more than one.

func (NodeSet) CompositeLit__0 added in v1.3.2

func (p NodeSet) CompositeLit__0() NodeSet

CompositeLit returns *ast.CompositeLit node set.

func (NodeSet) CompositeLit__1 added in v1.3.2

func (p NodeSet) CompositeLit__1(name string) NodeSet

CompositeLit returns *ast.CompositeLit node set.

func (NodeSet) EltLen__0 added in v1.3.2

func (p NodeSet) EltLen__0() (ret int, err error)

func (NodeSet) EltLen__1 added in v1.3.2

func (p NodeSet) EltLen__1(exactly bool) (ret int, err error)

func (NodeSet) Elt__0 added in v1.3.2

func (p NodeSet) Elt__0(i int) NodeSet

Elt returns elts[i] node set.

func (NodeSet) Elt__1 added in v1.3.2

func (p NodeSet) Elt__1() NodeSet

Elt returns elts[:] node set.

func (NodeSet) Elt__2 added in v1.3.2

func (p NodeSet) Elt__2(name string) NodeSet

Elt returns elts[name] node set.

func (NodeSet) ExprStmt added in v1.3.2

func (p NodeSet) ExprStmt() NodeSet

ExprStmt returns *ast.ExprStmt node set.

func (NodeSet) ForEach added in v1.3.2

func (p NodeSet) ForEach(callback func(node NodeSet))

func (NodeSet) Fun added in v1.3.2

func (p NodeSet) Fun() NodeSet

Fun returns fun node set.

func (NodeSet) FuncDecl__0 added in v1.3.2

func (p NodeSet) FuncDecl__0() NodeSet

FuncDecl returns *ast.FuncDecl node set.

func (NodeSet) FuncDecl__1 added in v1.3.2

func (p NodeSet) FuncDecl__1(name string) NodeSet

FuncDecl returns *ast.FuncDecl node set.

func (NodeSet) Funcs added in v1.3.2

func (p NodeSet) Funcs() NodeSet

Funcs returns all `*ast.FuncDecl` nodes.

func (NodeSet) GenDecl__0 added in v1.3.2

func (p NodeSet) GenDecl__0(tok token.Token) NodeSet

GenDecl returns *ast.GenDecl node set.

func (NodeSet) Gop_Enum added in v1.3.2

func (p NodeSet) Gop_Enum(callback func(node NodeSet))

func (NodeSet) Ident__0 added in v1.3.2

func (p NodeSet) Ident__0() (ret string, err error)

func (NodeSet) Ident__1 added in v1.3.2

func (p NodeSet) Ident__1(exactly bool) (ret string, err error)

func (NodeSet) ImportSpec

func (p NodeSet) ImportSpec() NodeSet

ImportSpec returns *ast.ImportSpec node set.

func (NodeSet) Match

func (p NodeSet) Match(match func(node Node) bool) (ret NodeSet)

Match filters the node set.

func (NodeSet) Name

func (p NodeSet) Name() []string

Name returns names of the node set.

func (NodeSet) Ok

func (p NodeSet) Ok() bool

Ok returns if node set is valid or not.

func (NodeSet) One

func (p NodeSet) One() NodeSet

One returns the first node as a node set.

func (NodeSet) Positions__0 added in v1.3.2

func (p NodeSet) Positions__0() (ret []token.Pos, err error)

func (NodeSet) Positions__1 added in v1.3.2

func (p NodeSet) Positions__1(exactly bool) (ret []token.Pos, err error)

func (NodeSet) Rhs added in v1.3.2

func (p NodeSet) Rhs(i int) NodeSet

Rhs returns rhs[i] node set.

func (NodeSet) ToString

func (p NodeSet) ToString(str func(node Node) string) (items []string)

ToString returns string values of the node set.

func (NodeSet) TypeSpec

func (p NodeSet) TypeSpec() NodeSet

TypeSpec returns *ast.TypeSpec node set.

func (NodeSet) UnquotedStringElts__0 added in v1.3.2

func (p NodeSet) UnquotedStringElts__0() (ret []string, err error)

func (NodeSet) UnquotedStringElts__1 added in v1.3.2

func (p NodeSet) UnquotedStringElts__1(exactly bool) (ret []string, err error)

func (NodeSet) UnquotedString__0 added in v1.3.2

func (p NodeSet) UnquotedString__0() (ret string, err error)

func (NodeSet) UnquotedString__1 added in v1.3.2

func (p NodeSet) UnquotedString__1(exactly bool) (ret string, err error)

func (NodeSet) ValueSpec added in v1.3.2

func (p NodeSet) ValueSpec() NodeSet

ValueSpec returns *ast.ValueSpec node set.

func (NodeSet) Varg added in v1.3.2

func (p NodeSet) Varg(i int) NodeSet

Varg returns args[i:] node set.

func (NodeSet) X added in v1.3.2

func (p NodeSet) X() NodeSet

X returns x node set.

Jump to

Keyboard shortcuts

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