symbol

package
v0.30.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package symbol builds per-file Pawn symbol tables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTestEntryPoint added in v0.30.2

func IsTestEntryPoint(item Symbol) bool

IsTestEntryPoint reports a YSI test function declaration.

Types

type ID

type ID int

ID identifies a Symbol or Scope within one Table. The zero value never refers to a real entry.

type Kind

type Kind uint8

Kind classifies a declared symbol.

const (
	KindFunction Kind = iota + 1
	KindPublic
	KindNative
	KindForward
	KindStock
	KindVariable
	KindConstant
	KindEnum
	KindParameter
	KindOperator
)

func (Kind) IsCallable

func (k Kind) IsCallable() bool

IsCallable reports whether k denotes something invoked with call syntax.

func (Kind) String

func (k Kind) String() string

type Reference

type Reference struct {
	Name     string
	Span     source.Span
	Scope    ID
	Resolved ID // 0 if no declaration was found.
	IsCall   bool
	ArgCount int // -1 for non-call references.
}

Reference is one identifier use, resolved against the scope active at that point in the tree.

type Scope

type Scope struct {
	ID     ID
	Kind   ScopeKind
	Parent ID // 0 for the file scope.
	Names  map[string]ID
}

Scope is one lexical scope. Names declared directly in a scope shadow same-named symbols in Parent.

type ScopeKind

type ScopeKind uint8

ScopeKind classifies a Scope.

const (
	ScopeFile ScopeKind = iota + 1
	ScopeFunction
	ScopeBlock
)

type StableID added in v0.2.0

type StableID [32]byte

StableID identifies a top-level declaration across source revisions.

type Symbol

type Symbol struct {
	ID            ID
	Name          string
	Kind          Kind
	Tag           string // declared tag, e.g. "Float"; "" if untagged.
	IsArray       bool
	IsConst       bool
	IsStatic      bool
	Scope         ID          // the scope this symbol is declared IN.
	FuncScope     ID          // for callable kinds with a body: the scope holding its parameters/locals; 0 otherwise.
	MinArgs       int         // required parameters for callable symbols.
	MaxArgs       int         // total parameters; -1 means variadic.
	ParamTags     []string    // parameter tags in declaration order.
	StateSelector string      // state selector text; empty for ordinary declarations.
	Span          source.Span // the declaration name's span.
}

Symbol is one declaration.

type Table

type Table struct {
	File        source.FileID
	Symbols     []Symbol
	Scopes      []Scope
	References  []Reference
	Diagnostics []diagnostic.Diagnostic
	// contains filtered or unexported fields
}

Table is the immutable result of Build.

func Build

func Build(root parser.SyntaxNode, file source.FileID) *Table

Build creates a symbol table from an error-tolerant syntax tree.

func BuildContext added in v0.11.0

func BuildContext(ctx context.Context, root parser.SyntaxNode, file source.FileID) (*Table, error)

BuildContext creates a symbol table and stops when ctx is cancelled.

func BuildMapped

func BuildMapped(root parser.SyntaxNode, file source.FileID, files func(uint32) source.FileID) *Table

BuildMapped maps token provenance file indexes to shared file IDs.

func BuildMappedContext added in v0.11.0

func BuildMappedContext(
	ctx context.Context,
	root parser.SyntaxNode,
	file source.FileID,
	files func(uint32) source.FileID,
) (*Table, error)

BuildMappedContext maps token origins and stops when ctx is cancelled.

func BuildMappedDeclarationsContext added in v0.14.0

func BuildMappedDeclarationsContext(
	ctx context.Context,
	root parser.SyntaxNode,
	file source.FileID,
	files func(uint32) source.FileID,
) (*Table, error)

BuildMappedDeclarationsContext builds mapped top-level declarations.

func BuildMappedNavigationContext added in v0.14.1

func BuildMappedNavigationContext(
	ctx context.Context,
	root parser.SyntaxNode,
	file source.FileID,
	files func(uint32) source.FileID,
) (*Table, error)

BuildMappedNavigationContext keeps details for the active file.

func BuildMappedNavigationWithSpansContext added in v0.18.0

func BuildMappedNavigationWithSpansContext(
	ctx context.Context,
	root parser.SyntaxNode,
	file source.FileID,
	mapSpan func(parser.SyntaxNode) (source.Span, bool),
) (*Table, error)

BuildMappedNavigationWithSpansContext keeps active-file details and uses mapSpan to map expanded nodes back to source files.

func BuildMappedWithSpansContext added in v0.29.0

func BuildMappedWithSpansContext(
	ctx context.Context,
	root parser.SyntaxNode,
	file source.FileID,
	mapSpan func(parser.SyntaxNode) (source.Span, bool),
) (*Table, error)

BuildMappedWithSpansContext builds full symbols using mapped source spans.

func PatchReference added in v0.25.0

func PatchReference(previous *Table, span source.Span, name string) (*Table, bool)

PatchReference returns a table with one reference name updated.

func RebaseParenthesized added in v0.27.1

func RebaseParenthesized(
	previous *Table,
	previousSource, currentSource []byte,
	previousTokens, tokens []token.Token,
	before, after parser.ByteRange,
) (*Table, bool)

RebaseParenthesized returns a table remapped after wrapping or unwrapping text.

func (*Table) DeclarationAt added in v0.1.19

func (t *Table) DeclarationAt(span source.Span) (Symbol, bool)

DeclarationAt returns the first symbol declared at span.

func (*Table) ExportFingerprint added in v0.3.0

func (t *Table) ExportFingerprint() [32]byte

ExportFingerprint identifies the table's top-level signatures.

func (*Table) Lookup

func (t *Table) Lookup(scope ID, name string) (Symbol, bool)

Lookup resolves name starting at scope and walking outward through parent scopes, the same rule used while building references.

func (*Table) LookupCallable added in v0.30.2

func (t *Table) LookupCallable(scope ID, name string, argCount int) (Symbol, bool)

LookupCallable resolves a call by name and argument count.

func (*Table) OperatorOverloads

func (t *Table) OperatorOverloads(name string) []Symbol

OperatorOverloads returns operator declarations with the given normalized name.

func (*Table) ReferencedAt added in v0.1.19

func (t *Table) ReferencedAt(span source.Span) (Symbol, bool)

ReferencedAt returns the symbol resolved by the first reference at span.

func (*Table) Scope

func (t *Table) Scope(id ID) (Scope, bool)

Scope looks up a scope by ID.

func (*Table) StableSymbolID added in v0.2.0

func (t *Table) StableSymbolID(id ID) (StableID, bool)

StableSymbolID returns a top-level symbol ID that survives body-only edits.

func (*Table) Symbol

func (t *Table) Symbol(id ID) (Symbol, bool)

Symbol looks up a symbol by ID.

func (*Table) UndefinedReferences

func (t *Table) UndefinedReferences() []Reference

UndefinedReferences returns names unresolved within this file.

Jump to

Keyboard shortcuts

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