parser

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check added in v0.1.9

func Check(code []byte) error

Check is a convenience function for tests to check Go code for syntax errors.

func FullName added in v0.1.5

func FullName(t Type) string

FullName does it's best to resolve the full name of a type

func Import added in v0.0.2

func Import(fsys fs.FS, dir string) (*build.Package, error)

func ImportPath

func ImportPath(t Type) (path string, err error)

ImportPath tries going to the type's definition

func IsBuiltin

func IsBuiltin(t Type) bool

IsBuiltin returns true if the type is built into Go

func IsImportType

func IsImportType(t Type, importPath, name string) (bool, error)

IsImportType checks if the type matches the import type

func TypeName

func TypeName(t Type) string

TypeName returns the name of the type

Types

type Alias

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

func (*Alias) Definition

func (a *Alias) Definition() (Declaration, error)

Definition goes to the aliases definition

func (*Alias) File

func (a *Alias) File() *File

func (*Alias) Kind

func (a *Alias) Kind() Kind

func (*Alias) Name

func (a *Alias) Name() string

func (*Alias) Package

func (a *Alias) Package() *Package

func (*Alias) Private

func (a *Alias) Private() bool

Private returns true if the field is private

func (*Alias) Type

func (a *Alias) Type() Type

type ArrayType

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

ArrayType struct

func (*ArrayType) Definition

func (t *ArrayType) Definition() (Declaration, error)

Definition returns the type definition

func (*ArrayType) ImportPath

func (t *ArrayType) ImportPath() (path string, err error)

ImportPath returns the import path if there is one

func (*ArrayType) Inner

func (t *ArrayType) Inner() Type

Inner type

func (*ArrayType) Name

func (t *ArrayType) Name() string

func (*ArrayType) Qualify

func (t *ArrayType) Qualify(qualifier string) Type

Qualify fn

func (*ArrayType) String

func (t *ArrayType) String() string

TODO: handle len in [len]elt

func (*ArrayType) Unqualify

func (t *ArrayType) Unqualify() Type

Unqualify returns the type if you were referring to it within the same package

type ChanType

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

ChanType struct

func (*ChanType) String

func (t *ChanType) String() string

String fn

type Declaration

type Declaration interface {
	Name() string
	Package() *Package
	Kind() Kind
}

Declaration interface

func Definition

func Definition(t Type) (Declaration, error)

Definition tries going to the type's definition

type EllipsisType

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

Ellipsis struct

func (*EllipsisType) Definition

func (t *EllipsisType) Definition() (Declaration, error)

Definition returns the declaration

func (*EllipsisType) ImportPath

func (t *EllipsisType) ImportPath() (path string, err error)

ImportPath returns the import path if there is one

func (*EllipsisType) Inner

func (t *EllipsisType) Inner() Type

Inner type

func (*EllipsisType) Name

func (t *EllipsisType) Name() string

func (*EllipsisType) String

func (t *EllipsisType) String() string

String fn

type Field

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

Field is a regular struct field

func (*Field) Definition

func (f *Field) Definition() (Declaration, error)

Definition gets the definition of the type

func (*Field) File

func (f *Field) File() *File

File that contains this field

func (*Field) Name

func (f *Field) Name() string

Name of the field

func (*Field) Private

func (f *Field) Private() bool

Private returns true if the field is private

func (*Field) Tags

func (f *Field) Tags() (tags Tags, err error)

Tags returns the field tags if there are any

func (*Field) Type

func (f *Field) Type() Type

Type of the field

type Fielder

type Fielder interface {
	File() *File
	Name() string
	Type() Type
}

Fielder is an interface containing the common operations on fields

type File

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

File struct

func (*File) Alias

func (f *File) Alias(name string) *Alias

func (*File) Aliases

func (f *File) Aliases() (aliases []*Alias)

func (*File) Function added in v0.2.8

func (f *File) Function(name string) *Function

Function returns a function by name

func (*File) Functions

func (f *File) Functions() (fns []*Function)

Functions returns all the functions in the file

func (*File) Import

func (f *File) Import() (path string, err error)

Import finds the import path of the package containing this file

func (*File) ImportName

func (f *File) ImportName(path string) (name string, err error)

ImportName finds an import name by import path

func (*File) ImportPath

func (f *File) ImportPath(name string) (path string, err error)

ImportPath finds an import path by import name

func (*File) Imports

func (f *File) Imports() (map[string]string, error)

Imports fn

func (*File) Interface

func (f *File) Interface(name string) *Interface

Interface returns an interface by name

func (*File) Interfaces

func (f *File) Interfaces() (ifaces []*Interface)

Interfaces returns all the interfaces in a file

func (*File) Package

func (f *File) Package() *Package

Package returns the package type

func (*File) Path

func (f *File) Path() string

Path returns the file path

func (*File) Struct

func (f *File) Struct(name string) *Struct

Struct returns a struct by name

func (*File) Structs

func (f *File) Structs() (stcts []*Struct)

Structs returns all the structs in a file

type FuncType

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

FuncType struct

func (*FuncType) String

func (t *FuncType) String() string

String fn

type Function

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

Function struct

func (*Function) File

func (fn *Function) File() *File

File returns file containing this function

func (*Function) Name

func (fn *Function) Name() string

Name of the function

func (*Function) Package

func (fn *Function) Package() *Package

Package returns the package containing this function

func (*Function) Params

func (fn *Function) Params() (fields []*Param)

Params returns parameters

func (*Function) Private

func (fn *Function) Private() bool

Private checks if the function is private or public

func (*Function) Receiver

func (fn *Function) Receiver() *Receiver

Receiver returns the receiver field, if any

func (*Function) Results

func (fn *Function) Results() (fields []*Result)

Results returns parameters

func (*Function) Signature

func (fn *Function) Signature() string

Signature returns the function signature

type IdentType

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

IdentType struct

func (*IdentType) Definition

func (t *IdentType) Definition() (Declaration, error)

Definition returns the type definition

func (*IdentType) ImportPath

func (t *IdentType) ImportPath() (path string, err error)

ImportPath returns the import path if there is one

func (*IdentType) Name

func (t *IdentType) Name() string

func (*IdentType) Qualify

func (t *IdentType) Qualify(qualifier string) Type

Qualify fn

func (*IdentType) String

func (t *IdentType) String() string

func (*IdentType) Unqualify

func (t *IdentType) Unqualify() Type

Unqualify identifier is the identifier

type Interface

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

Interface struct

func (*Interface) Directory

func (iface *Interface) Directory() string

Directory gets the directory

func (*Interface) File

func (iface *Interface) File() *File

File returns the file containing the struct

func (*Interface) Kind

func (iface *Interface) Kind() Kind

func (*Interface) Method

func (iface *Interface) Method(name string) *InterfaceMethod

func (*Interface) Methods

func (iface *Interface) Methods() (methods []*InterfaceMethod)

func (*Interface) Name

func (iface *Interface) Name() string

Name of the struct

func (*Interface) Package

func (iface *Interface) Package() *Package

Package name

type InterfaceMethod

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

func (*InterfaceMethod) File

func (im *InterfaceMethod) File() *File

func (*InterfaceMethod) Name

func (im *InterfaceMethod) Name() string

func (*InterfaceMethod) Params

func (im *InterfaceMethod) Params() (fields []*Param)

func (*InterfaceMethod) Results

func (im *InterfaceMethod) Results() (fields []*Result)

type InterfaceType

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

InterfaceType struct

func (*InterfaceType) String

func (t *InterfaceType) String() string

String fn

type Kind

type Kind uint8

Kind of declaration

const (
	KindBuiltin Kind = 1 + iota
	KindStruct
	KindInterface
)

func (Kind) String

func (k Kind) String() string

type MapType

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

MapType struct

func (*MapType) String

func (t *MapType) String() string

String fn

type Package

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

Package struct

func (*Package) Alias

func (pkg *Package) Alias(name string) *Alias

func (*Package) Aliases

func (pkg *Package) Aliases() (aliases []*Alias)

func (*Package) Directory

func (pkg *Package) Directory() string

Directory returns the directory of the package

func (*Package) FS

func (pkg *Package) FS() fs.FS

Module returns the module or fails

func (*Package) File added in v0.2.6

func (pkg *Package) File(name string) *File

File finds a file in the list

func (*Package) Files

func (pkg *Package) Files() []*File

Files returns a list of files

func (*Package) Function added in v0.2.8

func (pkg *Package) Function(name string) (fn *Function)

Functions returns all the functions in a package

func (*Package) Functions

func (pkg *Package) Functions() (fns []*Function)

Functions returns all the functions in a package

func (*Package) Import

func (pkg *Package) Import() (string, error)

Import returns the import path to this package

func (*Package) Interface

func (pkg *Package) Interface(name string) *Interface

func (*Package) Interfaces

func (pkg *Package) Interfaces() (ifaces []*Interface)

Interfaces returns all the interfaces in the package

func (*Package) Module

func (pkg *Package) Module() *gomod.Module

Module returns the module or fails

func (*Package) Name

func (pkg *Package) Name() string

Name of the package

func (*Package) Parser

func (pkg *Package) Parser() *Parser

func (*Package) PublicFunctions

func (pkg *Package) PublicFunctions() (fns []*Function)

PublicFunctions returns all public functions in the package

func (*Package) PublicMethods

func (pkg *Package) PublicMethods() (fns []*Function)

PublicMethods returns all public methods in the package

func (*Package) ResolveImport

func (pkg *Package) ResolveImport(directory string) (string, error)

ResolveImport resolves a directory from an import path

func (*Package) Struct

func (pkg *Package) Struct(name string) *Struct

Struct returns a struct by name

func (*Package) Structs

func (pkg *Package) Structs() (stcts []*Struct)

Structs returns all the structs in a package

type Param

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

Param is a function input

func (*Param) Definition

func (f *Param) Definition() (Declaration, error)

Definition gets the definition of the type

func (*Param) File

func (f *Param) File() *File

File that contains this field

func (*Param) Name

func (f *Param) Name() string

Name of the field

func (*Param) Private

func (f *Param) Private() bool

Private returns true if the field is private

func (*Param) String

func (f *Param) String() string

func (*Param) Type

func (f *Param) Type() Type

Type of the field

type Parser

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

Parser for parsing Go code.

func New

func New(fsys fs.FS, module *gomod.Module) *Parser

New Go parser.

func (*Parser) Import

func (p *Parser) Import(dir string) (*build.Package, error)

Import the package, taking into account build tags and file name conventions

func (*Parser) Parse

func (p *Parser) Parse(dir string) (*Package, error)

Parse a dir containing Go files.

type Receiver

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

Receiver is a function input

func (*Receiver) Definition

func (f *Receiver) Definition() (Declaration, error)

Definition gets the definition of the type

func (*Receiver) File

func (f *Receiver) File() *File

File that contains this field

func (*Receiver) Name

func (f *Receiver) Name() string

Name of the field

func (*Receiver) Private

func (f *Receiver) Private() bool

Private returns true if the field is private

func (*Receiver) String

func (f *Receiver) String() string

func (*Receiver) Type

func (f *Receiver) Type() Type

Type of the field

type Result

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

Result is a function output

func (*Result) Definition

func (f *Result) Definition() (Declaration, error)

func (*Result) File

func (f *Result) File() *File

File that contains this field

func (*Result) First

func (f *Result) First() bool

First result

func (*Result) IsError

func (f *Result) IsError() bool

IsError returns true if the field is an error TODO: eventually check if field implements error

func (*Result) Last

func (f *Result) Last() bool

Last result

func (*Result) Name

func (f *Result) Name() string

Name of the field

func (*Result) Named

func (f *Result) Named() bool

Named returns true if the result has a name

func (*Result) Private

func (f *Result) Private() bool

Private returns true if the field is private

func (*Result) String

func (f *Result) String() string

func (*Result) Type

func (f *Result) Type() Type

Type of the field

type SelectorType

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

SelectorType struct

func (*SelectorType) Definition

func (t *SelectorType) Definition() (Declaration, error)

Definition returns the type definition

func (*SelectorType) ImportPath

func (t *SelectorType) ImportPath() (path string, err error)

ImportPath returns the import path if there is one

func (*SelectorType) Name

func (t *SelectorType) Name() string

func (*SelectorType) Qualify

func (t *SelectorType) Qualify(qualifier string) Type

Qualify fn

func (*SelectorType) String

func (t *SelectorType) String() string

func (*SelectorType) Unqualify

func (t *SelectorType) Unqualify() Type

Unqualify returns the selector type

type SliceExpr

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

SliceExpr struct

func (*SliceExpr) String

func (t *SliceExpr) String() string

String fn

type StarType

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

StarType struct

func (*StarType) Definition

func (t *StarType) Definition() (Declaration, error)

Definition returns the type definition

func (*StarType) ImportPath

func (t *StarType) ImportPath() (path string, err error)

ImportPath returns the import path if there is one

func (*StarType) Inner

func (t *StarType) Inner() Type

Inner type

func (*StarType) Name

func (t *StarType) Name() string

func (*StarType) Qualify

func (t *StarType) Qualify(qualifier string) Type

Qualify fn

func (*StarType) String

func (t *StarType) String() string

func (*StarType) Unqualify

func (t *StarType) Unqualify() Type

Unqualify returns the local type

type Struct

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

Struct struct

func (*Struct) Directory

func (stct *Struct) Directory() string

Directory gets the directory

func (*Struct) Field

func (stct *Struct) Field(name string) *Field

func (*Struct) FieldAt

func (stct *Struct) FieldAt(nth int) (field *Field, err error)

FieldAt gets the field at i

func (*Struct) Fields

func (stct *Struct) Fields() (fields []*Field)

Fields function

func (*Struct) File

func (stct *Struct) File() *File

File returns the file containing the struct

func (*Struct) Kind

func (stct *Struct) Kind() Kind

func (*Struct) Method

func (stct *Struct) Method(name string) *Function

func (*Struct) Methods

func (stct *Struct) Methods() (methods []*Function)

func (*Struct) Name

func (stct *Struct) Name() string

Name of the struct

func (*Struct) Package

func (stct *Struct) Package() *Package

Package name

func (*Struct) Private

func (stct *Struct) Private() bool

Private returns true if the field is private

func (*Struct) PublicFields

func (stct *Struct) PublicFields() (fields []*Field)

PublicFields returns all public fields

func (*Struct) PublicMethods

func (stct *Struct) PublicMethods() (methods []*Function)

type StructType

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

StructType struct

func (*StructType) String

func (t *StructType) String() string

String fn

type Tag

type Tag struct {
	Key     string
	Value   string
	Options []string
}

Tag is a struct tag on a field

type Tags

type Tags []*Tag

func (Tags) Get

func (tags Tags) Get(key string) string

Get the tag value or return an empty string

func (Tags) Has

func (tags Tags) Has(key string) bool

Has checks if we have a tag with the given key

type Type

type Type interface {
	String() string
	// contains filtered or unexported methods
}

Type fn

func Innermost

func Innermost(t Type) Type

Innermost returns the innermost type e.g. []*ast.Package becomes ast.Package e.g. []*string becomes string

func Qualify

func Qualify(t Type, qualifier string) Type

Qualify adds a package to a type e.g. []*Package becomes []*ast.Package

func Requalify

func Requalify(t Type, replace string) Type

Requalify changes the type qualifier e.g. []*v8.VM becomes []*js.VM e.g. []*string becomes []*string

func Unqualify

func Unqualify(t Type) Type

Unqualify removes a package from a type e.g. []*ast.Package becomes []*Package

Jump to

Keyboard shortcuts

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