vibes

package
v0.28.1 Latest Latest
Warning

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

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

Documentation

Overview

Package vibes implements the Vibescript execution engine. The initial version supports a Ruby-flavoured syntax with the following constructs:

  • Function definitions via `def name(args...) ... end` with implicit return.
  • Literals for ints, floats, strings, bools, nil, arrays, hashes, and symbols.
  • Arithmetic and comparison expressions (+, -, *, /, >, <, ==, !=).
  • Logical operators (and/or/not) and parentheses for grouping.
  • Indexing via `object[expr]` and property access via `object.attr`.
  • Function and method calls with positional and keyword arguments.
  • Built-ins such as `assert`, `money`, and `money_cents`; capabilities are provided by the host and accessed as globals (ctx, db, jobs, etc.).

Comments beginning with `#` are ignored. The interpreter enforces a simple step quota, rejecting scripts that exceed configured execution limits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayLiteral

type ArrayLiteral struct {
	Elements []Expression
	// contains filtered or unexported fields
}

ArrayLiteral represents an array literal expression.

func (*ArrayLiteral) Pos

func (e *ArrayLiteral) Pos() Position

type AssignStmt

type AssignStmt struct {
	Target Expression
	Value  Expression
	// contains filtered or unexported fields
}

AssignStmt represents a variable assignment.

func (*AssignStmt) Pos

func (s *AssignStmt) Pos() Position

type BinaryExpr

type BinaryExpr struct {
	Left     Expression
	Operator TokenType
	Right    Expression
	// contains filtered or unexported fields
}

BinaryExpr represents a binary operator expression (e.g. a + b).

func (*BinaryExpr) Pos

func (e *BinaryExpr) Pos() Position

type Block

type Block struct {
	Params []Param
	Body   []Statement
	Env    *Env
	// contains filtered or unexported fields
}

Block represents a closure passed to a function at runtime.

type BlockLiteral

type BlockLiteral struct {
	Params []Param
	Body   []Statement
	// contains filtered or unexported fields
}

BlockLiteral represents an inline block (closure) expression.

func (*BlockLiteral) Pos

func (b *BlockLiteral) Pos() Position

type BoolLiteral

type BoolLiteral struct {
	Value bool
	// contains filtered or unexported fields
}

BoolLiteral represents a boolean constant (true or false).

func (*BoolLiteral) Pos

func (e *BoolLiteral) Pos() Position

type BreakStmt added in v0.16.0

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

BreakStmt represents a break statement that exits a loop.

func (*BreakStmt) Pos added in v0.16.0

func (s *BreakStmt) Pos() Position

type Builtin

type Builtin struct {
	Name       string
	Fn         BuiltinFunc
	AutoInvoke bool
}

Builtin represents a built-in function callable from Vibescript.

type BuiltinFunc

type BuiltinFunc func(exec *Execution, receiver Value, args []Value, kwargs map[string]Value, block Value) (Value, error)

BuiltinFunc is the Go function signature for built-in Vibescript functions.

type CallExpr

type CallExpr struct {
	Callee Expression
	Args   []Expression
	KwArgs []KeywordArg
	Block  *BlockLiteral
	// contains filtered or unexported fields
}

CallExpr represents a function or method call.

func (*CallExpr) Pos

func (e *CallExpr) Pos() Position

type CallOptions

type CallOptions struct {
	Globals      map[string]Value
	Capabilities []CapabilityAdapter
	AllowRequire bool
	Keywords     map[string]Value
}

CallOptions configures globals, capabilities, and other settings for a script invocation.

type CapabilityAdapter

type CapabilityAdapter interface {
	Bind(binding CapabilityBinding) (map[string]Value, error)
}

CapabilityAdapter binds host capabilities into a script invocation.

func MustNewContextCapability added in v0.15.0

func MustNewContextCapability(name string, resolver ContextCapabilityResolver) CapabilityAdapter

MustNewContextCapability constructs a capability adapter or panics on invalid arguments.

func MustNewDBCapability added in v0.15.0

func MustNewDBCapability(name string, db Database) CapabilityAdapter

MustNewDBCapability constructs a capability adapter or panics on invalid arguments.

func MustNewEventsCapability added in v0.15.0

func MustNewEventsCapability(name string, publisher EventPublisher) CapabilityAdapter

MustNewEventsCapability constructs a capability adapter or panics on invalid arguments.

func MustNewJobQueueCapability added in v0.6.0

func MustNewJobQueueCapability(name string, queue JobQueue) CapabilityAdapter

MustNewJobQueueCapability constructs a capability adapter or panics on invalid arguments.

func NewContextCapability added in v0.15.0

func NewContextCapability(name string, resolver ContextCapabilityResolver) (CapabilityAdapter, error)

NewContextCapability constructs a data-only context capability adapter.

func NewDBCapability added in v0.15.0

func NewDBCapability(name string, db Database) (CapabilityAdapter, error)

NewDBCapability constructs a capability adapter bound to the provided name.

func NewEventsCapability added in v0.15.0

func NewEventsCapability(name string, publisher EventPublisher) (CapabilityAdapter, error)

NewEventsCapability constructs a capability adapter bound to the provided name.

func NewJobQueueCapability

func NewJobQueueCapability(name string, queue JobQueue) (CapabilityAdapter, error)

NewJobQueueCapability constructs a capability adapter bound to the provided name.

type CapabilityBinding

type CapabilityBinding struct {
	Context context.Context
	Engine  *Engine
}

CapabilityBinding provides execution context for adapters during binding.

type CapabilityContractProvider added in v0.13.0

type CapabilityContractProvider interface {
	CapabilityContracts() map[string]CapabilityMethodContract
}

CapabilityContractProvider exposes per-method contracts for capability adapters. Contract keys must match builtin method names exposed to scripts (for example "jobs.enqueue").

type CapabilityMethodContract added in v0.13.0

type CapabilityMethodContract struct {
	ValidateArgs   func(args []Value, kwargs map[string]Value, block Value) error
	ValidateReturn func(result Value) error
}

CapabilityMethodContract validates capability method calls at the boundary. These contracts run before and after a capability builtin executes.

type CaseExpr added in v0.16.0

type CaseExpr struct {
	Target   Expression
	Clauses  []CaseWhenClause
	ElseExpr Expression
	// contains filtered or unexported fields
}

CaseExpr represents a case/when expression.

func (*CaseExpr) Pos added in v0.16.0

func (e *CaseExpr) Pos() Position

type CaseWhenClause added in v0.16.0

type CaseWhenClause struct {
	Values []Expression
	Result Expression
}

CaseWhenClause represents a single when branch in a case expression.

type ClassDef added in v0.5.0

type ClassDef struct {
	Name         string
	Methods      map[string]*ScriptFunction
	ClassMethods map[string]*ScriptFunction
	ClassVars    map[string]Value
	Body         []Statement
	// contains filtered or unexported fields
}

ClassDef represents a user-defined class with its methods and class-level state.

type ClassStmt added in v0.5.0

type ClassStmt struct {
	Name         string
	Methods      []*FunctionStmt
	ClassMethods []*FunctionStmt
	Properties   []PropertyDecl
	Body         []Statement
	// contains filtered or unexported fields
}

ClassStmt represents a class definition.

func (*ClassStmt) Pos added in v0.5.0

func (s *ClassStmt) Pos() Position

type ClassVarExpr added in v0.5.0

type ClassVarExpr struct {
	Name string
	// contains filtered or unexported fields
}

ClassVarExpr represents a class variable reference (e.g. @@count).

func (*ClassVarExpr) Pos added in v0.5.0

func (e *ClassVarExpr) Pos() Position

type Config

type Config struct {
	StepQuota        int
	MemoryQuotaBytes int
	StrictEffects    bool
	RecursionLimit   int
	ModulePaths      []string
	ModuleAllowList  []string
	ModuleDenyList   []string
	RandomReader     io.Reader
	MaxCachedModules int
	MaxSourceBytes   int
}

Config controls interpreter execution bounds and enforcement modes.

type ContextCapabilityResolver added in v0.15.0

type ContextCapabilityResolver func(ctx context.Context) (Value, error)

ContextCapabilityResolver resolves call-scoped context data for script access.

type DBEachRequest added in v0.15.0

type DBEachRequest struct {
	Collection string
	Options    map[string]Value
}

DBEachRequest captures db.each calls.

type DBFindRequest added in v0.15.0

type DBFindRequest struct {
	Collection string
	ID         Value
	Options    map[string]Value
}

DBFindRequest captures db.find calls.

type DBQueryRequest added in v0.15.0

type DBQueryRequest struct {
	Collection string
	Options    map[string]Value
}

DBQueryRequest captures db.query calls.

type DBSumRequest added in v0.15.0

type DBSumRequest struct {
	Collection string
	Field      string
	Options    map[string]Value
}

DBSumRequest captures db.sum calls.

type DBUpdateRequest added in v0.15.0

type DBUpdateRequest struct {
	Collection string
	ID         Value
	Attributes map[string]Value
	Options    map[string]Value
}

DBUpdateRequest captures db.update calls.

type Database added in v0.15.0

type Database interface {
	Find(ctx context.Context, req DBFindRequest) (Value, error)
	Query(ctx context.Context, req DBQueryRequest) (Value, error)
	Update(ctx context.Context, req DBUpdateRequest) (Value, error)
	Sum(ctx context.Context, req DBSumRequest) (Value, error)
	Each(ctx context.Context, req DBEachRequest) ([]Value, error)
}

Database exposes data access capability methods to scripts.

type Duration

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

Duration stores an integer number of seconds for now.

func (Duration) Seconds

func (d Duration) Seconds() int64

Seconds returns the duration as a whole number of seconds.

func (Duration) String

func (d Duration) String() string

String returns the duration formatted as "<n>s".

type Engine

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

Engine executes Vibescript programs with deterministic limits.

func MustNewEngine added in v0.6.0

func MustNewEngine(cfg Config) *Engine

MustNewEngine constructs an Engine or panics if the config is invalid.

func NewEngine

func NewEngine(cfg Config) (*Engine, error)

NewEngine constructs an Engine with sane defaults and registers built-ins.

func (*Engine) Builtins

func (e *Engine) Builtins() map[string]Value

Builtins returns a copy of the registered builtin map.

func (*Engine) ClearModuleCache added in v0.17.0

func (e *Engine) ClearModuleCache() int

ClearModuleCache drops all cached modules and returns the number of entries removed. Long-running hosts can call this between script runs to force fresh module reloads.

func (*Engine) Compile

func (e *Engine) Compile(source string) (*Script, error)

func (*Engine) ConfigSummary

func (e *Engine) ConfigSummary() string

ConfigSummary provides a human-readable description of the interpreter limits.

func (*Engine) Execute

func (e *Engine) Execute(ctx context.Context, script string) error

Execute compiles the provided source ensuring it is valid under current config.

func (*Engine) RegisterBuiltin

func (e *Engine) RegisterBuiltin(name string, fn BuiltinFunc)

RegisterBuiltin registers a callable global available to scripts.

func (*Engine) RegisterZeroArgBuiltin

func (e *Engine) RegisterZeroArgBuiltin(name string, fn BuiltinFunc)

RegisterZeroArgBuiltin registers a builtin that can be invoked without arguments or parentheses.

type EnumDef added in v0.21.0

type EnumDef struct {
	Name         string
	Members      map[string]*EnumValueDef
	MembersByKey map[string]*EnumValueDef
	Order        []string
	// contains filtered or unexported fields
}

EnumDef represents a user-defined enumeration with named members.

type EnumMemberStmt added in v0.21.0

type EnumMemberStmt struct {
	Name string
	// contains filtered or unexported fields
}

EnumMemberStmt represents a single member in an enum definition.

type EnumStmt added in v0.21.0

type EnumStmt struct {
	Name    string
	Members []EnumMemberStmt
	// contains filtered or unexported fields
}

EnumStmt represents an enum definition.

func (*EnumStmt) Pos added in v0.21.0

func (s *EnumStmt) Pos() Position

type EnumValueDef added in v0.21.0

type EnumValueDef struct {
	Enum   *EnumDef
	Name   string
	Symbol string
	Index  int
}

EnumValueDef represents a single member within an EnumDef.

type Env

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

Env represents a lexical scope that maps variable names to values.

func (*Env) Assign

func (e *Env) Assign(name string, val Value) bool

Assign updates an existing variable in the nearest enclosing scope, or defines it in the current scope.

func (*Env) CloneShallow

func (e *Env) CloneShallow() *Env

CloneShallow returns a copy of the environment with the same parent and a shallow copy of its bindings.

func (*Env) Define

func (e *Env) Define(name string, val Value)

Define binds a new variable in the current scope.

func (*Env) Get

func (e *Env) Get(name string) (Value, bool)

Get looks up a variable by name, traversing parent scopes if needed.

type EventPublishRequest added in v0.15.0

type EventPublishRequest struct {
	Topic   string
	Payload map[string]Value
	Options map[string]Value
}

EventPublishRequest captures events.publish calls.

type EventPublisher added in v0.15.0

type EventPublisher interface {
	Publish(ctx context.Context, req EventPublishRequest) (Value, error)
}

EventPublisher exposes event publication capability methods to scripts.

type Execution

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

Execution holds the runtime state for a single script evaluation.

func (*Execution) CallBlock added in v0.5.1

func (exec *Execution) CallBlock(block Value, args []Value) (Value, error)

CallBlock invokes a block value with the provided arguments. This is the public entry point for capability adapters that need to call user-supplied blocks (e.g. db.each, db.tx).

type ExprStmt

type ExprStmt struct {
	Expr Expression
	// contains filtered or unexported fields
}

ExprStmt wraps an expression used as a statement.

func (*ExprStmt) Pos

func (s *ExprStmt) Pos() Position

type Expression

type Expression interface {
	Node
	// contains filtered or unexported methods
}

Expression is the interface implemented by all expression AST nodes.

type FloatLiteral

type FloatLiteral struct {
	Value float64
	// contains filtered or unexported fields
}

FloatLiteral represents a floating-point constant.

func (*FloatLiteral) Pos

func (e *FloatLiteral) Pos() Position

type ForStmt

type ForStmt struct {
	Iterator string
	Iterable Expression
	Body     []Statement
	// contains filtered or unexported fields
}

ForStmt represents a for-in loop.

func (*ForStmt) Pos

func (s *ForStmt) Pos() Position

type FunctionStmt

type FunctionStmt struct {
	Name          string
	Params        []Param
	ReturnTy      *TypeExpr
	Body          []Statement
	IsClassMethod bool
	Exported      bool
	Private       bool
	// contains filtered or unexported fields
}

FunctionStmt represents a function or method definition.

func (*FunctionStmt) Pos

func (s *FunctionStmt) Pos() Position

type HashLiteral

type HashLiteral struct {
	Pairs []HashPair
	// contains filtered or unexported fields
}

HashLiteral represents a hash/map literal expression.

func (*HashLiteral) Pos

func (e *HashLiteral) Pos() Position

type HashPair

type HashPair struct {
	Key   Expression
	Value Expression
}

HashPair represents a single key-value pair in a hash literal.

type Identifier

type Identifier struct {
	Name string
	// contains filtered or unexported fields
}

Identifier represents a named reference in an expression.

func (*Identifier) Pos

func (e *Identifier) Pos() Position

type IfStmt

type IfStmt struct {
	Condition  Expression
	Consequent []Statement
	ElseIf     []*IfStmt
	Alternate  []Statement
	// contains filtered or unexported fields
}

IfStmt represents an if/elsif/else conditional statement.

func (*IfStmt) Pos

func (s *IfStmt) Pos() Position

type IndexExpr

type IndexExpr struct {
	Object Expression
	Index  Expression
	// contains filtered or unexported fields
}

IndexExpr represents a bracket-index access (e.g. arr[0]).

func (*IndexExpr) Pos

func (e *IndexExpr) Pos() Position

type Instance added in v0.5.0

type Instance struct {
	Class *ClassDef
	Ivars map[string]Value
}

Instance represents a runtime instance of a ClassDef with its own instance variables.

type IntegerLiteral

type IntegerLiteral struct {
	Value int64
	// contains filtered or unexported fields
}

IntegerLiteral represents an integer constant.

func (*IntegerLiteral) Pos

func (e *IntegerLiteral) Pos() Position

type InterpolatedString

type InterpolatedString struct {
	Parts []StringPart
	// contains filtered or unexported fields
}

InterpolatedString represents a string containing embedded expressions.

func (*InterpolatedString) Pos

func (s *InterpolatedString) Pos() Position

type IvarExpr added in v0.5.0

type IvarExpr struct {
	Name string
	// contains filtered or unexported fields
}

IvarExpr represents an instance variable reference (e.g. @name).

func (*IvarExpr) Pos added in v0.5.0

func (e *IvarExpr) Pos() Position

type JobQueue

type JobQueue interface {
	Enqueue(ctx context.Context, job JobQueueJob) (Value, error)
}

JobQueue exposes queue functionality to scripts via strongly-typed adapters.

type JobQueueEnqueueOptions

type JobQueueEnqueueOptions struct {
	Delay  *time.Duration
	Key    *string
	Kwargs map[string]Value
}

JobQueueEnqueueOptions represents keyword arguments supplied to enqueue.

type JobQueueJob

type JobQueueJob struct {
	Name    string
	Payload map[string]Value
	Options JobQueueEnqueueOptions
}

JobQueueJob captures a job invocation from script code.

type JobQueueRetryRequest

type JobQueueRetryRequest struct {
	JobID   string
	Options map[string]Value
}

JobQueueRetryRequest captures retry invocations.

type JobQueueWithRetry

type JobQueueWithRetry interface {
	JobQueue
	Retry(ctx context.Context, req JobQueueRetryRequest) (Value, error)
}

JobQueueWithRetry extends JobQueue with a retry operation.

type KeywordArg

type KeywordArg struct {
	Name  string
	Value Expression
}

KeywordArg represents a named argument in a function call.

type MemberExpr

type MemberExpr struct {
	Object   Expression
	Property string
	// contains filtered or unexported fields
}

MemberExpr represents a dot-access property lookup (e.g. obj.prop).

func (*MemberExpr) Pos

func (e *MemberExpr) Pos() Position

type Money

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

Money represents an ISO-4217 currency amount stored as integer cents.

func (Money) Cents

func (m Money) Cents() int64

Cents returns the amount in the smallest currency unit.

func (Money) Currency

func (m Money) Currency() string

Currency returns the ISO-4217 currency code.

func (Money) String

func (m Money) String() string

String returns the amount formatted as "X.XX CUR".

type NextStmt added in v0.16.0

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

NextStmt represents a next statement that skips to the next loop iteration.

func (*NextStmt) Pos added in v0.16.0

func (s *NextStmt) Pos() Position

type NilLiteral

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

NilLiteral represents the nil literal.

func (*NilLiteral) Pos

func (e *NilLiteral) Pos() Position

type Node

type Node interface {
	Pos() Position
}

Node is the interface implemented by all AST nodes.

type Param added in v0.5.0

type Param struct {
	Name       string
	Type       *TypeExpr
	DefaultVal Expression
	IsIvar     bool
}

Param represents a function or block parameter.

type Position

type Position struct {
	Line   int
	Column int
}

Position identifies a byte offset in the source file.

type Program

type Program struct {
	Statements []Statement
}

Program represents the top-level AST node containing all statements.

func (*Program) Pos

func (p *Program) Pos() Position

type PropertyDecl added in v0.5.0

type PropertyDecl struct {
	Names []string
	Kind  string // property/getter/setter
	// contains filtered or unexported fields
}

PropertyDecl represents a property, getter, or setter declaration in a class.

type RaiseStmt added in v0.17.0

type RaiseStmt struct {
	Value Expression
	// contains filtered or unexported fields
}

RaiseStmt represents a raise statement that throws an error.

func (*RaiseStmt) Pos added in v0.17.0

func (s *RaiseStmt) Pos() Position

type Range

type Range struct {
	Start int64
	End   int64
}

Range represents an integer range with inclusive start and end.

type RangeExpr

type RangeExpr struct {
	Start Expression
	End   Expression
	// contains filtered or unexported fields
}

RangeExpr represents a range expression (e.g. 1..10).

func (*RangeExpr) Pos

func (e *RangeExpr) Pos() Position

type ReturnStmt

type ReturnStmt struct {
	Value Expression
	// contains filtered or unexported fields
}

ReturnStmt represents a return statement.

func (*ReturnStmt) Pos

func (s *ReturnStmt) Pos() Position

type RuntimeError

type RuntimeError struct {
	Type      string
	Message   string
	CodeFrame string
	Frames    []StackFrame
}

RuntimeError represents a Vibescript runtime error with a call stack and source context.

func (*RuntimeError) Error

func (re *RuntimeError) Error() string

Error returns the error message with a code frame and formatted stack trace.

func (*RuntimeError) Unwrap

func (re *RuntimeError) Unwrap() error

Unwrap returns nil to satisfy the error unwrapping interface. RuntimeError is a terminal error that wraps the original error message but not the error itself.

type ScopeExpr added in v0.21.0

type ScopeExpr struct {
	Object   Expression
	Property string
	// contains filtered or unexported fields
}

ScopeExpr represents a scope-resolution access (e.g. Mod::Name).

func (*ScopeExpr) Pos added in v0.21.0

func (e *ScopeExpr) Pos() Position

type Script

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

Script represents a parsed Vibescript module ready for execution.

func (*Script) Call

func (s *Script) Call(ctx context.Context, name string, args []Value, opts CallOptions) (Value, error)

func (*Script) Classes added in v0.19.0

func (s *Script) Classes() []*ClassDef

Classes returns compiled classes in deterministic name order.

func (*Script) Enums added in v0.21.0

func (s *Script) Enums() []*EnumDef

Enums returns compiled enums in deterministic name order.

func (*Script) Function

func (s *Script) Function(name string) (*ScriptFunction, bool)

Function looks up a compiled function by name.

func (*Script) Functions added in v0.19.0

func (s *Script) Functions() []*ScriptFunction

Functions returns compiled functions in deterministic name order.

type ScriptFunction

type ScriptFunction struct {
	Name     string
	Params   []Param
	ReturnTy *TypeExpr
	Body     []Statement
	Pos      Position
	Env      *Env
	Exported bool
	Private  bool
	// contains filtered or unexported fields
}

ScriptFunction represents a user-defined function within a Vibescript module.

type StackFrame

type StackFrame struct {
	Function string
	Pos      Position
}

StackFrame represents a single entry in a runtime error's call stack.

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

Statement is the interface implemented by all statement AST nodes.

type StringExpr

type StringExpr struct {
	Expr Expression
}

StringExpr represents an embedded expression segment in an interpolated string.

type StringLiteral

type StringLiteral struct {
	Value string
	// contains filtered or unexported fields
}

StringLiteral represents a plain string constant.

func (*StringLiteral) Pos

func (e *StringLiteral) Pos() Position

type StringPart

type StringPart interface {
	// contains filtered or unexported methods
}

StringPart is the interface for parts of an interpolated string.

type StringText

type StringText struct {
	Text string
}

StringText represents a literal text segment in an interpolated string.

type SymbolLiteral

type SymbolLiteral struct {
	Name string
	// contains filtered or unexported fields
}

SymbolLiteral represents a symbol literal (e.g. :foo).

func (*SymbolLiteral) Pos

func (e *SymbolLiteral) Pos() Position

type Token

type Token struct {
	Type    TokenType
	Literal string
	Pos     Position
}

Token captures lexical information for the parser.

type TokenType

type TokenType string

TokenType identifies the lexical category of a token.

type TryStmt added in v0.17.0

type TryStmt struct {
	Body     []Statement
	RescueTy *TypeExpr
	Rescue   []Statement
	Ensure   []Statement
	// contains filtered or unexported fields
}

TryStmt represents a begin/rescue/ensure error-handling block.

func (*TryStmt) Pos added in v0.17.0

func (s *TryStmt) Pos() Position

type TypeExpr added in v0.5.0

type TypeExpr struct {
	Name     string
	Kind     TypeKind
	Nullable bool
	TypeArgs []*TypeExpr
	Shape    map[string]*TypeExpr
	Union    []*TypeExpr
	// contains filtered or unexported fields
}

TypeExpr represents a type annotation in the source code.

type TypeKind added in v0.5.1

type TypeKind int

TypeKind identifies the category of a type expression.

const (
	// TypeAny is the unconstrained type that matches any value.
	TypeAny TypeKind = iota
	TypeInt
	TypeFloat
	TypeNumber
	TypeString
	TypeBool
	TypeNil
	TypeDuration
	TypeTime
	TypeMoney
	TypeArray
	TypeHash
	TypeFunction
	TypeShape
	TypeUnion
	TypeEnum
	TypeUnknown
)

type UnaryExpr

type UnaryExpr struct {
	Operator TokenType
	Right    Expression
	// contains filtered or unexported fields
}

UnaryExpr represents a unary operator expression (e.g. -x, !y).

func (*UnaryExpr) Pos

func (e *UnaryExpr) Pos() Position

type UntilStmt added in v0.16.0

type UntilStmt struct {
	Condition Expression
	Body      []Statement
	// contains filtered or unexported fields
}

UntilStmt represents an until loop (loops while condition is false).

func (*UntilStmt) Pos added in v0.16.0

func (s *UntilStmt) Pos() Position

type Value

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

Value is a tagged union holding any Vibescript runtime value.

func NewArray

func NewArray(a []Value) Value

NewArray returns an array Value.

func NewAutoBuiltin

func NewAutoBuiltin(name string, fn BuiltinFunc) Value

NewAutoBuiltin returns a builtin function Value that auto-invokes without parentheses.

func NewBlock

func NewBlock(params []Param, body []Statement, env *Env) Value

NewBlock returns a block (closure) Value.

func NewBool

func NewBool(b bool) Value

NewBool returns a boolean Value.

func NewBuiltin

func NewBuiltin(name string, fn BuiltinFunc) Value

NewBuiltin returns a builtin function Value.

func NewClass added in v0.5.0

func NewClass(def *ClassDef) Value

NewClass returns a class definition Value.

func NewDuration

func NewDuration(d Duration) Value

NewDuration returns a duration Value.

func NewEnum added in v0.21.0

func NewEnum(def *EnumDef) Value

NewEnum returns an enum definition Value.

func NewEnumValue added in v0.21.0

func NewEnumValue(def *EnumValueDef) Value

NewEnumValue returns an enum member Value.

func NewFloat

func NewFloat(f float64) Value

NewFloat returns a floating-point Value.

func NewFunction

func NewFunction(fn *ScriptFunction) Value

NewFunction returns a script-defined function Value.

func NewHash

func NewHash(h map[string]Value) Value

NewHash returns a hash (map) Value.

func NewInstance added in v0.5.0

func NewInstance(inst *Instance) Value

NewInstance returns a class instance Value.

func NewInt

func NewInt(i int64) Value

NewInt returns an integer Value.

func NewMoney

func NewMoney(m Money) Value

NewMoney returns a money Value.

func NewNil

func NewNil() Value

NewNil returns a nil Value.

func NewObject

func NewObject(attrs map[string]Value) Value

NewObject returns an object Value with the given attributes.

func NewRange

func NewRange(r Range) Value

NewRange returns a range Value.

func NewString

func NewString(s string) Value

NewString returns a string Value.

func NewSymbol

func NewSymbol(name string) Value

NewSymbol returns a symbol Value.

func NewTime added in v0.4.0

func NewTime(t time.Time) Value

NewTime returns a time Value.

func (Value) Array

func (v Value) Array() []Value

Array returns the array content of v, or nil if v is not an array.

func (Value) Block

func (v Value) Block() *Block

Block returns the block (closure) of v, or nil if v is not a block.

func (Value) Bool

func (v Value) Bool() bool

Bool returns the boolean content of v, or false if v is not a bool.

func (Value) Builtin

func (v Value) Builtin() *Builtin

Builtin returns the builtin function of v, or nil if v is not a builtin.

func (Value) Class added in v0.5.0

func (v Value) Class() *ClassDef

Class returns the class definition of v, or nil if v is not a class.

func (Value) Duration

func (v Value) Duration() Duration

Duration returns the duration content of v, or a zero Duration if v is not a duration.

func (Value) Enum added in v0.21.0

func (v Value) Enum() *EnumDef

Enum returns the enum definition of v, or nil if v is not an enum.

func (Value) EnumValue added in v0.21.0

func (v Value) EnumValue() *EnumValueDef

EnumValue returns the enum member of v, or nil if v is not an enum value.

func (Value) Equal

func (v Value) Equal(other Value) bool

Equal reports whether v and other hold the same kind and value.

func (Value) Float

func (v Value) Float() float64

Float returns the float content of v, coercing from int if needed.

func (Value) Function

func (v Value) Function() *ScriptFunction

Function returns the script function of v, or nil if v is not a function.

func (Value) Hash

func (v Value) Hash() map[string]Value

Hash returns the hash content of v, or nil if v is not a hash or object.

func (Value) Instance added in v0.5.0

func (v Value) Instance() *Instance

Instance returns the class instance of v, or nil if v is not an instance.

func (Value) Int

func (v Value) Int() int64

Int returns the integer content of v, coercing from float if needed.

func (Value) IsNil

func (v Value) IsNil() bool

IsNil reports whether v is a nil value.

func (Value) Kind

func (v Value) Kind() ValueKind

Kind returns the ValueKind of v.

func (Value) Money

func (v Value) Money() Money

Money returns the money content of v, or a zero Money if v is not money.

func (Value) Range

func (v Value) Range() Range

Range returns the range content of v, or a zero Range if v is not a range.

func (Value) String

func (v Value) String() string

String returns the string representation of v.

func (Value) Time added in v0.4.0

func (v Value) Time() time.Time

Time returns the time content of v, or a zero time if v is not a time.

func (Value) Truthy

func (v Value) Truthy() bool

Truthy reports whether v is considered true in a boolean context.

type ValueKind

type ValueKind int

ValueKind identifies the type of a runtime Value.

const (
	// KindNil is the nil value kind.
	KindNil ValueKind = iota
	KindBool
	KindInt
	KindFloat
	KindString
	KindArray
	KindHash
	KindFunction
	KindBuiltin
	KindMoney
	KindDuration
	KindTime
	KindSymbol
	KindObject
	KindRange
	KindBlock
	KindEnum
	KindEnumValue
	KindClass
	KindInstance
)

func (ValueKind) String

func (k ValueKind) String() string

String returns the human-readable name of the ValueKind.

type WhileStmt added in v0.16.0

type WhileStmt struct {
	Condition Expression
	Body      []Statement
	// contains filtered or unexported fields
}

WhileStmt represents a while loop.

func (*WhileStmt) Pos added in v0.16.0

func (s *WhileStmt) Pos() Position

type YieldExpr added in v0.5.0

type YieldExpr struct {
	Args []Expression
	// contains filtered or unexported fields
}

YieldExpr represents a yield call that invokes the enclosing block.

func (*YieldExpr) Pos added in v0.5.0

func (y *YieldExpr) Pos() Position

Source Files

Jump to

Keyboard shortcuts

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