language

package
v0.0.0-...-86251c0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeInt              = &Type{BaseType: ObjectTypeInt, Content: "int"}
	TypeFloat            = &Type{BaseType: ObjectTypeFloat, Content: "float"}
	TypeBool             = &Type{BaseType: ObjectTypeBool, Content: "bool"}
	TypeString           = &Type{BaseType: ObjectTypeString, Content: "string"}
	TypeChar             = &Type{BaseType: ObjectTypeChar, Content: "char"}
	TypeByte             = &Type{BaseType: ObjectTypeByte, Content: "byte"}
	TypeList             = &Type{BaseType: ObjectTypeList, Element: TypeAny}
	TypeDict             = &Type{BaseType: ObjectTypeDict, Key: TypeAny, Value: TypeAny}
	TypeStructInstance   = Nullable(&Type{BaseType: ObjectTypeStructInstance})
	TypeStructDefinition = &Type{BaseType: ObjectTypeStructDefinition}
	TypeNil              = &Type{BaseType: ObjectTypeNil, Content: "nil"}
	TypeAny              = &Type{BaseType: ObjectTypeAny, Content: "any"}
	TypeVoid             = &Type{BaseType: ObjectTypeVoid, Content: "void"}
	TypeHtml             = &Type{BaseType: ObjectTypeHtml, Content: "html"}
)
View Source
var ErrIndexOutOfBounds = errors.New("index out of bounds")

Functions

func ToValue

func ToValue(obj Object, json ...bool) (any, error)

func TypeCheck

func TypeCheck(shouldBe *Type, is *Type) bool

Types

type Any

type Any struct {
	Data Object
	// contains filtered or unexported fields
}

func NewAny

func NewAny(value Object, debug *debug.Debug) *Any

func (*Any) Clone

func (i *Any) Clone() *Any

func (*Any) Debug

func (i *Any) Debug() *debug.Debug

func (*Any) GetPrototype

func (i *Any) GetPrototype() Prototype

func (*Any) ID

func (i *Any) ID() string

func (*Any) Inspect

func (i *Any) Inspect() string

func (*Any) String

func (i *Any) String() string

func (*Any) Type

func (i *Any) Type() *Type

func (*Any) TypeString

func (i *Any) TypeString() string

func (*Any) Value

func (i *Any) Value() any

type Attribute

type Attribute struct {
	Name  string
	Kind  string // "DYNAMIC" or "TEXT"
	Value Object
}

type BasicFnArg

type BasicFnArg struct {
	TypeVal    *Type
	NameVal    string
	DefaultVal Object
}

func (*BasicFnArg) Default

func (b *BasicFnArg) Default() Object

func (*BasicFnArg) Name

func (b *BasicFnArg) Name() string

func (*BasicFnArg) Type

func (b *BasicFnArg) Type() *Type

type Bool

type Bool struct {
	Data bool
	// contains filtered or unexported fields
}

func NewBool

func NewBool(value bool, debug *debug.Debug) *Bool

func (*Bool) Clone

func (i *Bool) Clone() Object

func (*Bool) Debug

func (i *Bool) Debug() *debug.Debug

func (*Bool) GetPrototype

func (i *Bool) GetPrototype() Prototype

func (*Bool) ID

func (i *Bool) ID() string

func (*Bool) Inspect

func (i *Bool) Inspect() string

func (*Bool) String

func (i *Bool) String() string

func (*Bool) Type

func (i *Bool) Type() *Type

func (*Bool) TypeString

func (i *Bool) TypeString() string

func (*Bool) Value

func (i *Bool) Value() any

type Byte

type Byte struct {
	Data byte
	// contains filtered or unexported fields
}

func NewByte

func NewByte(value byte, debug *debug.Debug) *Byte

func (*Byte) Clone

func (i *Byte) Clone() Object

func (*Byte) Debug

func (i *Byte) Debug() *debug.Debug

func (*Byte) GetPrototype

func (i *Byte) GetPrototype() Prototype

func (*Byte) ID

func (i *Byte) ID() string

func (*Byte) Inspect

func (i *Byte) Inspect() string

func (*Byte) String

func (i *Byte) String() string

func (*Byte) Type

func (i *Byte) Type() *Type

func (*Byte) TypeString

func (i *Byte) TypeString() string

func (*Byte) Value

func (i *Byte) Value() any

type Char

type Char struct {
	Data rune
	// contains filtered or unexported fields
}

func NewChar

func NewChar(value rune, debug *debug.Debug) *Char

func (*Char) Clone

func (i *Char) Clone() Object

func (*Char) Debug

func (i *Char) Debug() *debug.Debug

func (*Char) GetPrototype

func (i *Char) GetPrototype() Prototype

func (*Char) ID

func (i *Char) ID() string

func (*Char) Inspect

func (i *Char) Inspect() string

func (*Char) String

func (i *Char) String() string

func (*Char) Type

func (i *Char) Type() *Type

func (*Char) TypeString

func (i *Char) TypeString() string

func (*Char) Value

func (i *Char) Value() any

type Dict

type Dict struct {
	Data      *OrderedMap
	KeyType   *Type
	ValueType *Type
	// contains filtered or unexported fields
}

func NewDict

func NewDict(keys []Object, values []Object, keyType *Type, valueType *Type, debug *debug.Debug) (*Dict, error)

func (*Dict) Clone

func (i *Dict) Clone() Object

func (*Dict) Debug

func (i *Dict) Debug() *debug.Debug

func (*Dict) GetPrototype

func (i *Dict) GetPrototype() Prototype

func (*Dict) ID

func (i *Dict) ID() string

func (*Dict) Inspect

func (i *Dict) Inspect() string

func (*Dict) Iterator

func (i *Dict) Iterator() func() (Object, Object, bool)

func (*Dict) String

func (i *Dict) String() string

func (*Dict) Type

func (i *Dict) Type() *Type

func (*Dict) TypeString

func (i *Dict) TypeString() string

func (*Dict) Value

func (i *Dict) Value() any

type DictPrototype

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

func NewDictPrototype

func NewDictPrototype(base *Dict) *DictPrototype

func (*DictPrototype) GetObject

func (dp *DictPrototype) GetObject(name string) (Object, bool)

func (*DictPrototype) Objects

func (dp *DictPrototype) Objects() map[string]Object

func (*DictPrototype) SetObject

func (dp *DictPrototype) SetObject(name string, value Object) error

type Element

type Element struct {
	Data *ElementData
	// contains filtered or unexported fields
}

func NewElement

func NewElement(data *ElementData, debug *debug.Debug) *Element

func (*Element) Clone

func (e *Element) Clone() Object

func (*Element) Debug

func (e *Element) Debug() *debug.Debug

func (*Element) GetPrototype

func (e *Element) GetPrototype() Prototype

func (*Element) ID

func (e *Element) ID() string

func (*Element) Inspect

func (e *Element) Inspect() string

func (*Element) String

func (e *Element) String() string

func (*Element) Type

func (e *Element) Type() *Type

func (*Element) TypeString

func (e *Element) TypeString() string

func (*Element) Value

func (e *Element) Value() any

type ElementChild

type ElementChild struct {
	Type      astnode.NodeType // Element, ElementRawText, ElementDynamicText
	Content   string           // for RawText
	Value     *Element         // for DynamicText or nested Element
	IsEscaped bool
}

type ElementData

type ElementData struct {
	TagName   string
	Args      []Attribute
	Children  []ElementChild
	SelfClose bool
}

type ElementPrototype

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

func NewElementPrototype

func NewElementPrototype(base *Element) *ElementPrototype

func (*ElementPrototype) GetObject

func (e *ElementPrototype) GetObject(name string) (Object, bool)

func (*ElementPrototype) Objects

func (e *ElementPrototype) Objects() map[string]Object

func (*ElementPrototype) SetObject

func (e *ElementPrototype) SetObject(name string, value Object) error

type Float

type Float struct {
	Data float64
	// contains filtered or unexported fields
}

func NewFloat

func NewFloat(value float64, debug *debug.Debug) *Float

func (*Float) Clone

func (i *Float) Clone() Object

func (*Float) Debug

func (i *Float) Debug() *debug.Debug

func (*Float) GetPrototype

func (i *Float) GetPrototype() Prototype

func (*Float) ID

func (i *Float) ID() string

func (*Float) Inspect

func (i *Float) Inspect() string

func (*Float) String

func (i *Float) String() string

func (*Float) Type

func (i *Float) Type() *Type

func (*Float) TypeString

func (i *Float) TypeString() string

func (*Float) Value

func (i *Float) Value() any

type FnArg

type FnArg interface {
	Type() *Type
	Name() string
	Default() Object
}

type Function

type Function struct {
	Data       func(args []Object) (Object, error)
	ArgTypes   []FnArg
	ReturnType *Type
	// contains filtered or unexported fields
}

func NewFunction

func NewFunction(data func([]Object) (Object, error), debug *debug.Debug) *Function

func NewTypedFunction

func NewTypedFunction(argTypes []FnArg, returnType *Type, data func([]Object) (Object, error), debug *debug.Debug) *Function

func (*Function) Clone

func (i *Function) Clone() Object

func (*Function) Debug

func (i *Function) Debug() *debug.Debug

func (*Function) GetPrototype

func (i *Function) GetPrototype() Prototype

func (*Function) ID

func (i *Function) ID() string

func (*Function) Inspect

func (i *Function) Inspect() string

func (*Function) String

func (i *Function) String() string

func (*Function) Type

func (i *Function) Type() *Type

func (*Function) TypeString

func (i *Function) TypeString() string

func (*Function) Value

func (i *Function) Value() any

type FunctionPrototype

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

func NewFunctionPrototype

func NewFunctionPrototype(base *Function) *FunctionPrototype

func (*FunctionPrototype) GetObject

func (fp *FunctionPrototype) GetObject(name string) (Object, bool)

func (*FunctionPrototype) Objects

func (fp *FunctionPrototype) Objects() map[string]Object

func (*FunctionPrototype) SetObject

func (fp *FunctionPrototype) SetObject(name string, value Object) error

type Int

type Int struct {
	Data int64
	// contains filtered or unexported fields
}

func NewInt

func NewInt(value int64, debug *debug.Debug) *Int

func (*Int) Clone

func (i *Int) Clone() Object

func (*Int) Debug

func (i *Int) Debug() *debug.Debug

func (*Int) GetPrototype

func (i *Int) GetPrototype() Prototype

func (*Int) ID

func (i *Int) ID() string

func (*Int) Inspect

func (i *Int) Inspect() string

func (*Int) Iterator

func (i *Int) Iterator() func() (Object, Object, bool)

func (*Int) String

func (i *Int) String() string

func (*Int) Type

func (i *Int) Type() *Type

func (*Int) TypeString

func (i *Int) TypeString() string

func (*Int) Value

func (i *Int) Value() any

type IntPrototype

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

func NewIntPrototype

func NewIntPrototype(base *Int) *IntPrototype

func (*IntPrototype) GetObject

func (i *IntPrototype) GetObject(name string) (Object, bool)

func (*IntPrototype) Objects

func (i *IntPrototype) Objects() map[string]Object

func (*IntPrototype) SetObject

func (i *IntPrototype) SetObject(name string, value Object) error

type List

type List struct {
	Data     []Object
	ItemType *Type
	// contains filtered or unexported fields
}

func NewList

func NewList(values []Object, itemType *Type, debug *debug.Debug) *List

func (*List) Clone

func (i *List) Clone() Object

func (*List) Debug

func (i *List) Debug() *debug.Debug

func (*List) GetPrototype

func (i *List) GetPrototype() Prototype

func (*List) ID

func (i *List) ID() string

func (*List) Inspect

func (i *List) Inspect() string

func (*List) Iterator

func (i *List) Iterator() func() (Object, Object, bool)

func (*List) String

func (i *List) String() string

func (*List) Type

func (i *List) Type() *Type

func (*List) TypeString

func (i *List) TypeString() string

func (*List) Value

func (i *List) Value() any

type ListPrototype

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

func NewListPrototype

func NewListPrototype(base *List) *ListPrototype

func (*ListPrototype) GetObject

func (lp *ListPrototype) GetObject(name string) (Object, bool)

func (*ListPrototype) Objects

func (lp *ListPrototype) Objects() map[string]Object

func (*ListPrototype) SetObject

func (lp *ListPrototype) SetObject(name string, value Object) error

type NilObj

type NilObj struct{}
var Nil *NilObj

func NewNil

func NewNil() *NilObj

func (*NilObj) Clone

func (n *NilObj) Clone() Object

func (*NilObj) Debug

func (n *NilObj) Debug() *debug.Debug

func (*NilObj) GetPrototype

func (n *NilObj) GetPrototype() Prototype

func (*NilObj) ID

func (n *NilObj) ID() string

func (*NilObj) Inspect

func (n *NilObj) Inspect() string

func (*NilObj) String

func (n *NilObj) String() string

func (*NilObj) Type

func (n *NilObj) Type() *Type

func (*NilObj) TypeString

func (n *NilObj) TypeString() string

func (*NilObj) Value

func (n *NilObj) Value() any

type Object

type Object interface {
	ID() string

	Type() *Type
	Inspect() string

	TypeString() string
	String() string

	GetPrototype() Prototype
	Value() any

	Debug() *debug.Debug
	Clone() Object
}

func DefaultValue

func DefaultValue(typ *Type) Object

func FromValue

func FromValue(data any, voidNil bool, dg ...*debug.Debug) (Object, error)

type ObjectType

type ObjectType int
const (
	ObjectTypeInt ObjectType = iota
	ObjectTypeFloat
	ObjectTypeBool
	ObjectTypeString
	ObjectTypeChar
	ObjectTypeByte
	ObjectTypeList
	ObjectTypeDict
	ObjectTypeStructInstance
	ObjectTypeStructDefinition
	ObjectTypeFunction
	ObjectTypeNil
	ObjectTypeAny
	ObjectTypeVoid
	ObjectTypeSignal // TypeSignal is not really a type, it is used for break, continue statements
	ObjectTypeHtml
)

func (ObjectType) Base

func (ot ObjectType) Base() ObjectType

func (ObjectType) Hashable

func (ot ObjectType) Hashable() bool

func (ObjectType) String

func (ot ObjectType) String() string

type OrderedMap

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

func NewOrderedMap

func NewOrderedMap() *OrderedMap

func (*OrderedMap) Delete

func (om *OrderedMap) Delete(key Object)

func (*OrderedMap) Get

func (om *OrderedMap) Get(key Object) (Object, bool)

func (*OrderedMap) Iterate

func (om *OrderedMap) Iterate(fn func(key Object, value Object) bool)

func (*OrderedMap) IterateErr

func (om *OrderedMap) IterateErr(f func(key Object, value Object) error) error

func (*OrderedMap) Len

func (om *OrderedMap) Len() int

func (*OrderedMap) Set

func (om *OrderedMap) Set(key Object, value Object)

type Prototype

type Prototype interface {
	Objects() map[string]Object
	GetObject(name string) (Object, bool)
	SetObject(name string, value Object) error
}

type Ref

type Ref struct{ Data Object }

func NewRef

func NewRef(value Object) *Ref

func (*Ref) Clone

func (i *Ref) Clone() Object

func (*Ref) Debug

func (i *Ref) Debug() *debug.Debug

func (*Ref) GetPrototype

func (i *Ref) GetPrototype() Prototype

func (*Ref) ID

func (i *Ref) ID() string

func (*Ref) Inspect

func (i *Ref) Inspect() string

func (*Ref) String

func (i *Ref) String() string

func (*Ref) Type

func (i *Ref) Type() *Type

func (*Ref) TypeString

func (i *Ref) TypeString() string

func (*Ref) Value

func (i *Ref) Value() any

type Signal

type Signal struct {
	Data  string
	Carry Object
	// contains filtered or unexported fields
}

func NewSignal

func NewSignal(signal string, debug *debug.Debug) *Signal

func (*Signal) Clone

func (i *Signal) Clone() Object

func (*Signal) Debug

func (i *Signal) Debug() *debug.Debug

func (*Signal) GetCarry

func (i *Signal) GetCarry() Object

func (*Signal) GetPrototype

func (i *Signal) GetPrototype() Prototype

func (*Signal) ID

func (i *Signal) ID() string

func (*Signal) Inspect

func (i *Signal) Inspect() string

func (*Signal) SetCarry

func (i *Signal) SetCarry(carry Object) *Signal

func (*Signal) String

func (i *Signal) String() string

func (*Signal) Type

func (i *Signal) Type() *Type

func (*Signal) TypeString

func (i *Signal) TypeString() string

func (*Signal) Value

func (i *Signal) Value() any

type String

type String struct {
	Data string
	// contains filtered or unexported fields
}

func NewString

func NewString(value string, debug *debug.Debug) *String

func (*String) Clone

func (i *String) Clone() Object

func (*String) Debug

func (i *String) Debug() *debug.Debug

func (*String) GetPrototype

func (i *String) GetPrototype() Prototype

func (*String) ID

func (i *String) ID() string

func (*String) Inspect

func (i *String) Inspect() string

func (*String) Iterator

func (s *String) Iterator() func() (Object, Object, bool)

func (*String) String

func (i *String) String() string

func (*String) Type

func (i *String) Type() *Type

func (*String) TypeString

func (i *String) TypeString() string

func (*String) Value

func (i *String) Value() any

type StringPrototype

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

func NewStringPrototype

func NewStringPrototype(base *String) *StringPrototype

func (*StringPrototype) GetObject

func (s *StringPrototype) GetObject(name string) (Object, bool)

func (*StringPrototype) Objects

func (s *StringPrototype) Objects() map[string]Object

func (*StringPrototype) SetObject

func (s *StringPrototype) SetObject(name string, value Object) error

type Struct

type Struct struct {
	Name string

	Data []StructField
	// contains filtered or unexported fields
}

func NewStruct

func NewStruct(name string, fields []StructField, debug *debug.Debug) *Struct

func (*Struct) Clone

func (i *Struct) Clone() Object

func (*Struct) Debug

func (i *Struct) Debug() *debug.Debug

func (*Struct) GetPrototype

func (i *Struct) GetPrototype() Prototype

func (*Struct) ID

func (i *Struct) ID() string

func (*Struct) Inspect

func (i *Struct) Inspect() string

func (*Struct) NewInstance

func (s *Struct) NewInstance() (*StructInstance, error)

func (*Struct) Settable

func (s *Struct) Settable() []string

func (*Struct) String

func (i *Struct) String() string

func (*Struct) Type

func (i *Struct) Type() *Type

func (*Struct) TypeString

func (i *Struct) TypeString() string

func (*Struct) Value

func (i *Struct) Value() any

type StructDefinition

type StructDefinition struct {
	Name   string
	Fields []StructField
	Debug  debug.Debug
}

type StructField

type StructField struct {
	Name string
	Type *Type
}

type StructInstance

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

func NewStructInstance

func NewStructInstance(base *Struct, name string, debug *debug.Debug) (*StructInstance, error)

func (*StructInstance) Clone

func (i *StructInstance) Clone() Object

func (*StructInstance) Debug

func (i *StructInstance) Debug() *debug.Debug

func (*StructInstance) GetPrototype

func (i *StructInstance) GetPrototype() Prototype

func (*StructInstance) ID

func (i *StructInstance) ID() string

func (*StructInstance) Inspect

func (i *StructInstance) Inspect() string

func (*StructInstance) Iterator

func (s *StructInstance) Iterator() func() (Object, Object, bool)

func (*StructInstance) String

func (i *StructInstance) String() string

func (*StructInstance) Type

func (i *StructInstance) Type() *Type

func (*StructInstance) TypeString

func (i *StructInstance) TypeString() string

func (*StructInstance) Value

func (i *StructInstance) Value() any

type StructPrototype

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

func NewStructPrototype

func NewStructPrototype(base *Struct) *StructPrototype

func (*StructPrototype) Clone

func (s *StructPrototype) Clone() *StructPrototype

func (*StructPrototype) GetObject

func (s *StructPrototype) GetObject(name string) (Object, bool)

func (*StructPrototype) Implement

func (s *StructPrototype) Implement()

func (*StructPrototype) Implemented

func (s *StructPrototype) Implemented() bool

func (*StructPrototype) IsBase

func (sp *StructPrototype) IsBase() bool

func (*StructPrototype) Lock

func (s *StructPrototype) Lock()

func (*StructPrototype) NewInstance

func (sp *StructPrototype) NewInstance(instance *StructInstance) (*StructPrototype, error)

func (*StructPrototype) Objects

func (s *StructPrototype) Objects() map[string]Object

func (*StructPrototype) SetObject

func (s *StructPrototype) SetObject(name string, value Object) error

func (*StructPrototype) Unlock

func (s *StructPrototype) Unlock()

type Type

type Type struct {
	BaseType ObjectType
	Content  string  // "int", "string", etc. (used for simple types)
	Key      *Type   // if Kind == "DICT", represents the key type
	Value    *Type   // if Kind == "DICT", represents the value type or if Kind == "FUNCTION", represents the return type
	Element  *Type   // if Kind == "LIST", represents the element type
	Args     []*Type // if Kind == "FUNCTION", represents the function argument types
	ID       string  // if BaseType == ObjectTypeStructInstance, represents the struct ID
	Next     *Type   // if it's an union type, represents the next type in the union
}

Type represents a type in the language.

func NewDictType

func NewDictType(key *Type, value *Type) *Type

func NewFunctionType

func NewFunctionType(returnType *Type, argsType ...*Type) *Type

func NewListType

func NewListType(elementType *Type) *Type

func NewUnionType

func NewUnionType(types ...*Type) *Type

func Nullable

func Nullable(typ *Type) *Type

func (*Type) Base

func (t *Type) Base() ObjectType

func (*Type) Compare

func (t *Type) Compare(other *Type) bool

func (*Type) DeepClone

func (t *Type) DeepClone() *Type

func (*Type) NextMatch

func (t *Type) NextMatch(other *Type) bool

func (*Type) String

func (t *Type) String() string

Jump to

Keyboard shortcuts

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