parser

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package parser provides call graph extraction from Go source files.

Package parser provides type resolution and canonical ID construction for Go source analysis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnwindSelector

func UnwindSelector(expr *ast.SelectorExpr) (baseIdent *ast.Ident, chains []string)

UnwindSelector recursively unwinds a selector expression chain, returning the base identifier and the ordered chain of field/method names. Example: for a.b.c(), returns (ident("a"), ["b", "c"]).

Types

type CallParser

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

CallParser extracts call graph edges and control flow edges from Go source files.

func NewCallParser

func NewCallParser(moduleName string) *CallParser

NewCallParser creates a new call parser.

func (*CallParser) ExtractCalls

func (cp *CallParser) ExtractCalls(_ context.Context, path string) ([]*graph.Edge, error)

ExtractCalls extracts CALLS edges from a Go source file.

func (*CallParser) ExtractControlFlow

func (cp *CallParser) ExtractControlFlow(_ context.Context, path string) ([]*graph.Edge, error)

ExtractControlFlow extracts FLOWS_THROUGH edges with ordering from a Go source file.

func (*CallParser) SetTypeRegistry

func (cp *CallParser) SetTypeRegistry(reg *TypeRegistry)

SetTypeRegistry attaches a TypeRegistry for canonical type resolution.

type StructFieldInfo

type StructFieldInfo struct {
	FieldName string
	FieldType string
}

StructFieldInfo holds the type information for a struct field.

type StructInfo

type StructInfo struct {
	PkgPath string
	Name    string
	Fields  []StructFieldInfo
}

StructInfo holds type information for a parsed struct.

type TypeRegistry

type TypeRegistry struct {
	// localVarTypes maps variable name -> "fullPkgPath:ExactTypeName"
	// e.g., "svc" -> "internal/service:PaymentService"
	LocalVarTypes map[string]string

	// structIndex maps "fullPkgPath:StructName" -> *StructInfo
	StructIndex map[string]*StructInfo

	// moduleName for trimming internal paths
	ModuleName string
}

TypeRegistry tracks canonical type information for local variables and structs.

func NewTypeRegistry

func NewTypeRegistry() *TypeRegistry

NewTypeRegistry creates a new type registry.

func (*TypeRegistry) RegisterStruct

func (tr *TypeRegistry) RegisterStruct(pkgPath, typeName string, fields []StructFieldInfo)

RegisterStruct records a struct type and its fields for deep resolution.

func (*TypeRegistry) ResolveCallTarget

func (tr *TypeRegistry) ResolveCallTarget(target string, imports map[string]string, pkgPath string) string

ResolveCallTarget resolves a full call target string to a graph node ID, handling local variable method calls, package function calls, and local functions. Built-in functions (make, new, panic, etc.) are labeled stdlib:builtin:<name>. Go standard library functions (fmt.Println, os.Open, etc.) are labeled stdlib:<pkg>:<func>.

func (*TypeRegistry) ResolveFieldType

func (tr *TypeRegistry) ResolveFieldType(structKey, fieldName string) string

ResolveFieldType looks up the type of a struct field by name.

func (*TypeRegistry) ResolveMethodID

func (tr *TypeRegistry) ResolveMethodID(target string, imports map[string]string, _ string) string

ResolveMethodID resolves a selector expression (var.method or var.field.sub.method) to a canonical method node ID. Handles 2-part selectors (e.g., "svc.ProcessDeposit") and multi-part selectors (e.g., "s.repo.UpdateBalance") by walking the struct field chain. Returns "" when resolution fails.

func (*TypeRegistry) SetModuleName

func (tr *TypeRegistry) SetModuleName(name string)

SetModuleName sets the module prefix for canonical path resolution.

func (*TypeRegistry) TrackCompositeLitType

func (tr *TypeRegistry) TrackCompositeLitType(varName string, pkgAlias, typeName string, imports map[string]string)

TrackCompositeLitType records the type of a variable initialized with composite literal. Example: svc := &service.PaymentService{}

func (*TypeRegistry) TrackConstructorCall

func (tr *TypeRegistry) TrackConstructorCall(varName, pkgAlias, constructorName string, imports map[string]string)

TrackConstructorCall records the type of a variable initialized via constructor call. Example: svc := service.NewPaymentService(repo)

  • varName = "svc"
  • pkgAlias = "service" (import alias)
  • constructorName = "NewPaymentService"
  • imports maps "service" -> "github.com/PizenLabs/lea/internal/service"

func (*TypeRegistry) TrackLocalCompositeLitType

func (tr *TypeRegistry) TrackLocalCompositeLitType(varName, typeName, pkgPath string)

TrackLocalCompositeLitType records the type of a variable initialized with a same-package composite literal. Example: svc := &PaymentService{}

func (*TypeRegistry) TrackReceiverType

func (tr *TypeRegistry) TrackReceiverType(recvName, pkgPath, typeName string)

TrackReceiverType records the type of a method receiver variable. Example: func (s *PaymentService) ProcessDeposit()

Directories

Path Synopsis
Package contracts defines parser interfaces used across the app.
Package contracts defines parser interfaces used across the app.
Package golang provides a Go source parser for graph extraction.
Package golang provides a Go source parser for graph extraction.
Package treesitter parses non-Go sources using tree-sitter.
Package treesitter parses non-Go sources using tree-sitter.
python
Package python provides tree-sitter queries for Python.
Package python provides tree-sitter queries for Python.

Jump to

Keyboard shortcuts

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