parser

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasMethods

func HasMethods(pStruct Struct, methodNames ...string) bool

func LoadPackages

func LoadPackages(packagePatterns ...string) (map[string]*types.Package, error)

Loads and type checks a package. Returns any errors encountered during loading or typechecking, otherwise returns the package's data. Useful for static type analysis with the types package instead of manually parsing the AST. A good explainer lives here: https://github.com/golang/example/tree/master/gotypes

Types

type Field

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

func (Field) IsLocalType

func (f Field) IsLocalType() bool

Returns true if the field's type originates from the same package its parent struct is defined in.

func (Field) LookupTag

func (f Field) LookupTag(key string) (string, bool)

func (Field) String

func (f Field) String() string

type Struct

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

func ParseStructs

func ParseStructs(pkg *types.Package) ([]Struct, error)

We can iterate over the declarations at the package level a single time to extract all the data necessary for generation. Any new data that needs to be added to the struct definitions can be extracted here.

func (Struct) Fields

func (s Struct) Fields() []Field

func (Struct) LocalTypes

func (s Struct) LocalTypes() []Type

func (Struct) Name

func (s Struct) Name() string

func (Struct) PrintWithFieldError

func (s Struct) PrintWithFieldError(fieldIndex int, errMsg string) string

func (Struct) String

func (s Struct) String() string

Pretty prints the struct name and its fields. Useful for debugging.

type Typ

type Typ = Type

type Type

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

func (Type) IsIterable

func (t Type) IsIterable() bool

Returns true if type is slice or array

func (Type) IsPointer

func (t Type) IsPointer() bool

func (Type) IsStruct

func (t Type) IsStruct() bool

func (Type) Name

func (t Type) Name() string

func (Type) PackageName

func (t Type) PackageName() string

func (Type) Position

func (t Type) Position() int

Position in the Package the type object was parsed from

func (Type) ToStructType

func (t Type) ToStructType() Struct

func (Type) Type

func (t Type) Type() string

e.g. ccc.UUID, []ccc.UUID

func (Type) TypeName

func (t Type) TypeName() string

Qualified type without array/slice/pointer prefix. e.g. *ccc.UUID -> ccc.UUID, []ccc.UUID -> ccc.UUID

func (Type) UnqualifiedType

func (t Type) UnqualifiedType() string

Type without package prefix. e.g. ccc.UUID -> UUID, []ccc.UUID -> []UUID

func (Type) UnqualifiedTypeName

func (t Type) UnqualifiedTypeName() string

Type without array/slice/pointer or package prefix. e.g. *ccc.UUID -> UUID, []ccc.UUID -> UUID

Jump to

Keyboard shortcuts

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