gohanscript

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2018 License: Apache-2.0 Imports: 25 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTemplate

func ApplyTemplate(template *Template, param interface{}, context *Context) (result interface{})

ApplyTemplate apply template code for input params.

func CacheTemplate

func CacheTemplate(arg interface{}, templates map[string]*pongo2.Template, minigos map[string]*MiniGo) error

CacheTemplate caches template to the statement

func CompileFile

func CompileFile(file string) error

CompileFile compiles miniGo code and register func

func ContainsTemplate

func ContainsTemplate(arg interface{}) bool

ContainsTemplate checks an object contains template or not

func GetByKeys

func GetByKeys(keys []string, value interface{}) (interface{}, error)

GetByKeys get value from list of key

func KeyToList

func KeyToList(keys string) []string

KeyToList converts keys to string array

func LoadYAML

func LoadYAML(buf []byte) (*yaml.Node, error)

LoadYAML loads YAML from byte buffer

func LoadYAMLFile

func LoadYAMLFile(file string) (*yaml.Node, error)

LoadYAMLFile loads YAML from file

func MapToValue

func MapToValue(a map[string]interface{}) (result map[string]Value, err error)

MapToValue converts interface map to value map

func MappingNodeToMap

func MappingNodeToMap(node *yaml.Node) (result map[string]*yaml.Node)

MappingNodeToMap convert yaml node to map

func RegisterMiniGoFunc

func RegisterMiniGoFunc(name string, f MiniGoFunc)

RegisterMiniGoFunc register minigo func

func RegisterStmtParser

func RegisterStmtParser(funcName string, callback StmtParser)

RegisterStmtParser registers new parser per function

func RunTests

func RunTests(dir string) (total, success, failed int)

RunTests find tests under a directory and it executes them.

func StmtsToFunc

func StmtsToFunc(funcName string, stmts []*Stmt) (func(*Context) (interface{}, error), error)

StmtsToFunc creates list of func from stmts

Types

type Constant

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

Constant represents donburi consntant.

func (*Constant) Value

func (c *Constant) Value(context *Context) interface{}

Value returns constant value

type Context

type Context struct {
	VM *VM
	// contains filtered or unexported fields
}

Context is execution context in gohan script. Variables are stored in this context object.

func NewContext

func NewContext(vm *VM) *Context

NewContext makes data context

func (*Context) Clear

func (context *Context) Clear(key string)

Clear clears key

func (*Context) Data

func (context *Context) Data() map[string]interface{}

Data returns context data

func (*Context) Extend

func (context *Context) Extend(values map[string]interface{}) *Context

Extend clones context and extend it

func (*Context) Get

func (context *Context) Get(key string) (interface{}, error)

Get returns data from key

func (*Context) HasKey

func (context *Context) HasKey(key string) bool

HasKey checks if we have key

func (*Context) MayGet

func (context *Context) MayGet(key string) interface{}

MayGet returns data from key if it exists

func (*Context) MaybeInt

func (context *Context) MaybeInt(key string) int

MaybeInt returns a int

func (*Context) MaybeList

func (context *Context) MaybeList(key string) []interface{}

MaybeList resturns a List or nil

func (*Context) MaybeMap

func (context *Context) MaybeMap(key string) map[string]interface{}

MaybeMap resturns a Map or nil

func (*Context) MaybeString

func (context *Context) MaybeString(key string) string

MaybeString returns a string

func (*Context) Set

func (context *Context) Set(key string, value interface{})

Set set data in the context

func (*Context) SetByKeys

func (context *Context) SetByKeys(key string, value interface{})

SetByKeys set values in keys

func (*Context) SetMap

func (context *Context) SetMap(data map[string]interface{})

SetMap set entire data

type DebuggerRPC

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

DebuggerRPC is a proecess to handle remote debuggging

func (*DebuggerRPC) Command

func (d *DebuggerRPC) Command(param []byte, ack *string) error

Command accepts debug command

type Environment

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

Environment gohan script based environment for gohan extension

func NewEnvironment

func NewEnvironment() *Environment

NewEnvironment create new gohan extension environment based on context

func (*Environment) Clone

func (env *Environment) Clone() ext.Environment

Clone makes clone of the environment

func (*Environment) HandleEvent

func (env *Environment) HandleEvent(event string, context map[string]interface{}) (err error)

HandleEvent handles event

func (*Environment) IsEventHandled

func (env *Environment) IsEventHandled(event string, context map[string]interface{}) bool

IsEventHandled returns whether a given event is handled by this environment

func (*Environment) Load

func (env *Environment) Load(source, code string) error

Load loads script for environment

func (*Environment) LoadExtensionsForPath

func (env *Environment) LoadExtensionsForPath(extensions []*schema.Extension, timeLimit time.Duration, timeLimits []*schema.PathEventTimeLimit, path string) error

LoadExtensionsForPath for returns extensions for specific path

type Error

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

Error represent error for gohanscript

type MiniGo

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

MiniGo is tiny interpreter for evaluating small expression in the gohan script MiniGo uses go parser, and implements subset of functions

func CompileExpr

func CompileExpr(expr string) (*MiniGo, error)

CompileExpr compiles single line of code

func CompileGoStmt

func CompileGoStmt(file string) (*MiniGo, error)

CompileGoStmt compiles miniGo code and register func

func (*MiniGo) Eval

func (code *MiniGo) Eval(context *Context, offset int, stack *Stack) ([]interface{}, error)

Eval executes byte code.

func (*MiniGo) Run

func (code *MiniGo) Run(context *Context) (interface{}, error)

Run code with given context.

func (*MiniGo) String

func (code *MiniGo) String() string

type MiniGoFunc

type MiniGoFunc func(vm *VM, args []interface{}) []interface{}

MiniGoFunc represents function which can be used in minigo

type MiniGoValue

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

MiniGoValue reprensents minigo value

func NewMiniGoValue

func NewMiniGoValue(param interface{}) (*MiniGoValue, error)

NewMiniGoValue makes a MiniGoValue value

func (*MiniGoValue) Value

func (i *MiniGoValue) Value(context *Context) interface{}

Value returns nil

type Nil

type Nil struct {
}

Nil reprensents nil

func (*Nil) Value

func (i *Nil) Value(context *Context) interface{}

Value returns nil

type Op

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

Op ...

func (Op) String

func (op Op) String() string

type OpCode

type OpCode int

OpCode ...

const (
	// ILLEGAL tokens
	ILLEGAL OpCode = iota

	POP
	PUSH
	CALL
	GET
	SET

	// Identifiers and basic type literals
	// (these tokens stand for classes of literals)
	IDENT  // main
	INT    // 12345
	FLOAT  // 123.45
	IMAG   // 123.45i
	CHAR   // 'a'
	STRING // "abc"

	// Operators and delimiters
	ADD // +
	SUB // -
	MUL // *
	QUO // /
	REM // %

	AND     // &
	OR      // |
	XOR     // ^
	SHL     // <<
	SHR     // >>
	AND_NOT // &^

	ADD_ASSIGN // +=
	SUB_ASSIGN // -=
	MUL_ASSIGN // *=
	QUO_ASSIGN // /=
	REM_ASSIGN // %=

	AND_ASSIGN     // &=
	OR_ASSIGN      // |=
	XOR_ASSIGN     // ^=
	SHL_ASSIGN     // <<=
	SHR_ASSIGN     // >>=
	AND_NOT_ASSIGN // &^=

	LAND  // &&
	LOR   // ||
	ARROW // <-
	INC   // ++
	DEC   // --

	EQL    // ==
	LSS    // <
	GTR    // >
	ASSIGN // =
	NOT    // !

	NEQ      // !=
	LEQ      // <=
	GEQ      // >=
	DEFINE   // :=
	ELLIPSIS // ...

	GETPROP
	SETPROP
	INCPROP
	DECPROP

	GETINDEX
	SETINDEX
	INCINDEX
	DECINDEX

	GOTO
	GOTOIF

	RANGE

	RET
	SUB_UNARY
)

func (OpCode) String

func (i OpCode) String() string

type Stack

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

Stack express stack in running context

func NewStack

func NewStack() *Stack

NewStack makes stack

type Stmt

type Stmt struct {
	Name     string
	When     *MiniGo
	Until    *MiniGo
	File     string
	Dir      string
	Line     int
	Column   int
	Vars     map[string]Value
	Rescue   []*Stmt
	Always   []*Stmt
	ElseStmt []*Stmt

	Retry     int
	Delay     int
	Worker    int
	Args      map[string]Value
	WithItems Value
	LoopVar   string
	WithDict  Value
	Register  string
	RawData   map[string]interface{}
	RawNode   map[string]*yaml.Node
	// contains filtered or unexported fields
}

Stmt represents gohan script statement. Stmt is responseible to generate go function from YAML definitions.

func MakeStmts

func MakeStmts(FileName string, node *yaml.Node) ([]*Stmt, error)

MakeStmts parses multiple statesmantes

func NewStmt

func NewStmt(FileName string, node *yaml.Node) (stmt *Stmt, err error)

NewStmt makes gohan statement from yaml node

func (*Stmt) Arg

func (stmt *Stmt) Arg(key string, context *Context) interface{}

Arg get augument data using key and context

func (*Stmt) Error

func (stmt *Stmt) Error(err error) error

Error makes err with stmt information

func (*Stmt) Errorf

func (stmt *Stmt) Errorf(msg string, args ...interface{}) error

Errorf makes err with stmt information

func (*Stmt) Func

func (stmt *Stmt) Func() (func(context *Context) (interface{}, error), error)

Func generates function from stmt

func (*Stmt) HasArgs

func (stmt *Stmt) HasArgs(keys ...string) error

HasArgs checks if statement has functions

type StmtParser

type StmtParser func(stmt *Stmt) (func(*Context) (interface{}, error), error)

StmtParser converts gohan script statement for golang function. You can register your parser using RegisterStmtParser call, so that you can have new gohan script function implemented by go

func GetStmtParser

func GetStmtParser(funcName string) StmtParser

GetStmtParser returns parser for specific per function

type Template

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

Template reprensents a value includes templates

func NewTemplate

func NewTemplate(param interface{}) *Template

NewTemplate makes a template value

func (*Template) Value

func (t *Template) Value(context *Context) interface{}

Value applies new template value

type VM

type VM struct {
	Context *Context

	StopChan chan func()
	// contains filtered or unexported fields
}

VM is a struct for Gohan script.

func NewVM

func NewVM() *VM

NewVM creates a VM

func (*VM) Clone

func (vm *VM) Clone() *VM

Clone clones a VM

func (*VM) LoadFile

func (vm *VM) LoadFile(file string) error

LoadFile loads gohan script code from file and make func

func (*VM) LoadString

func (vm *VM) LoadString(fileName, yamlString string) error

LoadString loads gohan script code from string and make func

func (*VM) Run

func (vm *VM) Run(data map[string]interface{}) error

Run executes loaded funcs

func (*VM) RunFile

func (vm *VM) RunFile(file string) (interface{}, error)

RunFile load data from file and execute it

func (*VM) Stop

func (vm *VM) Stop()

Stop stops vm

func (*VM) String

func (vm *VM) String() string

type Value

type Value interface {
	Value(context *Context) interface{}
}

Value represents gohan script value interface

func NewValue

func NewValue(a interface{}) (Value, error)

NewValue makes gohan script value from an yaml data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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