golang

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XGoPackage = "github.com/goplus/xgo/dql/reflects"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Mode parser.Mode
	Fset *token.FileSet
}

Config represents the configuration for parsing Go source code.

type File

type File struct {
	ast.File
}

File represents a Go file.

func ParseFile

func ParseFile(filename string, src any, conf ...Config) (f *File, err error)

ParseFile parses Go source code from the given filename or source, returning a File object. An optional Config can be provided to customize the parsing behavior.

func (*File) XGo_Any

func (f *File) XGo_Any(name string) NodeSet

XGo_Any returns a NodeSet containing all descendant nodes (including the node itself) with the specified name. If name is "", it returns all nodes.

  • .**.name
  • .**.“element-name”
  • .**.*

func (*File) XGo_Child

func (f *File) XGo_Child() NodeSet

XGo_Child returns a NodeSet containing all child nodes of the node.

  • .*

func (*File) XGo_Elem

func (f *File) XGo_Elem(name string) NodeSet

XGo_Elem returns a NodeSet containing the child nodes with the specified name.

  • .name
  • .“element-name”

type Node

type Node = reflects.Node

Node represents a Go AST node.

type NodeSet

type NodeSet struct {
	reflects.NodeSet
}

NodeSet represents a set of Go AST nodes.

func From

func From(uri string, src any, conf ...Config) NodeSet

From parses Go source code from the given URI or source, returning a NodeSet. An optional Config can be provided to customize the parsing behavior.

func New

func New(f *ast.File) NodeSet

New creates a NodeSet from the given *ast.File.

func NodeSet_Cast

func NodeSet_Cast(seq iter.Seq[Node]) NodeSet

NodeSet(seq) casts a NodeSet from a sequence of nodes.

func Nodes

func Nodes(nodes ...Node) NodeSet

Nodes creates a NodeSet containing the provided nodes.

func Root

func Root(doc Node) NodeSet

Root creates a NodeSet containing the provided root node.

func Source

func Source(r any, conf ...Config) (ret NodeSet)

Source creates a NodeSet from various types of Go sources. It supports the following source types: - string: treats the string as a URI, opens the resource, and reads Go source code from it. - []byte: treated as Go source code. - *bytes.Buffer: treated as Go source code. - io.Reader: treated as Go source code. - *ast.File: creates a NodeSet from the provided *ast.File. - reflect.Value: creates a NodeSet from the provided reflect.Value (expected to be *ast.File). - Node: creates a NodeSet containing the single provided node. - iter.Seq[Node]: returns the provided sequence as a NodeSet. - NodeSet: returns the provided NodeSet as is. If the source type is unsupported, it panics.

func (NodeSet) All

func (p NodeSet) All() NodeSet

All returns a NodeSet containing all nodes. It's a cache operation for performance optimization when you need to traverse the nodes multiple times.

func (NodeSet) Class

func (p NodeSet) Class() string

Class returns the class name of the first node in the NodeSet.

func (NodeSet) Ok added in v1.6.5

func (p NodeSet) Ok() bool

Ok returns true if there is no error in the NodeSet.

func (NodeSet) One

func (p NodeSet) One() NodeSet

One returns a NodeSet containing the first node. It's a performance optimization when you only need the first node (stop early).

func (NodeSet) Single

func (p NodeSet) Single() NodeSet

Single returns a NodeSet containing the single node. If there are zero or more than one nodes, it returns an error. ErrNotFound or ErrMultipleResults is returned accordingly.

func (NodeSet) XGo_Any

func (p NodeSet) XGo_Any(name string) NodeSet

XGo_Any returns a NodeSet containing all descendant nodes (including the nodes themselves) with the specified name. If name is "", it returns all nodes.

  • .**.name
  • .**.“element-name”
  • .**.*

func (NodeSet) XGo_Attr__0

func (p NodeSet) XGo_Attr__0(name string) any

XGo_Attr returns the value of the specified attribute from the first node in the NodeSet. It only retrieves the attribute from the first node.

  • $name
  • $“attr-name”

func (NodeSet) XGo_Attr__1

func (p NodeSet) XGo_Attr__1(name string) (val any, err error)

XGo_Attr returns the value of the specified attribute from the first node in the NodeSet. It only retrieves the attribute from the first node.

  • $name
  • $“attr-name”

func (NodeSet) XGo_Child

func (p NodeSet) XGo_Child() NodeSet

XGo_Child returns a NodeSet containing all child nodes of the nodes in the NodeSet.

func (NodeSet) XGo_Elem

func (p NodeSet) XGo_Elem(name string) NodeSet

XGo_Elem returns a NodeSet containing the child nodes with the specified name.

  • .name
  • .“element-name”

func (NodeSet) XGo_Enum

func (p NodeSet) XGo_Enum() iter.Seq[NodeSet]

XGo_Enum returns an iterator over the nodes in the NodeSet.

func (NodeSet) XGo_Select

func (p NodeSet) XGo_Select(name string) NodeSet

XGo_Select returns a NodeSet containing the nodes with the specified name.

  • @name
  • @"element-name"

Jump to

Keyboard shortcuts

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