eval

package
v0.0.0-...-3085ebc Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NUMBER_OBJ       = "NUMBER"
	NIL_OBJ          = "NIL_OBJ"
	BOOLEAN_OBJ      = "BOOLEAN"
	STRING_OBJ       = "STRING"
	ERROR_OBJ        = "ERROR"
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	FUNCTION_OBJ     = "FUNCTION"
	BUILTIN_OBJ      = "BUILTIN"
	ARRAY_OBJ        = "ARRAY"
	TUPLE_OBJ        = "TUPLE"
	HASH_OBJ         = "HASH"
	BREAK_OBJ        = "BREAK"
	CONTINUE_OBJ     = "CONTINUE"
	FALLTHROUGH_OBJ  = "FALLTHROUGH"
	REGEX_OBJ        = "REGEX"
	GO_OBJ           = "GO_OBJ"
	GFO_OBJ          = "GFO_OBJ"
	FILE_OBJ         = "FILE"
	OS_OBJ           = "OS_OBJ"
	STRUCT_OBJ       = "STRUCT"
	THROW_OBJ        = "THROW"
	TAIL_OBJ         = "TAIL_OBJ"
	CMD_OBJ          = "CMD_OBJ"
)

Variables

View Source
var (
	ERR_ARGUMENT        = "wrong number of arguments. expected=%d, got=%d"
	ERR_NOMETHOD        = "undefined method '%s' for object %s"
	ERR_NOMETHODEX      = "undefined method '%s.%s', Did you mean '%s.%s'?"
	ERR_INDEX           = "index error: '%d' out of range"
	ERR_KEY             = "key error: type %s is not hashable"
	ERR_PREFIXOP        = "unsupported operator for prefix expression:'%s' and type: %s"
	ERR_INFIXOP         = "unsupported operator for infix expression: %s '%s' %s"
	ERR_POSTFIXOP       = "unsupported operator for postfix expression:'%s' and type: %s"
	ERR_UNKNOWNIDENT    = "unknown identifier: '%s' is not defined"
	ERR_DIVIDEBYZERO    = "divide by zero"
	ERR_NOTFUNCTION     = "expect a function, got %s"
	ERR_PARAMTYPE       = "%s argument for '%s' should be type %s. got=%s"
	ERR_NOTITERABLE     = "foreach's operating type must be iterable"
	ERR_IMPORT          = "import error: %s"
	ERR_NAMENOTEXPORTED = "cannot refer to unexported name %s.%s"
	ERR_INVALIDARG      = "invalid argument supplied"
	ERR_NOINDEXABLE     = "index error: type %s is not indexable"
	ERR_NOTREGEXP       = "right type is not a regexp object, got %s"
	ERR_NOCONSTRUCTOR   = "got %d parameters, but the struct has no 'init' method supplied"
	ERR_THROWNOTHANDLED = "throw object '%s' not handled"
	ERR_RANGETYPE       = "range(..) type should be %s type, got %s"
	ERR_MULTIASSIGN     = "the number of names and values are not equal"
	ERR_DECORATOR       = "decorator '%s' is not a function"
	ERR_DECORATED_NAME  = "can not find the name of the decorated function"
	ERR_DECORATOR_FN    = "a decorator must decorate a named function or another decorator"
)
View Source
var (
	ERR_HASDOT           = errors.New("symbol contains '.'")
	ERR_VALUENOTFUNCTION = errors.New("symbol value not function")
)
View Source
var (
	TRUE        = &Boolean{Bool: true}
	FALSE       = &Boolean{Bool: false}
	BREAK       = &Break{}
	CONTINUE    = &Continue{}
	FALLTHROUGH = &Fallthrough{}
	NIL         = &Nil{}
)
View Source
var ALL_ARGS = "$_"
View Source
var GlobalScopes map[string]Object = make(map[string]Object)

Functions

func InterpolateString

func InterpolateString(str string, scope *Scope) string

func IsTrue

func IsTrue(obj Object) bool

func ObjectToGoValue

func ObjectToGoValue(obj Object, typ reflect.Type) reflect.Value

Magpie language Object to go language Value.

func RegisterGoFunctions

func RegisterGoFunctions(name string, vars map[string]interface{}) error

func RegisterGoVars

func RegisterGoVars(name string, vars map[string]interface{}) error

func SetGlobalObj

func SetGlobalObj(name string, Obj Object)

Types

type Array

type Array struct {
	Members []Object
}

func (*Array) CallMethod

func (a *Array) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Array) Inspect

func (a *Array) Inspect() string

func (*Array) Type

func (a *Array) Type() ObjectType

type Boolean

type Boolean struct {
	Bool bool
}

func NewBooleanObj

func NewBooleanObj(b bool) *Boolean

func (*Boolean) CallMethod

func (b *Boolean) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type Break

type Break struct{}

func (*Break) CallMethod

func (b *Break) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Break) Inspect

func (b *Break) Inspect() string

func (*Break) Type

func (b *Break) Type() ObjectType

type Builtin

type Builtin struct {
	Fn BuiltinFunc
}

func (*Builtin) CallMethod

func (b *Builtin) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunc

type BuiltinFunc func(line string, scope *Scope, args ...Object) Object

type Command

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

func (*Command) CallMethod

func (c *Command) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Command) Inspect

func (c *Command) Inspect() string

func (*Command) Type

func (c *Command) Type() ObjectType

type Continue

type Continue struct{}

func (*Continue) CallMethod

func (c *Continue) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Continue) Inspect

func (c *Continue) Inspect() string

func (*Continue) Type

func (c *Continue) Type() ObjectType

type Error

type Error struct {
	Message string
}

func (*Error) CallMethod

func (e *Error) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type Fallthrough

type Fallthrough struct{}

func (*Fallthrough) CallMethod

func (f *Fallthrough) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Fallthrough) Inspect

func (f *Fallthrough) Inspect() string

func (*Fallthrough) Type

func (f *Fallthrough) Type() ObjectType

type FileObject

type FileObject struct {
	File    *os.File
	Name    string
	Scanner *bufio.Scanner
}

func (*FileObject) CallMethod

func (f *FileObject) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*FileObject) Inspect

func (f *FileObject) Inspect() string

func (*FileObject) Type

func (f *FileObject) Type() ObjectType

type Formatter

type Formatter struct {
	Obj Object
}

This `Formatter` struct is mainly used to encapsulate golang `fmt` package's `Formatter` interface.

func (*Formatter) Format

func (ft *Formatter) Format(s fmt.State, verb rune)

type Function

type Function struct {
	Literal *ast.FunctionLiteral
	Scope   *Scope
}

func (*Function) CallMethod

func (f *Function) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type GoFuncObject

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

wrapper for go functions

func NewGoFuncObject

func NewGoFuncObject(fname string, fn interface{}) *GoFuncObject

func (*GoFuncObject) CallMethod

func (gfn *GoFuncObject) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*GoFuncObject) Inspect

func (gfn *GoFuncObject) Inspect() string

func (*GoFuncObject) Type

func (gfn *GoFuncObject) Type() ObjectType

type GoObject

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

Wrapper for go object

func NewGoObject

func NewGoObject(obj interface{}) *GoObject

func (*GoObject) CallMethod

func (gobj *GoObject) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*GoObject) Inspect

func (gobj *GoObject) Inspect() string

func (*GoObject) Type

func (gobj *GoObject) Type() ObjectType

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

func NewHash

func NewHash() *Hash

func (*Hash) CallMethod

func (h *Hash) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Hash) Inspect

func (h *Hash) Inspect() string

func (*Hash) Type

func (h *Hash) Type() ObjectType

type HashKey

type HashKey struct {
	Type  ObjectType
	Value uint64
}

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

type Hashable

type Hashable interface {
	HashKey() HashKey
}

type Iterable

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

Whether the Object is iterable (HASH, ARRAY, STRING, TUPLE, Some of the GoObject)

type Nil

type Nil struct {
}

func NewNil

func NewNil(s string) *Nil

func (*Nil) CallMethod

func (n *Nil) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Nil) Inspect

func (n *Nil) Inspect() string

func (*Nil) Type

func (n *Nil) Type() ObjectType

type Number

type Number struct {
	Value float64
}

func NewNumber

func NewNumber(f float64) *Number

func (*Number) CallMethod

func (n *Number) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Number) HashKey

func (n *Number) HashKey() HashKey

func (*Number) Inspect

func (n *Number) Inspect() string

func (*Number) Type

func (n *Number) Type() ObjectType

type Object

type Object interface {
	Type() ObjectType
	Inspect() string
	CallMethod(line string, scope *Scope, method string, args ...Object) Object
}

func Eval

func Eval(node ast.Node, scope *Scope) (val Object)

func GetGlobalObj

func GetGlobalObj(name string) (Object, bool)

func NewOsObj

func NewOsObj() Object

type ObjectType

type ObjectType string

object

type Os

type Os struct{}

func (*Os) CallMethod

func (o *Os) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Os) Inspect

func (o *Os) Inspect() string

func (*Os) Type

func (o *Os) Type() ObjectType

type RegEx

type RegEx struct {
	RegExp *regexp.Regexp
	Value  string
}

func (*RegEx) CallMethod

func (re *RegEx) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*RegEx) Inspect

func (re *RegEx) Inspect() string

func (*RegEx) Type

func (re *RegEx) Type() ObjectType

type ReturnValue

type ReturnValue struct {
	Value  Object   // for old campatibility
	Values []Object // return multiple values
}

func (*ReturnValue) CallMethod

func (rv *ReturnValue) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type Scope

type Scope struct {
	Writer io.Writer
	// contains filtered or unexported fields
}

func NewScope

func NewScope(p *Scope, w io.Writer) *Scope

func (*Scope) DebugPrint

func (s *Scope) DebugPrint(indent string)

func (*Scope) Del

func (s *Scope) Del(name string)

func (*Scope) Get

func (s *Scope) Get(name string) (Object, bool)

func (*Scope) GetAllExported

func (s *Scope) GetAllExported(anotherScope *Scope)

Get all exported to 'anotherScope'

func (*Scope) GetKeys

func (s *Scope) GetKeys() []string

Get all the keys of the scope.

func (*Scope) GetStruct

func (s *Scope) GetStruct(name string) (*ast.StructStatement, bool)

func (*Scope) Set

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

func (*Scope) SetStruct

func (s *Scope) SetStruct(structStmt *ast.StructStatement) *ast.StructStatement

type String

type String struct {
	String string
}

func NewString

func NewString(s string) *String

func (*String) CallMethod

func (s *String) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Type

func (s *String) Type() ObjectType

type Struct

type Struct struct {
	Scope *Scope //struct's scope
}

func (*Struct) CallMethod

func (s *Struct) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Struct) Inspect

func (s *Struct) Inspect() string

func (*Struct) Type

func (s *Struct) Type() ObjectType

type TailCall

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

func (*TailCall) CallMethod

func (tc *TailCall) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*TailCall) Inspect

func (tc *TailCall) Inspect() string

func (*TailCall) Type

func (tc *TailCall) Type() ObjectType

type Throw

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

func (*Throw) CallMethod

func (t *Throw) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Throw) Inspect

func (t *Throw) Inspect() string

func (*Throw) Type

func (t *Throw) Type() ObjectType

type Tuple

type Tuple struct {
	// Used in function return values.
	// if a function returns multiple values, they will wrap the results into a tuple,
	// the flag will be set to true
	IsMulti bool
	Members []Object
}

func NewTuple

func NewTuple(isMulti bool) *Tuple

func (*Tuple) CallMethod

func (t *Tuple) CallMethod(line string, scope *Scope, method string, args ...Object) Object

func (*Tuple) HashKey

func (t *Tuple) HashKey() HashKey

func (*Tuple) Inspect

func (t *Tuple) Inspect() string

func (*Tuple) Type

func (t *Tuple) Type() ObjectType

Jump to

Keyboard shortcuts

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