symbol

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind enumerates the kind of a Symbol.

const (
	VarSymbol     Kind = iota // Variables
	CaprefSymbol              // Capture group references
	DecoSymbol                // Decorators
	PatternSymbol             // Named pattern constants

)

Kind enumerates the kinds of symbols found in the program text.

func (Kind) String

func (k Kind) String() string

type Scope

type Scope struct {
	Parent  *Scope
	Symbols map[string]*Symbol
}

Scope maintains a record of the identifiers declared in the current program scope, and a link to the parent scope.

func NewScope

func NewScope(parent *Scope) *Scope

NewScope creates a new scope within the parent scope.

func (*Scope) CopyFrom

func (s *Scope) CopyFrom(o *Scope)

CopyFrom copies all the symbols from another scope object into this one. It recurses up the input scope copying all visible symbols into one.

func (*Scope) Insert

func (s *Scope) Insert(sym *Symbol) (alt *Symbol)

Insert attempts to insert a symbol into the scope. If the scope already contains an object alt with the same name, the scope is unchanged and the function returns alt. Otherwise the symbol is inserted, and returns nil.

func (*Scope) InsertAlias

func (s *Scope) InsertAlias(sym *Symbol, alias string) (alt *Symbol)

InsertAlias attempts to insert a duplicate name for an existing symbol into the scope. If the scope already contains an object alt with the alias, the scope is unchanged and the function returns alt. Otherwise, the symbol is inserted and the function returns nil.

func (*Scope) Lookup

func (s *Scope) Lookup(name string, kind Kind) *Symbol

Lookup returns the symbol with the given name if it is found in this or any parent scope, otherwise nil.

func (*Scope) String

func (s *Scope) String() string

String prints the current scope and all parents to a string, recursing up to the root scope. This method is only used for debugging.

type Symbol

type Symbol struct {
	Name    string             // identifier name
	Kind    Kind               // kind of program object
	Type    types.Type         // object's type
	Pos     *position.Position // Source file position of definition
	Binding interface{}        // binding to storage allocated in runtime
	Addr    int                // Address offset in another structure, object specific
	Used    bool               // Optional marker that this symbol is used after declaration.
}

Symbol describes a named program object.

func NewSymbol

func NewSymbol(name string, kind Kind, pos *position.Position) (sym *Symbol)

NewSymbol creates a record of a given symbol kind, named name, found at loc.

Jump to

Keyboard shortcuts

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