package parser

import "k8s.io/gengo/v2/parser"

Package parser provides code to parse go files, type-check them, extract the types.

Index

Types

type Options

type Options struct {
	// BuildTags is a list of optional tags to be specified when loading
	// packages.
	BuildTags []string
}

Options holds optional settings for the Parser.

type Parser

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

Parser lets you add all the go files in all the packages that you care about, then constructs the type source data.

func New

func New() *Parser

New constructs a new Parser.

func NewWithOptions

func NewWithOptions(opts Options) *Parser

func (*Parser) FindPackages

func (p *Parser) FindPackages(patterns ...string) ([]string, error)

FindPackages expands the provided patterns into a list of Go import-paths, much like `go list -find`.

func (*Parser) LoadPackages

func (p *Parser) LoadPackages(patterns ...string) error

LoadPackages loads and parses the specified Go packages. Specifically named packages (without a trailing "/...") which do not exist or have no Go files are an error.

func (*Parser) LoadPackagesTo

func (p *Parser) LoadPackagesTo(u *types.Universe, patterns ...string) ([]*types.Package, error)

LoadPackagesTo loads and parses the specified Go packages, and inserts them into the specified Universe. It returns the packages which match the patterns, but loads all packages and their imports, recursively, into the universe. See NewUniverse for more.

func (*Parser) LoadPackagesWithConfigForTesting

func (p *Parser) LoadPackagesWithConfigForTesting(cfg *packages.Config, patterns ...string) error

LoadPackagesWithConfigForTesting loads and parses the specified Go packages with the specified packages.Config as a starting point. This is for testing, and only the .Dir and .Env fields of the Config will be considered.

func (*Parser) NewUniverse

func (p *Parser) NewUniverse() (types.Universe, error)

NewUniverse finalizes the loaded packages, searches through them for types and produces a new Universe. The returned Universe has one types.Package entry for each Go package that has been loaded, including all of their dependencies, recursively. It also has one entry, whose key is "", which represents "builtin" types.

func (*Parser) UserRequestedPackages

func (p *Parser) UserRequestedPackages() []string

UserRequestedPackages fetches a list of the user-imported packages.

Source Files

doc.go parse.go parse_122.go

Directories

PathSynopsis
parser/tags
Version
v2.0.0-20250207200755-1244d31929d7 (latest)
Published
Feb 7, 2025
Platform
linux/amd64
Imports
13 packages
Last checked
2 weeks ago

Tools for package owners.