gopq

package
v1.0.32 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound - not found
	ErrNotFound = syscall.ENOENT
	// ErrBreak - break
	ErrBreak = syscall.ELOOP
	// ErrTooManyNodes - too may nodes
	ErrTooManyNodes = errors.New("too many nodes")
)

Functions

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() interface{}
}

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 NewSource

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

NewSource 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 os.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 NewSourceFrom

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

NewSourceFrom 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 os.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 Nodes

func Nodes(nodes ...Node) NodeSet

Nodes creates a fixed node set.

func One

func One(node Node) 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) Cache

func (p NodeSet) Cache() NodeSet

Cache caches 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

func (p NodeSet) CollectOne(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) ConstSpec

func (p NodeSet) ConstSpec() NodeSet

ConstSpec returns constants *ast.ValueSpec node set.

func (NodeSet) FuncDecl

func (p NodeSet) FuncDecl() NodeSet

FuncDecl returns *ast.FuncDecl node set.

func (NodeSet) GenDecl

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

GenDecl returns *ast.GenDecl node set.

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) 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) VarSpec

func (p NodeSet) VarSpec() NodeSet

VarSpec returns variables *ast.ValueSpec node set.

Jump to

Keyboard shortcuts

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