ast

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

This package defines source code entities - abstractions that end-user (a programmer) operates on. For convenience these structures have json tags. This is not clean architecture but it's very handy for LSP.

Index

Constants

View Source
const ArrayBypassIdx uint8 = 255
View Source
const MissingNodeNamePrefix = "__missing_node_name__"

Variables

This section is empty.

Functions

func IsArrayBypassIdx

func IsArrayBypassIdx(idx *uint8) bool

func IsArrayBypassPortAddr

func IsArrayBypassPortAddr(addr *PortAddr) bool

func MissingNodeName

func MissingNodeName(index int) string

Types

type Build

type Build struct {
	Modules     map[core.ModuleRef]Module `json:"modules,omitempty"`
	EntryModRef core.ModuleRef            `json:"entryModRef"`
}

type CommentTag added in v0.37.0

type CommentTag struct {
	Name  string `json:"name,omitempty"`
	Value string `json:"value,omitempty"`
}

type Comments added in v0.37.0

type Comments struct {
	TextBlocks []string          `json:"textBlocks,omitempty"`
	Inports    map[string]string `json:"inports,omitempty"`
	Outports   map[string]string `json:"outports,omitempty"`
	Examples   []string          `json:"examples,omitempty"`
	Tags       []CommentTag      `json:"tags,omitempty"`
	Meta       core.Meta         `json:"meta"`
}

Comments is a parsed comment payload attached to an entity.

type Component

type Component struct {
	Directives map[Directive]string `json:"directives,omitempty"`
	Nodes      map[string]Node      `json:"nodes,omitempty"`
	Net        []Connection         `json:"net,omitempty"`
	Interface  `json:"interface"`
	Meta       core.Meta `json:"meta"`
}

type Connection

type Connection struct {
	Senders   []ConnectionSender   `json:"sender,omitempty"`
	Receivers []ConnectionReceiver `json:"receiver,omitempty"`
	Meta      core.Meta            `json:"meta"`
}

type ConnectionReceiver

type ConnectionReceiver struct {
	PortAddr          *PortAddr   `json:"portAddr,omitempty"`
	ChainedConnection *Connection `json:"chainedConnection,omitempty"`
	Meta              core.Meta   `json:"meta"`
}

type ConnectionSender

type ConnectionSender struct {
	PortAddr       *PortAddr `json:"portAddr,omitempty"`
	Const          *Const    `json:"const,omitempty"`
	StructSelector []string  `json:"selector,omitempty"`
	Meta           core.Meta `json:"meta"`
}

func (ConnectionSender) String

func (s ConnectionSender) String() string

type Const

type Const struct {
	TypeExpr ts.Expr    `json:"typeExpr"`
	Value    ConstValue `json:"value"`
	Meta     core.Meta  `json:"meta"`
}

Const represents abstraction that allow to define reusable message value.

type ConstValue

type ConstValue struct {
	Ref     *core.EntityRef `json:"ref,omitempty"`
	Message *MsgLiteral     `json:"message,omitempty"`
	Meta    core.Meta       `json:"meta"`
}

func (ConstValue) String

func (c ConstValue) String() string

type Directive

type Directive string

Directive is an explicit instruction for compiler.

type EntitiesResult

type EntitiesResult struct {
	Entity     Entity
	EntityName string
	FileName   string
}

type Entity

type Entity struct {
	Type      ts.Def      `json:"type"`
	Component []Component `json:"component,omitempty"`
	Interface Interface   `json:"interface"`
	Const     Const       `json:"const"`
	Comments  *Comments   `json:"comments,omitempty"`
	Kind      EntityKind  `json:"kind,omitempty"`
	IsPublic  bool        `json:"exported,omitempty"`
}

func (Entity) Meta

func (e Entity) Meta() *core.Meta

type EntityKind

type EntityKind string
const (
	ComponentEntity EntityKind = "component_entity"
	ConstEntity     EntityKind = "const_entity"
	TypeEntity      EntityKind = "type_entity"
	InterfaceEntity EntityKind = "interface_entity"
)

type File

type File struct {
	Imports  map[string]Import `json:"imports,omitempty"`
	Entities map[string]Entity `json:"entities,omitempty"`
}

type IO

type IO struct {
	In   map[string]Port `json:"in,omitempty"`
	Out  map[string]Port `json:"out,omitempty"`
	Meta core.Meta       `json:"meta"`
}

type Import

type Import struct {
	Module  string    `json:"moduleName,omitempty"`
	Package string    `json:"pkgName,omitempty"`
	Meta    core.Meta `json:"meta"`
}

type Interface

type Interface struct {
	TypeParams TypeParams `json:"typeParams"`
	IO         IO         `json:"io"`
	Meta       core.Meta  `json:"meta"`
}

Interface describes abstract component.

type InteropableComponent

type InteropableComponent struct {
	Name      string
	Component Component
}

InteropableComponent describes a component that can be exported to go.

type Module

type Module struct {
	Packages map[string]Package `json:"packages,omitempty"`
	Manifest ModuleManifest     `json:"manifest"`
}

Module is unit of distribution.

func (Module) Entity

func (mod Module) Entity(entityRef core.EntityRef) (entity Entity, filename string, err error)

type ModuleManifest

type ModuleManifest struct {
	Deps            map[string]core.ModuleRef `json:"deps,omitempty" yaml:"deps,omitempty"`
	LanguageVersion string                    `json:"neva,omitempty" yaml:"neva,omitempty"`
}

type MsgLiteral

type MsgLiteral struct {
	Bool         *bool                 `json:"bool,omitempty"`
	Int          *int                  `json:"int,omitempty"`
	Float        *float64              `json:"float,omitempty"`
	Str          *string               `json:"str,omitempty"`
	DictOrStruct map[string]ConstValue `json:"dict,omitempty"`
	Union        *UnionLiteral         `json:"union,omitempty"`
	List         []ConstValue          `json:"vec,omitempty"`
	Meta         core.Meta             `json:"meta"`
}

func (MsgLiteral) String

func (m MsgLiteral) String() string

type Node

type Node struct {
	Directives    map[Directive]string `json:"directives,omitempty"`
	DIArgs        map[string]Node      `json:"diArgs,omitempty"`
	OverloadIndex *int                 `json:"overloadIndex,omitempty"`
	TypeArgs      TypeArgs             `json:"typeArgs,omitempty"`
	EntityRef     core.EntityRef       `json:"entityRef"`
	Meta          core.Meta            `json:"meta"`
	ErrGuard      bool                 `json:"errGuard,omitempty"`
}

func (Node) String

func (n Node) String() string

type Package

type Package map[string]File

func (Package) Entities

func (pkg Package) Entities() func(func(EntitiesResult) bool)

Entities iterates over all entities in the package using the range-func protocol.

func (Package) Entity

func (p Package) Entity(entityName string) (entity Entity, filename string, ok bool)

Just like program's Entity

func (Package) GetInteropableComponents

func (pkg Package) GetInteropableComponents() []InteropableComponent

GetInteropableComponents finds all public components in the package that have exactly one inport and one outport (valid for go interop). components that don't meet this criteria are silently ignored.

type Port

type Port struct {
	TypeExpr ts.Expr   `json:"typeExpr"`
	Meta     core.Meta `json:"meta"`
	IsArray  bool      `json:"isArray,omitempty"`
}

type PortAddr

type PortAddr struct {
	Node string    `json:"node,omitempty"`
	Port string    `json:"port,omitempty"`
	Idx  *uint8    `json:"idx,omitempty"` // TODO use bool flag instead of pointer to avoid problems with equality
	Meta core.Meta `json:"meta"`
}

func (PortAddr) String

func (p PortAddr) String() string

type Scope

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

func NewScope

func NewScope(build Build, location core.Location) Scope

NewScope returns a new scope with a given location

func (Scope) Entity

func (s Scope) Entity(entityRef core.EntityRef) (Entity, core.Location, error)

Entity returns entity by reference

func (Scope) GetComponent

func (s Scope) GetComponent(entityRef core.EntityRef) ([]Component, error)

TODO rename to GetComponents

func (Scope) GetConst

func (s Scope) GetConst(entityRef core.EntityRef) (Const, core.Location, error)

func (Scope) GetEntityKind

func (s Scope) GetEntityKind(entityRef core.EntityRef) (EntityKind, error)

func (Scope) GetFirstInportName

func (s Scope) GetFirstInportName(
	nodes map[string]Node,

	portAddr PortAddr,
) (string, error)

func (Scope) GetFirstOutportName

func (s Scope) GetFirstOutportName(
	nodes map[string]Node,

	portAddr PortAddr,
) (string, error)

func (Scope) GetNodeIOByPortAddr

func (s Scope) GetNodeIOByPortAddr(
	nodes map[string]Node,

	portAddr PortAddr,
) (IO, error)

func (Scope) GetType

func (s Scope) GetType(ref core.EntityRef) (ts.Def, ts.Scope, error)

GetType returns type definition by reference

func (Scope) IsTopType

func (s Scope) IsTopType(expr ts.Expr) bool

IsTopType returns true if expr is a top type (any)

func (Scope) Location

func (s Scope) Location() *core.Location

Location returns a location of the current scope

func (Scope) Relocate

func (s Scope) Relocate(location core.Location) Scope

Relocate returns a new scope with a given location

type TypeArgs

type TypeArgs []ts.Expr

func (TypeArgs) String

func (t TypeArgs) String() string

type TypeParams

type TypeParams struct {
	Params []ts.Param `json:"params,omitempty"`
	Meta   core.Meta  `json:"meta"`
}

func (TypeParams) String

func (t TypeParams) String() string

func (TypeParams) ToFrame

func (t TypeParams) ToFrame() map[string]ts.Def

type UnionLiteral

type UnionLiteral struct {
	EntityRef core.EntityRef `json:"entityRef"`
	Tag       string         `json:"tag,omitempty"`
	Data      *ConstValue    `json:"data,omitempty"`
	Meta      core.Meta      `json:"meta"`
}

Jump to

Keyboard shortcuts

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