parser

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetModulePath

func GetModulePath() (string, error)

GetModulePath returns the module path from go.mod in the current directory or parent directories

func GetPackageDir

func GetPackageDir(pkgPath string) (string, error)

GetPackageDir uses `go list` to get the directory of a package

func QuickScanForDirectives

func QuickScanForDirectives(filePath string) (bool, error)

QuickScanForDirectives does a fast text-based scan to check if a file might contain piccolo directives

func ResolvePackagePath

func ResolvePackagePath(relativePath string) (string, error)

ResolvePackagePath resolves a relative package path to a full import path

func ScanDirectory

func ScanDirectory(root string) ([]string, error)

ScanDirectory recursively scans a directory for Go files with piccolo directives

Types

type InterfaceDirective

type InterfaceDirective struct {
	FilePath      string            // Path to the file containing the interface
	InterfaceName string            // Name of the interface
	PackagePath   string            // Package path from // piccolo: package <path>
	StructNames   []string          // Struct names from // piccolo: struct A, B, C
	MethodNames   []string          // Method names from // piccolo: method X, Y, Z
	ImportAliases map[string]string // Import aliases from // piccolo: import-alias <pkg> <alias>
	HasMarkers    bool              // Whether // piccolo:start and // piccolo:end markers exist
	StartPos      int               // Byte position of interface body start (after '{')
	EndPos        int               // Byte position of interface body end (before '}')
	MarkerStart   int               // Byte position after // piccolo:start line (if markers exist)
	MarkerEnd     int               // Byte position before // piccolo:end line (if markers exist)
}

InterfaceDirective represents a parsed piccolo directive for an interface

func ParseFile

func ParseFile(filePath string) ([]*InterfaceDirective, error)

ParseFile parses a Go file and returns all interface directives found

type MethodInfo

type MethodInfo struct {
	StructName string // The struct this method belongs to
	Signature  string // The method signature (name + params + returns)
}

MethodInfo holds information about a method

type PackageCache

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

PackageCache caches parsed package information

func NewPackageCache

func NewPackageCache() *PackageCache

NewPackageCache creates a new package cache

func (*PackageCache) ExtractMethods

func (c *PackageCache) ExtractMethods(pkgPath string, structNames []string, methodNames []string) ([]string, error)

ExtractMethods extracts the specified methods from a package

func (*PackageCache) LoadPackage

func (c *PackageCache) LoadPackage(pkgPath string) (*PackageInfo, error)

LoadPackage loads and parses a package, extracting ALL methods from ALL structs

type PackageInfo

type PackageInfo struct {
	Dir     string                            // Package directory
	Methods map[string]map[string]*MethodInfo // Struct name -> Method name -> MethodInfo
}

PackageInfo holds parsed package information

Jump to

Keyboard shortcuts

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