interpreter

package
v0.0.0-...-5c6c84a Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorVariableExists "Variable already exists"
	ErrorVariableExists = errors.New("Variable already exists")
	// ErrorVariableDoesNotExist "Variable doesn't exist"
	ErrorVariableDoesNotExist = errors.New("Variable doesn't exist")
	// ErrorFunctionDoesNotExist "Function doesn't exist"
	ErrorFunctionDoesNotExist = errors.New("Function doesn't exist")
	// ErrorMaxDepth "Maximum depth is reached"
	ErrorMaxDepth = errors.New("Maximum depth is reached")
	// ErrorUserFunctionWrongCmd "Instructions in user functions should have valid "cmd" field"
	ErrorUserFunctionWrongCmd = errors.New("Instructions in user functions should have valid \"cmd\" field")
	// ErrorCannotConvertToFloat "Operands should be numeric"
	ErrorCannotConvertToFloat = errors.New("Operands should be numeric")
)

Functions

This section is empty.

Types

type FuncScope

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

FuncScope scope of functions

func NewFuncScope

func NewFuncScope(maxDepth int) *FuncScope

NewFuncScope creates new scrop of functions

func NewInternalFuncScope

func NewInternalFuncScope(output io.Writer, maxDepth int) *FuncScope

NewInternalFuncScope creates FuncScope and fills it with internal functions

func (*FuncScope) Execute

func (s *FuncScope) Execute(name string, globalVars, localVars *VarScope, internalFuncs, globalFuncs *FuncScope, depth int) (err error)

Execute executes requested function from scope and controls execution stack depth

func (*FuncScope) Set

func (s *FuncScope) Set(name string, f Function)

Set adds or updates function in stack by name

type Function

type Function interface {
	// Execute executes logic provided by Function object
	Execute(globalVars, localVars *VarScope, internalFuncs, globalFuncs *FuncScope, depth int) error
}

Function - basic function interface which describes Execute method

type Implementation

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

Implementation implements Interpreter interface

func (*Implementation) Run

func (i *Implementation) Run() error

Run starts execution of script

type Interpreter

type Interpreter interface {
	Run() error
}

Interpreter describes short interpreter interface

func NewInterpreter

func NewInterpreter(globalVars *VarScope, globalFuncs *FuncScope, output io.Writer, maxDepth int) Interpreter

NewInterpreter creates new instance of Implementation object

type UserFunction

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

UserFunction implements user-defined function which satisfy Function interface

func NewUserFunction

func NewUserFunction(body []map[string]string) *UserFunction

NewUserFunction creates user-defined function object from instruction list

func (UserFunction) Execute

func (f UserFunction) Execute(globalVars, localVars *VarScope, internalFuncs, globalFuncs *FuncScope, depth int) (err error)

Execute executes user-defined function

type VarScope

type VarScope struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

VarScope contains scope of execution variables

func NewVarScope

func NewVarScope() *VarScope

NewVarScope create new clean scope of variables

func (*VarScope) Create

func (s *VarScope) Create(name, val string) (err error)

Create creates new variable, fails when it does already exist

func (*VarScope) Delete

func (s *VarScope) Delete(name string) (err error)

Delete deletes variable from scope, fails when doesn't exist

func (*VarScope) Get

func (s *VarScope) Get(name string) (val string, err error)

Get returns variable from scope, returns 'undefined' when cannot find it

func (*VarScope) Set

func (s *VarScope) Set(name, val string)

Set creates of updates variable in scope

func (*VarScope) Update

func (s *VarScope) Update(name, val string) (err error)

Update updates existing variable, fails when it does not exist

Jump to

Keyboard shortcuts

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