object

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const BOOLEAN = "BOOLEAN"
View Source
const BREAK = "BREAK"
View Source
const CLASS = "CLASS"
View Source
const CONTINUE = "CONTINUE"
View Source
const ERROR = "ERROR"
View Source
const FUNCTION = "FUNCTION"
View Source
const INSTANCE = "INSTANCE"
View Source
const LIBRARY_FUNCTION = "LIBRARY_FUNCTION"
View Source
const LIBRARY_MODULE = "LIBRARY_MODULE"
View Source
const LIBRARY_PROPERTY = "LIBRARY_PROPERTY"
View Source
const LIST = "LIST"
View Source
const MAP = "MAP"
View Source
const NULL = "NULL"
View Source
const NUMBER = "NUMBER"
View Source
const RETURN = "RETURN"
View Source
const SCOPE = "SCOPE"
View Source
const STRING = "STRING"
View Source
const TRAIT = "TRAIT"

Variables

This section is empty.

Functions

func IsError

func IsError(obj Object) bool

IsError determines if the referenced object is an error.

func IsFalse

func IsFalse(obj Object) bool

func IsTrue

func IsTrue(obj Object) bool

func ObjectToAnyValue

func ObjectToAnyValue(val Object) any

func RegisterEvaluator

func RegisterEvaluator(e func(node ast.Node, scope *Scope) Object)

Types

type Boolean

type Boolean struct {
	Value bool
}

Boolean objects consist of a boolean value.

func (*Boolean) MapKey

func (boolean *Boolean) MapKey() MapKey

MapKey defines a unique hash value for use as a map key.

func (*Boolean) Method

func (boolean *Boolean) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on boolean objects.

func (*Boolean) String

func (boolean *Boolean) String() string

String represents the boolean object's value as a string.

func (*Boolean) Type

func (boolean *Boolean) Type() Type

Type returns the boolean object type.

type Break

type Break struct{}

Break objects consist of a nil value.

func (*Break) Method

func (obj *Break) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on break objects.

func (*Break) String

func (obj *Break) String() string

String represents the break object's value as a string.

func (*Break) Type

func (obj *Break) Type() Type

Type returns the break object type.

type Class

type Class struct {
	Name        *ast.Identifier
	Scope       *Scope
	Environment *Environment
	Super       *Class
	Traits      []*Trait
}

Class objects consist of a body and an environment.

func (*Class) Method

func (class *Class) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on class objects.

func (*Class) String

func (class *Class) String() string

String represents the class object's value as a string.

func (*Class) Type

func (class *Class) Type() Type

Type returns the class object type.

type Continue

type Continue struct{}

Continue objects consist of a nil value.

func (*Continue) Method

func (obj *Continue) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on continue objects.

func (*Continue) String

func (obj *Continue) String() string

String represents the continue object's value as a string.

func (*Continue) Type

func (obj *Continue) Type() Type

Type returns the continue object type.

type Environment

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

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

func (*Environment) All

func (environment *Environment) All() map[string]Object

func (*Environment) Call

func (environment *Environment) Call(function string, args []Object, writer io.Writer) Object

create a new function "Call" that can be used to call a function within the environment.

func (*Environment) Delete

func (environment *Environment) Delete(name string)

func (*Environment) Get

func (environment *Environment) Get(name string) (Object, bool)

func (*Environment) GetDirectory

func (environment *Environment) GetDirectory() string

func (*Environment) GetWriter

func (environment *Environment) GetWriter() io.Writer

func (*Environment) Has

func (environment *Environment) Has(name string) bool

func (*Environment) Set

func (environment *Environment) Set(name string, value Object) Object

func (*Environment) SetDirectory

func (environment *Environment) SetDirectory(directory string)

func (*Environment) SetWriter

func (environment *Environment) SetWriter(writer io.Writer)

type Error

type Error struct {
	Message string
}

Error objects consist of a nil value.

func NewError

func NewError(format string, a ...interface{}) *Error

func (*Error) Method

func (err *Error) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on error objects.

func (*Error) String

func (err *Error) String() string

String represents the error object's value as a string.

func (*Error) Type

func (err *Error) Type() Type

Type returns the error object type.

type Function

type Function struct {
	Parameters []*ast.Identifier
	Body       *ast.Block
	Defaults   map[string]ast.ExpressionNode
	Scope      *Scope
}

Function objects consist of a user-generated function.

func (*Function) Evaluate

func (function *Function) Evaluate(args []Object, writer io.Writer) Object

Evaluate evaluates the function's body ast.Block and returns the result.

func (*Function) Method

func (function *Function) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on function objects.

func (*Function) String

func (function *Function) String() string

String represents the function object's value as a string.

func (*Function) Type

func (function *Function) Type() Type

Type returns the function object type.

type GoFunction

type GoFunction func(scope *Scope, tok token.Token, args ...Object) Object

type GoProperty

type GoProperty func(scope *Scope, tok token.Token) Object

type HasMethods

type HasMethods interface {
	Method(method string, args []Object) (Object, bool)
}

type Instance

type Instance struct {
	Class       *Class
	Environment *Environment
}

Instance objects consist of a body and an environment.

func (*Instance) Call

func (instance *Instance) Call(name string, arguments []Object, tok token.Token) Object

func (*Instance) Method

func (instance *Instance) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on instance objects.

func (*Instance) String

func (instance *Instance) String() string

String represents the instance object's value as a string.

func (*Instance) Type

func (instance *Instance) Type() Type

Type returns the instance object type.

type LibraryFunction

type LibraryFunction struct {
	Name     string
	Function GoFunction
}

LibraryFunction objects consist of a native Go function.

func (*LibraryFunction) Method

func (libraryFunction *LibraryFunction) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on library function objects.

func (*LibraryFunction) String

func (libraryFunction *LibraryFunction) String() string

String represents the library function's value as a string.

func (*LibraryFunction) Type

func (libraryFunction *LibraryFunction) Type() Type

Type returns the library function object type.

type LibraryModule

type LibraryModule struct {
	Name       string
	Methods    map[string]*LibraryFunction
	Properties map[string]*LibraryProperty
}

LibraryModule objects consist of a slice of LibraryFunctions.

func (*LibraryModule) Method

func (libraryModule *LibraryModule) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on library module objects.

func (*LibraryModule) String

func (libraryModule *LibraryModule) String() string

String represents the library module's value as a string.

func (*LibraryModule) Type

func (libraryModule *LibraryModule) Type() Type

Type returns the library module object type.

type LibraryProperty

type LibraryProperty struct {
	Name     string
	Property GoProperty
}

LibraryProperty objects consist of a native Go property.

func (*LibraryProperty) Method

func (libraryProperty *LibraryProperty) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on library property objects.

func (*LibraryProperty) String

func (libraryProperty *LibraryProperty) String() string

String represents the library property's value as a string.

func (*LibraryProperty) Type

func (libraryProperty *LibraryProperty) Type() Type

Type returns the library property object type.

type List

type List struct {
	Elements []Object
}

List objects consist of a nil value.

func (*List) Method

func (list *List) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on list objects.

func (*List) String

func (list *List) String() string

String represents the list object's value as a string.

func (*List) Type

func (list *List) Type() Type

Type returns the list object type.

type Map

type Map struct {
	Pairs map[MapKey]MapPair
}

Map objects consist of a map value.

func NewMap

func NewMap(values map[string]interface{}) *Map

func (*Map) Method

func (mapObject *Map) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on map objects.

func (*Map) String

func (mapObject *Map) String() string

String represents the map object's value as a string.

func (*Map) Type

func (mapObject *Map) Type() Type

Type returns the map object type.

type MapKey

type MapKey struct {
	Type  Type
	Value uint64
}

type MapPair

type MapPair struct {
	Key   Object
	Value Object
}

type Mappable

type Mappable interface {
	MapKey() MapKey
}

type Null

type Null struct{}

Null objects consist of a nil value.

func (*Null) Method

func (null *Null) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on null objects.

func (*Null) String

func (null *Null) String() string

String represents the null object's value as a string.

func (*Null) Type

func (null *Null) Type() Type

Type returns the null object type.

type Number

type Number struct {
	Value decimal.Decimal
}

Number objects consist of a decimal value.

func (*Number) MapKey

func (number *Number) MapKey() MapKey

MapKey defines a unique hash value for use as a map key.

func (*Number) Method

func (number *Number) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on number objects.

func (*Number) String

func (number *Number) String() string

String represents the number object's value as a string.

func (*Number) Type

func (number *Number) Type() Type

Type returns the number object type.

type Object

type Object interface {
	HasMethods
	Type() Type
	String() string
}

Object is the interface for all object values.

func AnyValueToObject

func AnyValueToObject(val any) Object

type ObjectMethod

type ObjectMethod func(value interface{}, args ...Object) (Object, bool)

type Return

type Return struct {
	Value Object
}

Return objects consist of a value.

func (*Return) Method

func (obj *Return) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on return objects.

func (*Return) String

func (obj *Return) String() string

String represents the return object's value as a string.

func (*Return) Type

func (obj *Return) Type() Type

Type returns the return object type.

type Scope

type Scope struct {
	Environment *Environment
	Self        Object
}

Scope objects consist of an environment and parent object.

func (*Scope) Method

func (scope *Scope) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on scope objects.

func (*Scope) String

func (scope *Scope) String() string

String represents the scope object's value as a string.

func (*Scope) Type

func (scope *Scope) Type() Type

Type returns the scope object type.

type String

type String struct {
	Value string
}

String objects consist of a string value.

func (*String) MapKey

func (str *String) MapKey() MapKey

MapKey defines a unique hash value for use as a map key.

func (*String) Method

func (str *String) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on string objects.

func (*String) String

func (str *String) String() string

String represents the string object's value as a string. So meta.

func (*String) Type

func (str *String) Type() Type

Type returns the string object type.

type Trait added in v1.0.7

type Trait struct {
	Name        *ast.Identifier
	Scope       *Scope
	Environment *Environment
}

Trait objects consist of a body and an environment.

func (*Trait) Method added in v1.0.7

func (trait *Trait) Method(method string, args []Object) (Object, bool)

Method defines the set of methods available on trait objects.

func (*Trait) String added in v1.0.7

func (trait *Trait) String() string

String represents the class object's value as a string.

func (*Trait) Type added in v1.0.7

func (trait *Trait) Type() Type

Type returns the trait object type.

type Type

type Type string

Type is the type of the object given as a string.

Jump to

Keyboard shortcuts

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