tools

package
v2.8.9 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2018 License: Apache-2.0 Imports: 11 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter deprecated

func Filter(node *uast.Node, xpath string) ([]*uast.Node, error)

Filter takes a `*uast.Node` and a xpath query and filters the tree, returning the list of nodes that satisfy the given query. Filter is thread-safe but not concurrent by an internal global lock.

Deprecated: use Context.Filter

func FilterBool deprecated added in v2.3.0

func FilterBool(node *uast.Node, xpath string) (bool, error)

FilterBool takes a `*uast.Node` and a xpath query with a boolean return type (e.g. when using XPath functions returning a boolean type). FilterBool is thread-safe but not concurrent by an internal global lock.

Deprecated: use Context.FilterBool

func FilterNumber deprecated added in v2.3.0

func FilterNumber(node *uast.Node, xpath string) (float64, error)

FilterNumber takes a `*uast.Node` and a xpath query with a float return type (e.g. when using XPath functions returning a float type). FilterNumber is thread-safe but not concurrent by an internal global lock.

Deprecated: use Context.FilterNumber

func FilterString deprecated added in v2.3.0

func FilterString(node *uast.Node, xpath string) (string, error)

FilterString takes a `*uast.Node` and a xpath query with a string return type (e.g. when using XPath functions returning a string type). FilterString is thread-safe but not concurrent by an internal global lock.

Deprecated: use Context.FilterString

func FilterXPath added in v2.8.7

func FilterXPath(node nodes.External, query string) (query.Iterator, error)

FilterXPath is a shorthand for Context.FilterXPath.

Types

type Context added in v2.8.0

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

func NewContext added in v2.8.0

func NewContext() *Context

NewContext creates a new query context. Caller should close the context to release resources.

func (*Context) Close added in v2.8.0

func (c *Context) Close() error

func (*Context) Filter added in v2.8.0

func (c *Context) Filter(node *uast.Node, xpath string) (out []*uast.Node, err error)

Filter takes a `*uast.Node` and a xpath query and filters the tree, returning the list of nodes that satisfy the given query. Filter is thread-safe but not concurrent by an internal global lock.

func (*Context) FilterBool added in v2.8.0

func (c *Context) FilterBool(node *uast.Node, xpath string) (out bool, err error)

FilterBool takes a `*uast.Node` and a xpath query with a boolean return type (e.g. when using XPath functions returning a boolean type). FilterBool is thread-safe but not concurrent by an internal global lock.

func (*Context) FilterNumber added in v2.8.0

func (c *Context) FilterNumber(node *uast.Node, xpath string) (out float64, err error)

FilterNumber takes a `*uast.Node` and a xpath query with a float return type (e.g. when using XPath functions returning a float type). FilterNumber is thread-safe but not concurrent by an internal global lock.

func (*Context) FilterString added in v2.8.0

func (c *Context) FilterString(node *uast.Node, xpath string) (out string, err error)

FilterString takes a `*uast.Node` and a xpath query with a string return type (e.g. when using XPath functions returning a string type). FilterString is thread-safe but not concurrent by an internal global lock.

func (*Context) FilterXPath added in v2.8.7

func (c *Context) FilterXPath(node nodes.External, query string) (query.Iterator, error)

FilterXPath takes a `Node` as returned by UAST() call and an xpath query and filters the tree, returning the iterator of nodes that satisfy the given query.

func (*Context) NewIterator added in v2.8.0

func (c *Context) NewIterator(node *uast.Node, order TreeOrder) (*Iterator, error)

NewIterator constructs a new Iterator starting from the given `Node` and iterating with the traversal strategy given by the `order` parameter. Once the iteration have finished or you don't need the iterator anymore you must dispose it with the Dispose() method (or call it with `defer`).

type ErrInvalidArgument added in v2.6.1

type ErrInvalidArgument struct {
	Message string
}

func (*ErrInvalidArgument) Error added in v2.6.1

func (e *ErrInvalidArgument) Error() string

type Iterator added in v2.2.0

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

Iterator allows for traversal over a UAST tree.

func NewIterator added in v2.2.0

func NewIterator(node *uast.Node, order TreeOrder) (*Iterator, error)

NewIterator constructs a new Iterator starting from the given `Node` and iterating with the traversal strategy given by the `order` parameter. Once the iteration have finished or you don't need the iterator anymore you must dispose it with the Dispose() method (or call it with `defer`).

func (*Iterator) Close added in v2.8.0

func (it *Iterator) Close() error

Close must be called once you've finished using the iterator or preventively with `defer` to free the iterator resources. Failing to do so would produce a memory leak.

func (*Iterator) Dispose deprecated added in v2.2.0

func (it *Iterator) Dispose()

Dispose must be called once you've finished using the iterator or preventively with `defer` to free the iterator resources. Failing to do so would produce a memory leak.

Deprecated: use Close

func (*Iterator) Iterate added in v2.2.0

func (it *Iterator) Iterate() <-chan *uast.Node

Iterate function is similar to Next() but returns the `Node`s in a channel. It's mean to be used with the `for node := range myIter.Iterate() {}` loop.

func (*Iterator) Next added in v2.2.0

func (it *Iterator) Next() (*uast.Node, error)

Next retrieves the next `Node` in the tree's traversal or `nil` if there are no more nodes. Calling `Next()` on a finished iterator after the first `nil` will return an error.This is thread-safe but not concurrent by an internal global lock.

type TreeOrder added in v2.2.0

type TreeOrder int

TreeOrder represents the traversal strategy for UAST trees

const (
	// PreOrder traversal
	PreOrder TreeOrder = iota
	// PostOrder traversal
	PostOrder
	// LevelOrder (aka breadth-first) traversal
	LevelOrder
	// PositionOrder by node position in the source file
	PositionOrder
)

Jump to

Keyboard shortcuts

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