parser

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPkg a common package error.
	ErrPkg = errors.New("parser")
	// ErrPkgLoad error.
	ErrPkgLoad = fmt.Errorf("%w: unable to load packages", ErrPkg)
	// ErrRootPathNormalise error.
	ErrRootPathNormalise = fmt.Errorf("%w: unable to normalise the root path", ErrPkgLoad)
	// ErrGetRelPath error.
	ErrGetRelPath = fmt.Errorf("%w: unable to get relative path", ErrPkg)
)

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name string
	Type *TypeDesc
}

type CodeMap

type CodeMap[V *Var, T *Type, F *Func, C *Const] struct {
	Var   []V
	Type  []T
	Func  []F
	Const []C
}

type Const

type Const struct {
	FilePath    string
	Start       *Position
	End         *Position
	PackageName string
	PackagePath string
	Name        string
	Type        *TypeDesc
	TypeInfo    string
	IsExported  bool
	Doc         string
}

type DefaultParser

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

DefaultParser default parser service.

func New

func New(options ...Option) *DefaultParser

New factory function.

func (*DefaultParser) Parse

func (p *DefaultParser) Parse(path string) (*CodeMap[*Var, *Type, *Func, *Const], error)

Parse function to scan and parse a provided path.

type Field

type Field struct {
	Name       string
	Type       *TypeDesc
	IsExported bool
	Tags       *Tags
	Doc        string
}

type Func

type Func struct {
	FilePath    string
	Start       *Position
	End         *Position
	PackageName string
	PackagePath string
	Name        string
	Signature   *Signature
	Params      *Params
	IsExported  bool
	Doc         string
}

type Interface

type Interface struct {
	Name        string
	PackageName string
	PackagePath string
	// contains filtered or unexported fields
}
type Link struct {
	Name         string
	Underlying   string
	PackageName  string
	PackagePath  string
	PackageAlias string
}

type Method

type Method struct {
	FilePath          string
	Start             *Position
	End               *Position
	Name              string
	Signature         *Signature
	IsPointerReceiver bool
	IsExported        bool
	Doc               string
}

type Option

type Option func(p *DefaultParser)

Option function.

func WithDocParser

func WithDocParser(docParser doc.Parser) Option

WithDocParser configuration option.

func WithRootPath

func WithRootPath(rootPath string) Option

WithRootPath configuration option.

type Param

type Param struct {
	Name      string
	Constrain *TypeDesc
}

type Params

type Params struct {
	Label string
	List  []*Param
}

type Parser

type Parser interface {
	Parse(pkgPath string) (map[string][]any, error)
}

Parser code packages parser.

type Position

type Position struct {
	Offset int
	Line   int
	Column int
}

type Return

type Return struct {
	Name string
	Type *TypeDesc
}

type Signature

type Signature struct {
	Label     string
	Alt       string
	Arguments []*Argument
	Returns   []*Return
	Links     []*Link
}

type Tag

type Tag struct {
	Name  string
	Value string
}

type Tags

type Tags struct {
	Label string
	Tags  []*Tag
}

type Type

type Type struct {
	FilePath    string
	Start       *Position
	End         *Position
	PackageName string
	PackagePath string
	Name        string
	Type        *TypeDesc
	TypeInfo    string
	IsTypeAlias bool
	Interfaces  []*Interface
	Embedded    []*TypeDesc
	Params      *Params
	Fields      []*Field
	Methods     []*Method
	IsExported  bool
	Doc         string
}

type TypeDesc

type TypeDesc struct {
	Label string
	Links []*Link
}

type Var

type Var struct {
	FilePath    string
	Start       *Position
	End         *Position
	PackageName string
	PackagePath string
	Name        string
	Type        *TypeDesc
	TypeInfo    string
	Params      *Params
	IsExported  bool
	Doc         string
}

Jump to

Keyboard shortcuts

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