parser

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExampleDeprecationNote deprecated added in v1.1.0

func ExampleDeprecationNote()

ExampleDeprecationNote is an example of a deprecated function

Deprecated: This function is deprecated only for demonstration purposes

func GetPackages

func GetPackages() ([]string, error)

Load and return a list of Go package directories from the current project. Exclude the root directory and only include directories containing Go files.

Returns: Package directory paths and an error if any occurs

Example:

packages, err := parser.GetPackages()
if err != nil {
	log.Fatalf("Error fetching packages: %v", err)
}
for _, pkg := range packages {
	fmt.Printf("Package: %s\n", pkg)
}

func ParseEntitiesInPackage

func ParseEntitiesInPackage(projectPath string, pkgPath string, relativePath string) ([]EntityInfo, []ImportInfo, error)

Parse Go source files in the specified package directory, extracting function, method, type, struct, and interface information. Also gather import details and associate methods with structs. Resolve interface implementations and find references for each entity.

Returns: Entity and import information, and an error if any occurs

Example:

entities, err := parser.ParseEntitiesInPackage("/home/me/myproject/pkg/mypackage")
if err != nil {
	log.Fatalf("Error parsing entities: %v", err)
}
for _, entity := range entities {
	fmt.Printf("Name: %s\n", entity.Name)
	fmt.Printf("Type: %s\n", entity.Type)
	fmt.Printf("Description: %s\n", entity.Description)
	fmt.Printf("Package: %s\n", entity.Package)
}

Notes: The package must be a full path to the package directory

Types

type DescriptionData added in v1.1.0

type DescriptionData struct {
	Description     string
	Example         string
	Notes           string
	DeprecationNote string
	Returns         string

	// Raw fields
	DescriptionRaw     string
	DeprecationNoteRaw string
}

Holds different parts of a function's documentation comment

type EntityExtractor added in v1.1.0

type EntityExtractor interface {
	Extract(decl ast.Decl, fs *token.FileSet, interfaces map[string]EntityInfo, pkgName string, packagePath string, url string) EntityInfo
}

Define an interface for extracting information from AST declarations

Returns: EntityInfo struct

type EntityInfo

type EntityInfo struct {
	Name            string
	Description     string
	Example         string
	Notes           string
	DeprecationNote string
	Parameters      []string
	Returns         []string
	Body            string
	Type            string
	Fields          []FieldInfo
	Methods         []EntityInfo
	Implements      []ImplementationInfo
	Package         string
	PackageURL      string
	PackagePath     string
	References      []ReferenceInfo

	// Raw fields
	DescriptionRaw     string
	DeprecationNoteRaw string
}

Information about each entity in the package (functions, types, interfaces)

type FieldInfo added in v1.1.0

type FieldInfo struct {
	Name string
	Type string
	Tag  string
}

Information about each field in a struct

type FunctionExtractor added in v1.1.0

type FunctionExtractor struct{}

Extract function details from a function declaration.

Returns: An EntityInfo struct with extracted details about the function

func (FunctionExtractor) Extract added in v1.1.0

func (f FunctionExtractor) Extract(decl ast.Decl, fs *token.FileSet, interfaces map[string]EntityInfo, pkgName string, packagePath string, url string) EntityInfo

type ImplementationInfo added in v1.1.0

type ImplementationInfo struct {
	InterfaceName string
	Package       string
}

Information about an implemented interface

type ImportInfo added in v1.1.1

type ImportInfo struct {
	URL     string
	Path    string
	Alias   string
	Doc     string
	Comment string
}

Information about an imported package

type InterfaceExtractor added in v1.1.0

type InterfaceExtractor struct{}

Extract interface details from an interface declaration.

Returns: An EntityInfo struct with extracted details about the interface

func (InterfaceExtractor) Extract added in v1.1.0

func (i InterfaceExtractor) Extract(decl ast.Decl, fs *token.FileSet, interfaces map[string]EntityInfo, pkgName string, packagePath string, url string) EntityInfo

type MethodExtractor added in v1.1.1

type MethodExtractor struct{}

Extract method details from a method declaration.

Returns: An EntityInfo struct with extracted details about the method

func (MethodExtractor) Extract added in v1.1.1

func (m MethodExtractor) Extract(decl ast.Decl, fs *token.FileSet, interfaces map[string]EntityInfo, pkgName string, packagePath string, url string) EntityInfo

type ReferenceInfo added in v1.1.1

type ReferenceInfo struct {
	Name        string
	Package     string
	PackageURL  string
	PackagePath string
}

Information about references used by an entity

type StructExtractor added in v1.1.0

type StructExtractor struct{}

Extract struct details from a struct declaration.

Returns: An EntityInfo struct with extracted details about the struct

func (StructExtractor) Extract added in v1.1.0

func (s StructExtractor) Extract(decl ast.Decl, fs *token.FileSet, interfaces map[string]EntityInfo, pkgName string, packagePath string, url string) EntityInfo

type TypeExtractor added in v1.1.0

type TypeExtractor struct{}

Extract type details from a type declaration.

Returns: An EntityInfo struct with details about the type

func (TypeExtractor) Extract added in v1.1.0

func (t TypeExtractor) Extract(decl ast.Decl, fs *token.FileSet, interfaces map[string]EntityInfo, pkgName string, packagePath string, url string) EntityInfo

Jump to

Keyboard shortcuts

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