runtime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(left, right Value) bool

Equal returns true if two values are equal

func Greater

func Greater(left, right Value) (bool, error)

Greater returns true if left > right (numeric comparison)

func GreaterEqual

func GreaterEqual(left, right Value) (bool, error)

GreaterEqual returns true if left >= right (numeric comparison)

func IsArray

func IsArray(v Value) bool

func IsBool

func IsBool(v Value) bool

func IsNull

func IsNull(v Value) bool

func IsNumber

func IsNumber(v Value) bool

func IsObject

func IsObject(v Value) bool

func IsString

func IsString(v Value) bool

func Less

func Less(left, right Value) (bool, error)

Less returns true if left < right (numeric comparison)

func LessEqual

func LessEqual(left, right Value) (bool, error)

LessEqual returns true if left <= right (numeric comparison)

func NotEqual

func NotEqual(left, right Value) bool

NotEqual returns true if two values are not equal

func ToBool

func ToBool(v Value) bool

func ToNumber

func ToNumber(v Value) (float64, error)

func ToString

func ToString(v Value) (string, error)

Types

type ArrayValue

type ArrayValue struct {
	Elements []Value
}

ArrayValue represents an array of values

func NewArray

func NewArray(elements ...Value) *ArrayValue

func (*ArrayValue) IsTruthy

func (a *ArrayValue) IsTruthy() bool

func (*ArrayValue) String

func (a *ArrayValue) String() string

func (*ArrayValue) Type

func (a *ArrayValue) Type() ValueType

type BoolValue

type BoolValue struct {
	Value bool
}

BoolValue represents a boolean value

func NewBool

func NewBool(b bool) *BoolValue

func (*BoolValue) IsTruthy

func (b *BoolValue) IsTruthy() bool

func (*BoolValue) String

func (b *BoolValue) String() string

func (*BoolValue) Type

func (b *BoolValue) Type() ValueType

type Func

type Func func(args ...Value) (Value, error)

type NullValue

type NullValue struct{}

NullValue represents a null value

func NewNull

func NewNull() *NullValue

func (*NullValue) IsTruthy

func (n *NullValue) IsTruthy() bool

func (*NullValue) String

func (n *NullValue) String() string

func (*NullValue) Type

func (n *NullValue) Type() ValueType

type NumberValue

type NumberValue struct {
	Value float64
}

NumberValue represents a numeric value

func NewNumber

func NewNumber(n float64) *NumberValue

func (*NumberValue) IsTruthy

func (n *NumberValue) IsTruthy() bool

func (*NumberValue) String

func (n *NumberValue) String() string

func (*NumberValue) Type

func (n *NumberValue) Type() ValueType

type ObjectValue

type ObjectValue struct {
	Fields map[string]Value
}

ObjectValue represents an object (map of string keys to values)

func NewObject

func NewObject() *ObjectValue

func (*ObjectValue) Get

func (o *ObjectValue) Get(key string) (Value, bool)

Get retrieves a field from the object

func (*ObjectValue) IsTruthy

func (o *ObjectValue) IsTruthy() bool

func (*ObjectValue) Set

func (o *ObjectValue) Set(key string, val Value)

Set sets a field in the object

func (*ObjectValue) String

func (o *ObjectValue) String() string

func (*ObjectValue) Type

func (o *ObjectValue) Type() ValueType

type Scope

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

Scope manages variable bindings and template definitions

func NewScope

func NewScope(parent *Scope) *Scope

NewScope creates a new scope with an optional parent

func (*Scope) DefineTemplate

func (s *Scope) DefineTemplate(name string, tmpl *Template)

DefineTemplate registers a template in the current scope

func (*Scope) Get

func (s *Scope) Get(name string) (Value, error)

Get retrieves a variable value from this scope or parent scopes

func (*Scope) GetFunction

func (s *Scope) GetFunction(name string) (Func, bool)

func (*Scope) GetTemplate

func (s *Scope) GetTemplate(name string) (*Template, error)

GetTemplate retrieves a template from this scope or parent scopes

func (s *Scope) Link(other *Scope)

func (*Scope) Set

func (s *Scope) Set(name string, val Value)

Set binds a variable to a value in the current scope

func (*Scope) SetFunction

func (s *Scope) SetFunction(name string, f Func)

func (*Scope) SetGlobal

func (s *Scope) SetGlobal(name string, val Value)

type StringValue

type StringValue struct {
	Value string
}

StringValue represents a string value

func NewString

func NewString(s string) *StringValue

func (*StringValue) IsTruthy

func (s *StringValue) IsTruthy() bool

func (*StringValue) String

func (s *StringValue) String() string

func (*StringValue) Type

func (s *StringValue) Type() ValueType

type Template

type Template struct {
	Name     string
	Body     []parser.Node // The AST nodes to evaluate
	Filename string        // Source file where template was defined
}

Template represents a user-defined template

func NewTemplate

func NewTemplate(name string, body []parser.Node, filename string) *Template

NewTemplate creates a new template with source file information

type Value

type Value interface {
	Type() ValueType
	String() string
	IsTruthy() bool
}

Value is the interface for all runtime values

func NewValue

func NewValue(val any) Value

type ValueType

type ValueType int

ValueType represents the type of a runtime value

const (
	StringType ValueType = iota
	NumberType
	BoolType
	NullType
	ArrayType
	ObjectType
)

func (ValueType) String

func (vt ValueType) String() string

Jump to

Keyboard shortcuts

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