linking

package
v0.0.0-...-6cc8dd8 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultScopeOfType

func DefaultScopeOfType[T core.AstNode](node core.AstNode) core.Scope

DefaultScopeOfType is the default way of creating a scope for a reference in the given AST node. It combines the global scope (imported symbols) and the local scope (symbols visible from a container).

func DescribeExport

func DescribeExport(node core.AstNode) *core.SymbolDescription

DescribeExport checks whether the given node is a symbol (i.e. has a name) and returns a description for it.

Language-specific implementations can be provided by implementing the ExportedSymbolDescriber interface.

func DescribeLocal

func DescribeLocal(node core.AstNode) (*core.SymbolDescription, core.AstNode)

DescribeLocal checks whether the given node is a symbol (i.e. has a name) and returns a description for it. A symbol is mapped to its direct container, making it visible in all its siblings.

Language-specific implementations can be provided by implementing the LocalSymbolDescriber interface.

func GetLocalSymbols

func GetLocalSymbols[T core.AstNode](node core.AstNode) core.SymbolSeq

GetLocalSymbols retrieves the local symbols for the given AST node and type.

func GlobalScopeOfType

func GlobalScopeOfType[T core.AstNode](node core.AstNode) core.Scope

GlobalScopeOfType is the default way of creating a global scope for a reference in the given AST node. It returns the scope of imported symbols for the given type.

func LocalScopeOfType

func LocalScopeOfType[T core.AstNode](node core.AstNode, globalScope core.Scope) core.Scope

LocalScopeOfType is the default way of creating a local scope for a reference in the given AST node. It returns the scope of symbols visible from the given AST node or any of its containers.

func Name

func Name(node core.AstNode) core.StringUnit

Name checks the 'Name' attribute of the given node and returns its value as a StringUnit, i.e. a Token or a CompositeNode, both of which can produce a string.

Language-specific implementations can be provided by implementing the Denominator interface.

func SetupDefaultServices

func SetupDefaultServices(sc *service.Container)

SetupDefaultServices sets up the default services for the linking package. If any service is already set, it's not overwritten.

Types

type DefaultLinker

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

DefaultLinker is the default implementation of Linker. It resolves all references in the document.

func (s *DefaultLinker) Link(ctx context.Context, document *core.Document)

type DefaultLocalSymbols

type DefaultLocalSymbols struct {
	Symbols map[core.AstNode]core.SymbolContainer
}

DefaultLocalSymbols is the default implementation of core.LocalSymbols.

func NewDefaultLocalSymbols

func NewDefaultLocalSymbols() *DefaultLocalSymbols

NewDefaultLocalSymbols creates a new DefaultLocalSymbols instance.

func NewDefaultLocalSymbolsFromMap

func NewDefaultLocalSymbolsFromMap(m map[core.AstNode]core.SymbolContainer) *DefaultLocalSymbols

NewDefaultLocalSymbolsFromMap creates a new DefaultLocalSymbols instance from a map of AST nodes to symbol containers.

func (*DefaultLocalSymbols) For

For returns the [SymbolContainer] for the given AST node, which contains all symbols that are locally visible in that node.

type DefaultLocalSymbolsProvider

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

DefaultLocalSymbolsProvider is the default implementation of LocalSymbolsProvider.

func (*DefaultLocalSymbolsProvider) LocalSymbols

func (s *DefaultLocalSymbolsProvider) LocalSymbols(ctx context.Context, document *core.Document) core.LocalSymbols

type DefaultReferenceDescriber

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

DefaultReferenceDescriber is the default implementation of ReferenceDescriber.

func (*DefaultReferenceDescriber) DescribeReference

type DefaultReferenceDescriptionsProvider

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

DefaultReferenceDescriptionsProvider is the default implementation of ReferenceDescriptionsProvider.

func (*DefaultReferenceDescriptionsProvider) ReferenceDescriptions

type DefaultSymbolExporter

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

DefaultSymbolExporter is the default implementation of SymbolExporter. By default, it exports the root node and its direct children that have a name.

func (*DefaultSymbolExporter) ExportSymbols

func (s *DefaultSymbolExporter) ExportSymbols(ctx context.Context, document *core.Document) core.SymbolContainer

type DefaultSymbolImporter

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

DefaultSymbolImporter is the default implementation of SymbolImporter. It flat-maps the exported symbols of all documents into a single lazy sequence.

func (*DefaultSymbolImporter) ImportSymbols

func (s *DefaultSymbolImporter) ImportSymbols(ctx context.Context, doc *core.Document, allDocs iter.Seq[*core.Document]) core.SymbolContainer

type Denominator

type Denominator interface {
	// Denominate determines the name of the receiver node.
	Denominate() core.StringUnit
}

Denominator can be implemented by AST node Impl structs to provide custom naming logic.

type ExportedSymbolDescriber

type ExportedSymbolDescriber interface {
	// DescribeExport determines the name and other metadata of the receiver node as an exported symbol.
	// It returns the description, or nil if the node should not be exported.
	DescribeExport() *core.SymbolDescription
}

ExportedSymbolDescriber can be implemented by AST node Impl structs to provide custom exported symbol description logic.

type Linker

type Linker interface {
	// Link resolves all references in the document.
	// A list of all references is stored in the document's References field.
	// The caller must hold the document's write lock.
	Link(ctx context.Context, document *core.Document)
}

Linker resolves cross-references in a document's AST.

func NewDefaultLinker

func NewDefaultLinker(sc *service.Container) Linker

type LocalSymbolDescriber

type LocalSymbolDescriber interface {
	// DescribeLocal determines the name and other metadata of the receiver node as a locally visible symbol.
	// It also returns a container in which the symbol shall be visible. All direct or indirect children of the container
	// will include the symbol in their local scopes.
	//
	// If the node should not be visible locally, it returns nil.
	DescribeLocal() (*core.SymbolDescription, core.AstNode)
}

LocalSymbolDescriber can be implemented by AST node Impl structs to provide custom local symbol description logic.

type LocalSymbolsProvider

type LocalSymbolsProvider interface {
	// LocalSymbols traverses the document's AST and computes the local symbol table.
	// The result is stored in the document's LocalSymbols field.
	LocalSymbols(ctx context.Context, document *core.Document) core.LocalSymbols
}

LocalSymbolsProvider is a service that computes local symbol information for documents.

func NewDefaultLocalSymbolsProvider

func NewDefaultLocalSymbolsProvider(sc *service.Container) LocalSymbolsProvider

type ReferenceDescriber

type ReferenceDescriber interface {
	// DescribeReference describes metadata about a reference, like the source and target nodes.
	DescribeReference(ctx context.Context, ref core.UntypedReference) *core.ReferenceDescription
}

ReferenceDescriber is a service that describes references.

func NewDefaultReferenceDescriber

func NewDefaultReferenceDescriber(sc *service.Container) ReferenceDescriber

type ReferenceDescriptionsProvider

type ReferenceDescriptionsProvider interface {
	// ReferenceDescriptions computes the reference descriptions for a document.
	// The result is stored in the document's ReferenceDescriptions field.
	ReferenceDescriptions(ctx context.Context, document *core.Document) core.ReferenceDescriptions
}

ReferenceDescriptionsProvider is a service that computes the reference descriptions for a document.

func NewDefaultReferenceDescriptionsProvider

func NewDefaultReferenceDescriptionsProvider(sc *service.Container) ReferenceDescriptionsProvider

type SymbolExporter

type SymbolExporter interface {
	// ExportSymbols traverses the document's AST and computes the exported symbols.
	// The result is stored in the document's ExportedSymbols field.
	ExportSymbols(ctx context.Context, document *core.Document) core.SymbolContainer
}

SymbolExporter is a service that computes the symbols to be exported from a document, so they can be imported into other documents.

func NewDefaultSymbolExporter

func NewDefaultSymbolExporter(sc *service.Container) SymbolExporter

type SymbolImporter

type SymbolImporter interface {
	// ImportSymbols creates a sequence of all symbols that are visible from other documents.
	// The result is stored in the document's ImportedSymbols field.
	ImportSymbols(ctx context.Context, document *core.Document, allDocuments iter.Seq[*core.Document]) core.SymbolContainer
}

SymbolImporter is a service that computes the symbols imported into a document from other documents, making them available for cross-document reference resolution.

func NewDefaultSymbolImporter

func NewDefaultSymbolImporter(sc *service.Container) SymbolImporter

Jump to

Keyboard shortcuts

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