lang

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilObject = Nil{}

Functions

This section is empty.

Types

type ArgCtx

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

func NewArgCtx

func NewArgCtx(fn *FunctionV2, args []Object) *ArgCtx

func (*ArgCtx) Arg

func (ctx *ArgCtx) Arg(name string) (Object, error)

type Array

type Array struct {
	Base

	// Keys are the keys of the array.
	Keys []Object
	// Map is the map of the array.
	Map map[Object]Object
}

func (*Array) Access

func (a *Array) Access(access any) (Object, bool)

func (*Array) Copy

func (a *Array) Copy() Object

func (*Array) Method

func (a *Array) Method(name string) Method

func (*Array) Methods

func (a *Array) Methods() []string

func (*Array) SetVariable

func (a *Array) SetVariable(name string, value Object) error

func (*Array) String

func (a *Array) String() string

func (*Array) Type

func (a *Array) Type() ObjType

func (*Array) Value

func (a *Array) Value() any

func (*Array) Variable

func (a *Array) Variable(variable string) Object

func (*Array) Variables

func (a *Array) Variables() []string

type Base

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

Base is the base object

func NewBase

func NewBase(name string, debug *models.Debug) Base

func (*Base) Debug

func (b *Base) Debug() *models.Debug

func (*Base) Immute

func (b *Base) Immute()

func (*Base) IsMutable

func (b *Base) IsMutable() bool

func (*Base) Name

func (b *Base) Name() string

func (*Base) Rename

func (b *Base) Rename(s string)

type Bool

type Bool struct {
	Base
	// contains filtered or unexported fields
}

func (*Bool) Copy

func (b *Bool) Copy() Object

func (*Bool) Method

func (*Bool) Method(name string) Method

func (*Bool) Methods

func (*Bool) Methods() []string

func (*Bool) Name

func (b *Bool) Name() string

func (*Bool) SetVariable

func (*Bool) SetVariable(_ string, _ Object) error

func (*Bool) String

func (b *Bool) String() string

func (*Bool) Type

func (*Bool) Type() ObjType

func (*Bool) Value

func (b *Bool) Value() any

func (*Bool) Variable

func (b *Bool) Variable(name string) Object

func (*Bool) Variables

func (*Bool) Variables() []string

type Definition

type Definition struct {
	Base
	// contains filtered or unexported fields
}

func NewDefinition

func NewDefinition(defName, name string, debug *models.Debug, nodes []*models.Node, ex Executer) *Definition

func (*Definition) Copy

func (d *Definition) Copy() Object

func (*Definition) Method

func (d *Definition) Method(name string) Method

func (*Definition) Methods

func (d *Definition) Methods() []string

func (*Definition) NewInstance

func (d *Definition) NewInstance() (Object, error)

func (*Definition) SetVariable

func (d *Definition) SetVariable(name string, value Object) error

func (*Definition) String

func (d *Definition) String() string

func (*Definition) Type

func (d *Definition) Type() ObjType

func (*Definition) TypeString

func (d *Definition) TypeString() string

func (*Definition) Value

func (d *Definition) Value() any

func (*Definition) Variable

func (d *Definition) Variable(variable string) Object

func (*Definition) Variables

func (d *Definition) Variables() []string

type ExecFunc

type ExecFunc func(args []Object) (Object, error)

type ExecFuncV2

type ExecFuncV2 func(args *ArgCtx) (any, error)

type Executer

type Executer interface {
	GetVariable(name string) (Object, error)
	Variables() []string
	AssignVariable(name string, object Object) error
	GetMethod(name string) (Method, error)
	Execute(nodes []*models.Node) (Object, error)
	GetNew() Executer
}

Executer represents a node executer in the runtime

type Float

type Float struct {
	Base
	// contains filtered or unexported fields
}

Float represents a float object

func (*Float) Copy

func (f *Float) Copy() Object

func (*Float) Method

func (f *Float) Method(name string) Method

func (*Float) Methods

func (f *Float) Methods() []string

func (*Float) Name

func (f *Float) Name() string

func (*Float) SetVariable

func (f *Float) SetVariable(_ string, _ Object) error

func (*Float) String

func (f *Float) String() string

func (*Float) Type

func (f *Float) Type() ObjType

func (*Float) Value

func (f *Float) Value() any

func (*Float) Variable

func (f *Float) Variable(name string) Object

func (*Float) Variables

func (f *Float) Variables() []string

type Fn

type Fn struct {
	Base
	Fn Method
}

func (*Fn) Copy

func (f *Fn) Copy() Object

func (*Fn) Method

func (f *Fn) Method(name string) Method

func (*Fn) Methods

func (f *Fn) Methods() []string

func (*Fn) Name

func (f *Fn) Name() string

func (*Fn) SetVariable

func (f *Fn) SetVariable(_ string, _ Object) error

func (*Fn) String

func (f *Fn) String() string

func (*Fn) Type

func (f *Fn) Type() ObjType

func (*Fn) Value

func (f *Fn) Value() any

func (*Fn) Variable

func (f *Fn) Variable(name string) Object

func (*Fn) Variables

func (f *Fn) Variables() []string

type Function

type Function struct {
	// Method is a method of the function
	Method
	// contains filtered or unexported fields
}

Function represents a function method

func NewFunction

func NewFunction(exec ExecFunc) *Function

NewFunction creates a new function method

func (*Function) Args

func (f *Function) Args() []string

func (*Function) Debug

func (f *Function) Debug() *models.Debug

func (*Function) Execute

func (f *Function) Execute(args []Object) (Object, error)

func (*Function) GetVariadicArg

func (f *Function) GetVariadicArg() string

func (*Function) HasVariadicArg

func (f *Function) HasVariadicArg() bool

func (*Function) WithArg

func (f *Function) WithArg(arg string) *Function

func (*Function) WithArgs

func (f *Function) WithArgs(args []string) *Function

func (*Function) WithDebug

func (f *Function) WithDebug(debug *models.Debug) *Function

func (*Function) WithTypeSafeArgs

func (f *Function) WithTypeSafeArgs(typesafeArgs ...TypeSafeArg) *Function

func (*Function) WithVariadicArg

func (f *Function) WithVariadicArg(arg string) *Function

type FunctionV2

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

func FnV2

func FnV2(exec ExecFuncV2) *FunctionV2

func (*FunctionV2) Adapter

func (f *FunctionV2) Adapter() *Function

func (*FunctionV2) WithArg

func (f *FunctionV2) WithArg(arg string) *FunctionV2

func (*FunctionV2) WithDebug

func (f *FunctionV2) WithDebug(debug *models.Debug) *FunctionV2

func (*FunctionV2) WithTypeSafeArgs

func (f *FunctionV2) WithTypeSafeArgs(typesafeArgs ...TypeSafeArg) *FunctionV2

func (*FunctionV2) WithVariadicArg

func (f *FunctionV2) WithVariadicArg(arg string) *FunctionV2

type IOStream

type IOStream struct {
	Base
	// contains filtered or unexported fields
}

func (*IOStream) Copy

func (i *IOStream) Copy() Object

func (*IOStream) Method

func (i *IOStream) Method(name string) Method

func (*IOStream) Methods

func (i *IOStream) Methods() []string

func (*IOStream) Name

func (f *IOStream) Name() string

func (*IOStream) SetVariable

func (i *IOStream) SetVariable(_ string, _ Object) error

func (*IOStream) String

func (i *IOStream) String() string

func (*IOStream) Type

func (f *IOStream) Type() ObjType

func (*IOStream) Value

func (f *IOStream) Value() any

func (*IOStream) Variable

func (i *IOStream) Variable(name string) Object

func (*IOStream) Variables

func (*IOStream) Variables() []string

type Instance

type Instance struct {
	Base
	// contains filtered or unexported fields
}

func NewDefinitionInstance

func NewDefinitionInstance(def *Definition, ex Executer) *Instance

func (*Instance) Copy

func (i *Instance) Copy() Object

func (*Instance) Definition

func (i *Instance) Definition() *Definition

func (*Instance) Method

func (i *Instance) Method(name string) Method

func (*Instance) Methods

func (i *Instance) Methods() []string

func (*Instance) SetVariable

func (i *Instance) SetVariable(name string, value Object) error

func (*Instance) String

func (i *Instance) String() string

func (*Instance) Type

func (*Instance) Type() ObjType

func (*Instance) TypeString

func (i *Instance) TypeString() string

func (*Instance) Value

func (i *Instance) Value() any

func (*Instance) Variable

func (i *Instance) Variable(variable string) Object

func (*Instance) Variables

func (i *Instance) Variables() []string

type Integer

type Integer struct {
	Base
	// contains filtered or unexported fields
}

func (*Integer) Copy

func (i *Integer) Copy() Object

func (*Integer) Method

func (i *Integer) Method(name string) Method

func (*Integer) Methods

func (i *Integer) Methods() []string

func (*Integer) Name

func (i *Integer) Name() string

func (*Integer) SetVariable

func (i *Integer) SetVariable(_ string, _ Object) error

func (*Integer) String

func (i *Integer) String() string

func (*Integer) Type

func (i *Integer) Type() ObjType

func (*Integer) Value

func (i *Integer) Value() any

func (*Integer) Variable

func (i *Integer) Variable(name string) Object

func (*Integer) Variables

func (i *Integer) Variables() []string

type List

type List struct {
	Base
	// contains filtered or unexported fields
}

List represents a list object

func (*List) Copy

func (l *List) Copy() Object

func (*List) Method

func (l *List) Method(name string) Method

func (*List) Methods

func (l *List) Methods() []string

func (*List) Name

func (l *List) Name() string

func (*List) SetVariable

func (l *List) SetVariable(_ string, _ Object) error

func (*List) String

func (l *List) String() string

func (*List) Type

func (l *List) Type() ObjType

func (*List) Value

func (l *List) Value() any

func (*List) Variable

func (l *List) Variable(variable string) Object

func (*List) Variables

func (l *List) Variables() []string

type Method

type Method interface {
	// Args returns the arguments of the method
	Args() []string
	// Execute executes the method with the given arguments
	Execute(args []Object) (Object, error)
}

Method represents a method in the language

type Module

type Module interface {
	// Namespace returns the namespace of the module
	Namespace() string
	// Objects returns the objects of the module
	Objects() map[string]Object
	// Methods returns the methods of the module
	Methods() map[string]Method
}

Module represents a module in the language

type Nil

type Nil struct {
	Object
	// contains filtered or unexported fields
}

func (Nil) Copy

func (n Nil) Copy() Object

func (Nil) Debug

func (n Nil) Debug() *models.Debug

func (Nil) Immute

func (n Nil) Immute()

func (Nil) IsMutable

func (n Nil) IsMutable() bool

func (Nil) Name

func (n Nil) Name() string

func (Nil) Rename

func (n Nil) Rename(_ string)

func (Nil) String

func (n Nil) String() string

func (Nil) Type

func (n Nil) Type() ObjType

func (Nil) Value

func (n Nil) Value() any

type ObjAddr

type ObjAddr struct {
	Base
	// contains filtered or unexported fields
}

func (*ObjAddr) Copy

func (o *ObjAddr) Copy() Object

func (*ObjAddr) Method

func (o *ObjAddr) Method(name string) Method

func (*ObjAddr) Methods

func (*ObjAddr) Methods() []string

func (*ObjAddr) SetVariable

func (*ObjAddr) SetVariable(_ string, _ Object) error

func (*ObjAddr) String

func (o *ObjAddr) String() string

func (*ObjAddr) Type

func (*ObjAddr) Type() ObjType

func (*ObjAddr) Value

func (o *ObjAddr) Value() any

func (*ObjAddr) Variable

func (*ObjAddr) Variable(_ string) Object

func (*ObjAddr) Variables

func (*ObjAddr) Variables() []string

type ObjType

type ObjType string

ObjType is the type of the object

const (
	TString     ObjType = "<Object:string>"
	TInt        ObjType = "<Object:int>"
	TFloat      ObjType = "<Object:float>"
	TBool       ObjType = "<Object:bool>"
	TList       ObjType = "<Object:list>"
	TNothing    ObjType = "<Object:nothing>"
	TNil        ObjType = "<Object:nil>"
	TDefinition ObjType = "<Definition>"
	TInstance   ObjType = "<Object:instance>"
	TFunction   ObjType = "<Function>"
	TIOStream   ObjType = "<Object:iostream>"
	TArray      ObjType = "<Object:array>"
	TFnRef      ObjType = "<Object:function>"
	TAddr       ObjType = "<Object:address>"
	TAny        ObjType = "<Object:any>"
)

func (ObjType) String

func (o ObjType) String() string

func (ObjType) TokenType

func (o ObjType) TokenType() tokens.TokenType

type Object

type Object interface {
	// Type returns the type of the object
	Type() ObjType
	// Name is the name of the object, or empty string if the object is inlined
	Name() string
	// Rename renames the object
	Rename(s string)
	// Value returns the value of the object
	Value() any

	// IsMutable returns if the object is mutable
	IsMutable() bool
	// Immute makes the object immutable
	Immute()

	// Method returns a method by name
	Method(name string) Method
	// Methods returns the method names of the object
	Methods() []string

	// Variable returns a variable by name
	Variable(name string) Object
	// Variables returns the variable names of the object
	Variables() []string
	// SetVariable sets a variable by name
	SetVariable(name string, object Object) error

	// Debug returns the debug information of the object
	Debug() *models.Debug

	// String returns the string representation of the object
	String() string

	// Copy returns a copy of the object
	Copy() Object
}

Object represents an object in the language

func Addr

func Addr(s Object) Object

func FromValue

func FromValue(data any) (Object, error)

func GetListValue

func GetListValue(l Object) []Object

func Immute

func Immute(obj Object) Object

func NewArray

func NewArray(name string, debug *models.Debug, keys []Object, values []Object) Object

func NewArrayMap

func NewArrayMap(name string, debug *models.Debug, m map[string]Object) Object

func NewBool

func NewBool(name string, b bool, debug *models.Debug) Object

func NewFloat

func NewFloat(name string, f float64, debug *models.Debug) Object

NewFloat creates a new float object

func NewFn

func NewFn(name string, debug *models.Debug, fn Method) Object

func NewIOStream

func NewIOStream(name string, r io.Reader) Object

func NewInteger

func NewInteger(name string, i int, debug *models.Debug) Object

func NewList

func NewList(name string, li []Object, debug *models.Debug) Object

NewList creates a new list object

func NewNil

func NewNil(name string, debug *models.Debug) Object

func NewRef

func NewRef(name string, debug *models.Debug, r Object) Object

func NewString

func NewString(name, s string, debug *models.Debug) Object

NewString creates a new string object

type Ref

type Ref struct {
	Base
	// contains filtered or unexported fields
}

func (*Ref) Copy

func (r *Ref) Copy() Object

func (*Ref) Method

func (r *Ref) Method(name string) Method

func (*Ref) Methods

func (r *Ref) Methods() []string

func (*Ref) Name

func (r *Ref) Name() string

func (*Ref) SetVariable

func (r *Ref) SetVariable(name string, value Object) error

func (*Ref) String

func (r *Ref) String() string

func (*Ref) Type

func (r *Ref) Type() ObjType

func (*Ref) Value

func (r *Ref) Value() any

func (*Ref) Variable

func (r *Ref) Variable(name string) Object

func (*Ref) Variables

func (r *Ref) Variables() []string

type String

type String struct {
	Base
	// contains filtered or unexported fields
}

String represents a string object

func (*String) Copy

func (s *String) Copy() Object

func (*String) Method

func (s *String) Method(name string) Method

func (*String) Methods

func (s *String) Methods() []string

func (*String) SetVariable

func (s *String) SetVariable(_ string, _ Object) error

func (*String) String

func (s *String) String() string

func (*String) Type

func (s *String) Type() ObjType

func (*String) Value

func (s *String) Value() any

func (*String) Variable

func (s *String) Variable(variable string) Object

func (*String) Variables

func (s *String) Variables() []string

type TypeSafeArg

type TypeSafeArg struct {
	Name string
	Type ObjType
}

type VariadicMethod

type VariadicMethod interface {
	Method
	// HasVariadicArg returns if the method has a variadic argument
	HasVariadicArg() bool
	// GetVariadicArg returns the variadic argument of the method
	GetVariadicArg() string
}

VariadicMethod represents a variadic method in the language

Jump to

Keyboard shortcuts

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