runtime

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	Dependencies []*Value
}

type Array

type Array []*Value

type Builtin

type Builtin struct {
	Identifier string
	Symbol     *semantics.Symbol
	Value      *Value
}

Builtin is a globally available value

type DefaultRuntime

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

func CreateDefaultRuntime

func CreateDefaultRuntime() *DefaultRuntime

func (*DefaultRuntime) Add

func (runtime *DefaultRuntime) Add(left *Value, right *Value) *Value

func (*DefaultRuntime) And

func (runtime *DefaultRuntime) And(left *Value, right *Value) *Value

func (*DefaultRuntime) Define

func (runtime *DefaultRuntime) Define(identifier string, value *Value)

func (*DefaultRuntime) Divide

func (runtime *DefaultRuntime) Divide(left *Value, right *Value) *Value

func (*DefaultRuntime) Equals

func (runtime *DefaultRuntime) Equals(left *Value, right *Value) *Value

func (*DefaultRuntime) GreaterThan

func (runtime *DefaultRuntime) GreaterThan(left *Value, right *Value) *Value

func (*DefaultRuntime) GreaterThanOrEqual

func (runtime *DefaultRuntime) GreaterThanOrEqual(left *Value, right *Value) *Value

func (*DefaultRuntime) Index

func (runtime *DefaultRuntime) Index(left *Value, right *Value) *Value

func (*DefaultRuntime) LessThan

func (runtime *DefaultRuntime) LessThan(left *Value, right *Value) *Value

func (*DefaultRuntime) LessThanOrEqual

func (runtime *DefaultRuntime) LessThanOrEqual(left *Value, right *Value) *Value

func (*DefaultRuntime) Modulo

func (runtime *DefaultRuntime) Modulo(left *Value, right *Value) *Value

func (*DefaultRuntime) Multiply

func (runtime *DefaultRuntime) Multiply(left *Value, right *Value) *Value

func (*DefaultRuntime) Negative

func (runtime *DefaultRuntime) Negative(operand *Value) *Value

func (*DefaultRuntime) Not

func (runtime *DefaultRuntime) Not(operand *Value) *Value

func (*DefaultRuntime) NotEquals

func (runtime *DefaultRuntime) NotEquals(left *Value, right *Value) *Value

func (*DefaultRuntime) Or

func (runtime *DefaultRuntime) Or(left *Value, right *Value) *Value

func (*DefaultRuntime) PopScope

func (runtime *DefaultRuntime) PopScope()

func (*DefaultRuntime) PushScope

func (runtime *DefaultRuntime) PushScope(scopeType ScopeType)

func (*DefaultRuntime) Resolve

func (runtime *DefaultRuntime) Resolve(identifier string) *Value

func (*DefaultRuntime) ResolveEscapes

func (runtime *DefaultRuntime) ResolveEscapes(value string) string

func (*DefaultRuntime) Scope

func (runtime *DefaultRuntime) Scope() *Scope

func (*DefaultRuntime) Selector

func (runtime *DefaultRuntime) Selector(value *Value, identifier string) *Value

func (*DefaultRuntime) SetScope

func (runtime *DefaultRuntime) SetScope(scope *Scope)

func (*DefaultRuntime) Shell

func (runtime *DefaultRuntime) Shell(script string)

func (*DefaultRuntime) ShellFormat

func (runtime *DefaultRuntime) ShellFormat(value *Value) string

func (*DefaultRuntime) Subtract

func (runtime *DefaultRuntime) Subtract(left *Value, right *Value) *Value

type Delegate

type Delegate interface {
	Add(left *Value, right *Value) *Value
	Subtract(left *Value, right *Value) *Value
	Multiply(left *Value, right *Value) *Value
	Divide(left *Value, right *Value) *Value
	Modulo(left *Value, right *Value) *Value

	Equals(left *Value, right *Value) *Value
	NotEquals(left *Value, right *Value) *Value
	GreaterThan(left *Value, right *Value) *Value
	GreaterThanOrEqual(left *Value, right *Value) *Value
	LessThan(left *Value, right *Value) *Value
	LessThanOrEqual(left *Value, right *Value) *Value

	And(left *Value, right *Value) *Value
	Or(left *Value, right *Value) *Value

	Not(operand *Value) *Value
	Negative(operand *Value) *Value

	Shell(script string)
	ShellFormat(value *Value) string

	Index(left *Value, right *Value) *Value
	Selector(value *Value, identifier string) *Value

	ResolveEscapes(value string) string

	Define(identifier string, value *Value)
	Resolve(identifier string) *Value
	SetScope(scope *Scope)
	Scope() *Scope
	PushScope(scopeType ScopeType)
	PopScope()
}

Delegate handles runtime-specific evaluations. Functions may panic

type Engine

type Engine struct {
	Delegate Delegate
	// contains filtered or unexported fields
}

func CreateEngine

func CreateEngine(delegate Delegate) *Engine

func (*Engine) Evaluate

func (engine *Engine) Evaluate(source *ast.Block) (err error)

func (*Engine) EvaluateTask

func (engine *Engine) EvaluateTask(task string) (err error)

type Function

type Function struct {
	// Arguments to define before executing the block. Only used when evaluating the Block
	Arguments []string
	// Block is the AST block that will be executed on invocation. Block and Handler are mutually exclusive.
	Block *ast.Block
	// Handler is the callback that should handle the invocation. Block and Handler are mutually exclusive.
	Handler        FunctionHandler
	IsRuleFunction bool
}

type FunctionHandler

type FunctionHandler func(engine *Engine, arguments []*Value) *Value

type Object

type Object map[string]*Value

type Program

type Program struct {
	Input     string
	Source    *ast.Block
	RootScope *semantics.Scope
	Builtins  map[string]*Builtin
	Engine    *Engine
	Delegate  Delegate
}

func CreateProgram

func CreateProgram(input string, delegate Delegate) *Program

func (*Program) BuildSymbols

func (program *Program) BuildSymbols() []error

func (*Program) DefineBuiltinFunction

func (program *Program) DefineBuiltinFunction(identifier string, arguments int, handler FunctionHandler)

DefineBuiltinFunction defines as new, globally available function

func (*Program) DefineBuiltinSymbols

func (program *Program) DefineBuiltinSymbols()

DefineBuiltinSymbols declares symbols in the global scope

func (*Program) DefineBuiltinValue

func (program *Program) DefineBuiltinValue(identifier string, valueType ValueType, traits semantics.Trait, value interface{})

func (*Program) DefineBuiltinValues

func (program *Program) DefineBuiltinValues()

DefineBuiltinSymbols defines the values in the delegate's scope

func (*Program) Parse

func (program *Program) Parse() error

func (*Program) Run

func (program *Program) Run() error

Run executes a program

func (*Program) RunTask

func (program *Program) RunTask(task string) error

RunTask executes a specific task

func (*Program) Validate

func (program *Program) Validate() []error

type Rule

type Rule struct {
	Outputs      []string
	Dependencies []*Value
	// Block is the AST block that will be executed on invocation
	Block *ast.Block
}

type RuntimeError

type RuntimeError struct {
	Message string
}

func CreateRuntimeError

func CreateRuntimeError(message string) *RuntimeError

func (*RuntimeError) Error

func (err *RuntimeError) Error() string

type Scope

type Scope struct {
	ParentScope *Scope
	Values      map[string]*Value
	Type        ScopeType
}

func CreateScope

func CreateScope(parentScope *Scope, scopeType ScopeType) *Scope

func (*Scope) CreateScope

func (scope *Scope) CreateScope(scopeType ScopeType) *Scope

func (*Scope) Define

func (scope *Scope) Define(identifier string, value *Value)

func (*Scope) Lookup

func (scope *Scope) Lookup(identifier string) *Value

Lookup looks up an identifier upward the scope tree. Returns nil if not found

type ScopeType

type ScopeType int
const (
	ScopeTypeFunction ScopeType = iota
	ScopeTypeRuleFunction
	ScopeTypeRule
	ScopeTypeGeneric
	ScopeTypeGlobal
)

type Value

type Value struct {
	Type     ValueType
	Value    interface{}
	Exported bool
}

func (*Value) String

func (value *Value) String() string

type ValueType

type ValueType int
const (
	ValueTypeNumber ValueType = iota
	ValueTypeString
	ValueTypeBool
	ValueTypeFunction
	ValueTypeRuleFunction
	ValueTypeRule
	ValueTypeNone
	ValueTypeArray
	ValueTypeAlias
	ValueTypeObject
)

func (ValueType) String

func (i ValueType) String() string

Jump to

Keyboard shortcuts

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