parser

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bind

type Bind struct {
	IfaceType string
	ImplType  string
	Named     string
}

type Import

type Import struct {
	Alias string // empty means default import name
	Path  string // fully-qualified import path, e.g., "github.com/xfrr/assemble"
}

type Model

type Model struct {
	Provides []Provide
	Sets     []Set
	Binds    []Bind
	Starts   []StartHook
	Stops    []StopHook
	Imports  []Import
	// contains filtered or unexported fields
}

func ExtractModule

func ExtractModule(p *packages.Package, varName string, fset *token.FileSet) (Model, error)

ExtractModule scans the given package for a variable named `varName` and attempts to parse its value as an assemble module definition.

func (*Model) PkgName added in v0.1.2

func (m *Model) PkgName() string

func (*Model) SetPkgName added in v0.1.2

func (m *Model) SetPkgName(name string)

type ModuleRef added in v0.1.2

type ModuleRef struct {
	IsLocalIdent bool
	Ident        string

	IsSelector  bool
	SelPkgAlias string
	SelIdent    string
	SelPkgPath  string // resolved from file imports without types

	Imports []Import // imports from the file that declared the function
}

ModuleRef represents a reference to a module variable, either local or from another package.

func ExtractFunctionModuleRefLoose added in v0.1.2

func ExtractFunctionModuleRefLoose(p *packages.Package, funcName string) (ModuleRef, string, error)

ExtractFunctionModuleRefLoose scans the syntax (no types) to find:

func <funcName>(...) { return assemble.Assemble(<expr>) }

It returns a ModuleRef with the argument <expr> and the file's imports resolved purely from AST (aliases from source or last path segment).

type Provide

type Provide struct {
	FuncName       string
	PkgPath        string
	PkgAlias       string
	IsFuncLit      bool
	RawFuncLit     string
	TakesResolve   bool
	ResType        string
	HasError       bool
	Named          string
	LitParamCount  int
	LitResultCount int
}

type Set

type Set struct {
	ElemType string
	Elems    []Provide
}

type StartHook

type StartHook struct {
	FuncName    string
	PkgPath     string
	PkgAlias    string
	Priority    int
	TimeoutMs   int64
	TimeoutExpr string
	IsFuncLit   bool
	RawFuncLit  string

	// OnStartFor[T]
	IsStartFor   bool
	ForType      string
	FnHasCtx     bool
	FnHasResolve bool
}

type StopHook

type StopHook struct {
	FuncName    string
	PkgPath     string
	PkgAlias    string
	Priority    int
	TimeoutMs   int64
	TimeoutExpr string
	IsFuncLit   bool
	RawFuncLit  string

	// OnStopFor[T]
	IsStopFor    bool
	ForType      string
	FnHasCtx     bool
	FnHasResolve bool
}

Jump to

Keyboard shortcuts

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