eval

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 12 Imported by: 11

Documentation

Index

Constants

View Source
const Prompt = "\033[32m\033[0m > "

Variables

This section is empty.

Functions

func CheckVariableName

func CheckVariableName(lbl parser.TokLabel, paramIdx int, param Result) error

func ErrorMessage

func ErrorMessage(lbl parser.TokLabel, msg string) string

func HookFunction

func HookFunction(foo Function) error

func InvalidVarName

func InvalidVarName(lbl parser.TokLabel, paramIdx int, param Result) error

func IsFunction

func IsFunction(tok parser.TokLabel) bool

func RunLoop added in v0.4.0

func RunLoop()

func TooFewArgs

func TooFewArgs(lbl parser.TokLabel, provided int, expected int) error

func TooManyArgs

func TooManyArgs(lbl parser.TokLabel, provided int, expected int) error

func Validate

func Validate(env *Environment, tok parser.TokLabel, stack *StackFrame) error

func WrongNumberOfArgs

func WrongNumberOfArgs(lbl parser.TokLabel, provided int, expected int) error

func WrongTypeOfArg

func WrongTypeOfArg(lbl parser.TokLabel, paramIdx int, param Result) error

Types

type CharSequenceResult

type CharSequenceResult struct{ Val string }

Symbol is used to identify variables or functions

func NewCharSequenceResult

func NewCharSequenceResult(label string) *CharSequenceResult

func (CharSequenceResult) DeepCopy added in v0.3.0

func (r CharSequenceResult) DeepCopy() Result

func (*CharSequenceResult) SetValue

func (r *CharSequenceResult) SetValue(value interface{}) error

func (CharSequenceResult) String

func (r CharSequenceResult) String() string

func (CharSequenceResult) Tidy

func (r CharSequenceResult) Tidy()

func (CharSequenceResult) Type

func (r CharSequenceResult) Type() types.Type

func (CharSequenceResult) Value

func (r CharSequenceResult) Value() interface{}

type DictResult

type DictResult struct {
	Header []string
	Values map[string][]Result
}

DictResult represents a dictionary, map

func NewDictResult

func NewDictResult(head ...string) *DictResult

func (*DictResult) AddPair

func (r *DictResult) AddPair(k string, v ...Result) error

func (DictResult) DeepCopy added in v0.3.0

func (r DictResult) DeepCopy() Result

func (*DictResult) Merge

func (r *DictResult) Merge(other *DictResult) *DictResult

func (*DictResult) SetValue

func (r *DictResult) SetValue(value interface{}) error

func (DictResult) String

func (r DictResult) String() string

func (DictResult) Tidy

func (r DictResult) Tidy()

func (DictResult) Type

func (r DictResult) Type() types.Type

func (DictResult) Value

func (r DictResult) Value() interface{}

type EmptyResult

type EmptyResult struct{}

EmptyResult represents the empty set a.k.a. as null or nil

func NewEmptyResult

func NewEmptyResult() *EmptyResult

func (EmptyResult) DeepCopy added in v0.3.0

func (r EmptyResult) DeepCopy() Result

func (*EmptyResult) SetValue

func (r *EmptyResult) SetValue(value interface{}) error

func (EmptyResult) String

func (r EmptyResult) String() string

func (EmptyResult) Tidy

func (r EmptyResult) Tidy()

func (EmptyResult) Type

func (r EmptyResult) Type() types.Type

func (EmptyResult) Value

func (r EmptyResult) Value() interface{}

type Environment

type Environment struct {
	Bindings map[string]Result
}

func NewEnvironment

func NewEnvironment() *Environment

func (*Environment) Bind

func (env *Environment) Bind(variable string, value Result)

func (*Environment) DeepCopy added in v0.0.2

func (env *Environment) DeepCopy() *Environment

func (*Environment) GC

func (env *Environment) GC()

func (*Environment) NewStack

func (env *Environment) NewStack() *Stack

func (*Environment) Tidy

func (env *Environment) Tidy()

type Evaluator

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

func NewEvaluator

func NewEvaluator(env *Environment) Evaluator

func (*Evaluator) After

func (t *Evaluator) After()

func (*Evaluator) Before

func (t *Evaluator) Before()

func (*Evaluator) Enter

func (t *Evaluator) Enter(expression *parser.Sexpression) (bool, error)

func (*Evaluator) Leave

func (t *Evaluator) Leave(expression *parser.Sexpression) error

func (*Evaluator) Result

func (t *Evaluator) Result() Result

type Function

type Function interface {
	// Desc returns documentation showing the structure of the command and a
	// description text
	Desc() (string, string)
	// Symbol returns the symbol under which the function is available
	Symbol() parser.TokLabel
	// Validate return an error if there is a mismatch between the parameters
	// on the stack and the function requirements
	Validate(env *Environment, stack *StackFrame) error
	// Evaluate implements the function semantics and returns a Result object
	// that wraps the results of the computation
	Evaluate(env *Environment, stack *StackFrame) (Result, error)
}

Function is an interface to add new functionality

func NewFunctionAdd

func NewFunctionAdd() (Function, error)

func NewFunctionBindings

func NewFunctionBindings() (Function, error)

func NewFunctionComment added in v0.4.0

func NewFunctionComment() (Function, error)

func NewFunctionConcat

func NewFunctionConcat() (Function, error)

func NewFunctionDef

func NewFunctionDef() (Function, error)

func NewFunctionDesc

func NewFunctionDesc() (Function, error)

func NewFunctionDict

func NewFunctionDict() (Function, error)

func NewFunctionEval added in v0.6.0

func NewFunctionEval() (Function, error)

func NewFunctionIdentifier

func NewFunctionIdentifier() (Function, error)

func NewFunctionInt

func NewFunctionInt() (Function, error)

func NewFunctionKeyword

func NewFunctionKeyword() (Function, error)

func NewFunctionPair

func NewFunctionPair() (Function, error)

func NewFunctionQuote added in v0.6.0

func NewFunctionQuote() (Function, error)

func NewFunctionResolve

func NewFunctionResolve() (Function, error)

func NewFunctionRoot

func NewFunctionRoot() (Function, error)

func NewFunctionString

func NewFunctionString() (Function, error)

func NewFunctionTidy

func NewFunctionTidy() (Function, error)

func NewFunctionVec

func NewFunctionVec() (Function, error)

type FunctionAdd

type FunctionAdd struct{}

func (*FunctionAdd) Desc

func (f *FunctionAdd) Desc() (string, string)

func (*FunctionAdd) Evaluate

func (f *FunctionAdd) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionAdd) Symbol

func (f *FunctionAdd) Symbol() parser.TokLabel

func (*FunctionAdd) Validate

func (f *FunctionAdd) Validate(env *Environment, stack *StackFrame) error

type FunctionBindings

type FunctionBindings struct{}

func (*FunctionBindings) Desc

func (f *FunctionBindings) Desc() (string, string)

func (*FunctionBindings) Evaluate

func (f *FunctionBindings) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionBindings) Symbol

func (f *FunctionBindings) Symbol() parser.TokLabel

func (*FunctionBindings) Validate

func (f *FunctionBindings) Validate(env *Environment, stack *StackFrame) error

type FunctionComment added in v0.4.0

type FunctionComment struct{}

this function is useful to extract comments

func (*FunctionComment) Desc added in v0.4.0

func (f *FunctionComment) Desc() (string, string)

func (*FunctionComment) Evaluate added in v0.4.0

func (f *FunctionComment) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionComment) Symbol added in v0.4.0

func (f *FunctionComment) Symbol() parser.TokLabel

func (*FunctionComment) Validate added in v0.4.0

func (f *FunctionComment) Validate(env *Environment, stack *StackFrame) error

type FunctionConcat

type FunctionConcat struct{}

func (*FunctionConcat) Desc

func (f *FunctionConcat) Desc() (string, string)

func (*FunctionConcat) Evaluate

func (f *FunctionConcat) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionConcat) Symbol

func (f *FunctionConcat) Symbol() parser.TokLabel

func (*FunctionConcat) Validate

func (f *FunctionConcat) Validate(env *Environment, stack *StackFrame) error

type FunctionDef

type FunctionDef struct{}

func (*FunctionDef) Desc

func (f *FunctionDef) Desc() (string, string)

func (*FunctionDef) Evaluate

func (f *FunctionDef) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionDef) Symbol

func (f *FunctionDef) Symbol() parser.TokLabel

func (*FunctionDef) Validate

func (f *FunctionDef) Validate(env *Environment, stack *StackFrame) error

type FunctionDesc

type FunctionDesc struct{}

func (*FunctionDesc) Desc

func (f *FunctionDesc) Desc() (string, string)

func (*FunctionDesc) Evaluate

func (f *FunctionDesc) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionDesc) Symbol

func (f *FunctionDesc) Symbol() parser.TokLabel

func (*FunctionDesc) Validate

func (f *FunctionDesc) Validate(env *Environment, stack *StackFrame) error

type FunctionDict

type FunctionDict struct{}

func (*FunctionDict) Desc

func (f *FunctionDict) Desc() (string, string)

func (*FunctionDict) Evaluate

func (f *FunctionDict) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionDict) Symbol

func (f *FunctionDict) Symbol() parser.TokLabel

func (*FunctionDict) Validate

func (f *FunctionDict) Validate(env *Environment, stack *StackFrame) error

type FunctionEval added in v0.6.0

type FunctionEval struct{}

func (*FunctionEval) Desc added in v0.6.0

func (f *FunctionEval) Desc() (string, string)

func (*FunctionEval) Evaluate added in v0.6.0

func (f *FunctionEval) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionEval) Symbol added in v0.6.0

func (f *FunctionEval) Symbol() parser.TokLabel

func (*FunctionEval) Validate added in v0.6.0

func (f *FunctionEval) Validate(env *Environment, stack *StackFrame) error

type FunctionPair

type FunctionPair struct{}

func (*FunctionPair) Desc

func (f *FunctionPair) Desc() (string, string)

func (*FunctionPair) Evaluate

func (f *FunctionPair) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionPair) Symbol

func (f *FunctionPair) Symbol() parser.TokLabel

func (*FunctionPair) Validate

func (f *FunctionPair) Validate(env *Environment, stack *StackFrame) error

type FunctionQuote added in v0.6.0

type FunctionQuote struct{}

func (*FunctionQuote) Desc added in v0.6.0

func (f *FunctionQuote) Desc() (string, string)

func (*FunctionQuote) Evaluate added in v0.6.0

func (f *FunctionQuote) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionQuote) Symbol added in v0.6.0

func (f *FunctionQuote) Symbol() parser.TokLabel

func (*FunctionQuote) Validate added in v0.6.0

func (f *FunctionQuote) Validate(env *Environment, stack *StackFrame) error

type FunctionResolve

type FunctionResolve struct{}

func (*FunctionResolve) Desc

func (f *FunctionResolve) Desc() (string, string)

func (*FunctionResolve) Evaluate

func (f *FunctionResolve) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionResolve) Symbol

func (f *FunctionResolve) Symbol() parser.TokLabel

func (*FunctionResolve) Validate

func (f *FunctionResolve) Validate(env *Environment, stack *StackFrame) error

type FunctionRoot

type FunctionRoot struct{}

func (*FunctionRoot) Desc

func (f *FunctionRoot) Desc() (string, string)

func (*FunctionRoot) Evaluate

func (f *FunctionRoot) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionRoot) Symbol

func (f *FunctionRoot) Symbol() parser.TokLabel

func (*FunctionRoot) Validate

func (f *FunctionRoot) Validate(env *Environment, stack *StackFrame) error

type FunctionTidy

type FunctionTidy struct{}

func (*FunctionTidy) Desc

func (f *FunctionTidy) Desc() (string, string)

func (*FunctionTidy) Evaluate

func (f *FunctionTidy) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionTidy) Symbol

func (f *FunctionTidy) Symbol() parser.TokLabel

func (*FunctionTidy) Validate

func (f *FunctionTidy) Validate(env *Environment, stack *StackFrame) error

type FunctionVec

type FunctionVec struct{}

func (*FunctionVec) Desc

func (f *FunctionVec) Desc() (string, string)

func (*FunctionVec) Evaluate

func (f *FunctionVec) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FunctionVec) Symbol

func (f *FunctionVec) Symbol() parser.TokLabel

func (*FunctionVec) Validate

func (f *FunctionVec) Validate(env *Environment, stack *StackFrame) error

type FurnishIdentifier

type FurnishIdentifier struct{}

func (*FurnishIdentifier) Desc

func (f *FurnishIdentifier) Desc() (string, string)

func (*FurnishIdentifier) Evaluate

func (f *FurnishIdentifier) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FurnishIdentifier) Symbol

func (f *FurnishIdentifier) Symbol() parser.TokLabel

func (*FurnishIdentifier) Validate

func (f *FurnishIdentifier) Validate(env *Environment, stack *StackFrame) error

type FurnishInt

type FurnishInt struct{}

func (*FurnishInt) Desc

func (f *FurnishInt) Desc() (string, string)

func (*FurnishInt) Evaluate

func (f *FurnishInt) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FurnishInt) Symbol

func (f *FurnishInt) Symbol() parser.TokLabel

func (*FurnishInt) Validate

func (f *FurnishInt) Validate(env *Environment, stack *StackFrame) error

type FurnishKeyword

type FurnishKeyword struct{}

func (*FurnishKeyword) Desc

func (f *FurnishKeyword) Desc() (string, string)

func (*FurnishKeyword) Evaluate

func (f *FurnishKeyword) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FurnishKeyword) Symbol

func (f *FurnishKeyword) Symbol() parser.TokLabel

func (*FurnishKeyword) Validate

func (f *FurnishKeyword) Validate(env *Environment, stack *StackFrame) error

type FurnishString

type FurnishString struct{}

func (*FurnishString) Desc

func (f *FurnishString) Desc() (string, string)

func (*FurnishString) Evaluate

func (f *FurnishString) Evaluate(env *Environment, stack *StackFrame) (Result, error)

func (*FurnishString) Symbol

func (f *FurnishString) Symbol() parser.TokLabel

func (*FurnishString) Validate

func (f *FurnishString) Validate(env *Environment, stack *StackFrame) error

type IntResult

type IntResult struct{ Val int }

IntResult represents an int

func NewIntResult

func NewIntResult(value int) *IntResult

func (IntResult) DeepCopy added in v0.3.0

func (r IntResult) DeepCopy() Result

func (*IntResult) SetValue

func (r *IntResult) SetValue(value interface{}) error

func (IntResult) String

func (r IntResult) String() string

func (IntResult) Tidy

func (r IntResult) Tidy()

func (IntResult) Type

func (r IntResult) Type() types.Type

func (IntResult) Value

func (r IntResult) Value() interface{}

type KeyWordResult

type KeyWordResult struct{ Val string }

KeywordResult is used for dictionary/hash keys

func NewKeyWordResult

func NewKeyWordResult(value string) *KeyWordResult

func (KeyWordResult) DeepCopy added in v0.3.0

func (r KeyWordResult) DeepCopy() Result

func (*KeyWordResult) SetValue

func (r *KeyWordResult) SetValue(value interface{}) error

func (KeyWordResult) String

func (r KeyWordResult) String() string

func (KeyWordResult) Tidy

func (r KeyWordResult) Tidy()

func (KeyWordResult) Type

func (r KeyWordResult) Type() types.Type

func (KeyWordResult) Value

func (r KeyWordResult) Value() interface{}

type Result

type Result interface {
	DeepCopy() Result
	String() string
	Type() types.Type
	Value() interface{}
	SetValue(interface{}) error
	Tidy()
}

Result represents values computed by the evalation of S-epxressions

func Evaluate

func Evaluate(env *Environment, tok parser.TokLabel, stack *StackFrame) (Result, error)

func EvaluateExpression

func EvaluateExpression(expression string) (Result, error)

func EvaluateExpressionWithEnv

func EvaluateExpressionWithEnv(expression string, env *Environment) (Result, error)

func Run added in v0.4.0

func Run(scriptcontent string) (Result, error)

func RunScriptPath added in v0.4.0

func RunScriptPath(scriptpath string) (Result, error)

type SexpressionResult added in v0.6.0

type SexpressionResult struct{ Exp *parser.Sexpression }

SexpressoinResult is used for dictionary/hash keys

func NewSexpressionResult added in v0.6.0

func NewSexpressionResult(expression *parser.Sexpression) *SexpressionResult

func (SexpressionResult) DeepCopy added in v0.6.0

func (r SexpressionResult) DeepCopy() Result

func (*SexpressionResult) SetValue added in v0.6.0

func (r *SexpressionResult) SetValue(value interface{}) error

func (SexpressionResult) String added in v0.6.0

func (r SexpressionResult) String() string

func (SexpressionResult) Tidy added in v0.6.0

func (r SexpressionResult) Tidy()

func (SexpressionResult) Type added in v0.6.0

func (r SexpressionResult) Type() types.Type

func (SexpressionResult) Value added in v0.6.0

func (r SexpressionResult) Value() interface{}

type Stack

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

func (*Stack) Empty

func (s *Stack) Empty() bool

func (*Stack) Items

func (s *Stack) Items() []StackFrame

func (*Stack) PeekStackFrame

func (stack *Stack) PeekStackFrame() *StackFrame

func (*Stack) PopStackFrame

func (s *Stack) PopStackFrame() *StackFrame

func (*Stack) PushStackFrame

func (s *Stack) PushStackFrame() *StackFrame

type StackFrame

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

func (*StackFrame) Append

func (stack *StackFrame) Append(other *StackFrame)

func (*StackFrame) Empty

func (stack *StackFrame) Empty() bool

func (*StackFrame) GetArgument added in v0.2.0

func (stack *StackFrame) GetArgument(index int) Result

func (*StackFrame) Items

func (s *StackFrame) Items() []Result

func (*StackFrame) Peek

func (stack *StackFrame) Peek() Result

func (*StackFrame) Pop

func (stack *StackFrame) Pop() Result

func (*StackFrame) Push

func (stack *StackFrame) Push(item Result)

func (*StackFrame) Reset

func (stack *StackFrame) Reset()

func (*StackFrame) Size

func (stack *StackFrame) Size() int

type StringResult

type StringResult struct{ Val string }

StringResult is used for strings

func NewStringResult

func NewStringResult(value string) *StringResult

func (StringResult) DeepCopy added in v0.3.0

func (r StringResult) DeepCopy() Result

func (*StringResult) SetValue

func (r *StringResult) SetValue(value interface{}) error

func (StringResult) String

func (r StringResult) String() string

func (StringResult) Tidy

func (r StringResult) Tidy()

func (StringResult) Type

func (r StringResult) Type() types.Type

func (StringResult) Value

func (r StringResult) Value() interface{}

type SymbolResult

type SymbolResult struct{ Val string }

Symbol is used to identify variables or functions

func NewSymbolResult

func NewSymbolResult(label string) *SymbolResult

func (SymbolResult) DeepCopy added in v0.3.0

func (r SymbolResult) DeepCopy() Result

func (*SymbolResult) SetValue

func (r *SymbolResult) SetValue(value interface{}) error

func (SymbolResult) String

func (r SymbolResult) String() string

func (SymbolResult) Tidy

func (r SymbolResult) Tidy()

func (SymbolResult) Type

func (r SymbolResult) Type() types.Type

func (SymbolResult) Value

func (r SymbolResult) Value() interface{}

type VecResult added in v0.1.0

type VecResult struct {
	Data []Result
}

VecResult represents a vector

func NewVecResult added in v0.1.0

func NewVecResult() *VecResult

func (*VecResult) AppendResult added in v0.1.0

func (r *VecResult) AppendResult(value Result) error

func (VecResult) DeepCopy added in v0.3.0

func (r VecResult) DeepCopy() Result

func (*VecResult) PrependResult added in v0.1.0

func (r *VecResult) PrependResult(value Result) error

func (*VecResult) SetValue added in v0.1.0

func (r *VecResult) SetValue(value interface{}) error

func (VecResult) String added in v0.1.0

func (r VecResult) String() string

func (VecResult) Tidy added in v0.1.0

func (r VecResult) Tidy()

func (VecResult) Type added in v0.1.0

func (r VecResult) Type() types.Type

func (VecResult) Value added in v0.1.0

func (r VecResult) Value() interface{}

Jump to

Keyboard shortcuts

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