parser

package
v2.0.0-...-a0386bf Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

Jump to

Keyboard shortcuts

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