interpreter

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2019 License: MIT Imports: 7 Imported by: 8

Documentation

Overview

Package interpreter provides the implementation of the Flux interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoFunctionCall

func DoFunctionCall(f func(args Arguments) (values.Value, error), argsObj values.Object) (values.Value, error)

func ToFloatArray

func ToFloatArray(a values.Array) ([]float64, error)

func ToStringArray

func ToStringArray(a values.Array) ([]string, error)

Types

type Arguments

type Arguments interface {
	GetAll() []string
	Get(name string) (values.Value, bool)
	GetRequired(name string) (values.Value, error)

	GetString(name string) (string, bool, error)
	GetInt(name string) (int64, bool, error)
	GetFloat(name string) (float64, bool, error)
	GetBool(name string) (bool, bool, error)
	GetFunction(name string) (values.Function, bool, error)
	GetArray(name string, t semantic.Nature) (values.Array, bool, error)
	GetObject(name string) (values.Object, bool, error)

	GetRequiredString(name string) (string, error)
	GetRequiredInt(name string) (int64, error)
	GetRequiredFloat(name string) (float64, error)
	GetRequiredBool(name string) (bool, error)
	GetRequiredFunction(name string) (values.Function, error)
	GetRequiredArray(name string, t semantic.Nature) (values.Array, error)
	GetRequiredObject(name string) (values.Object, error)
	// contains filtered or unexported methods
}

Arguments provides access to the keyword arguments passed to a function. semantic.The Get{Type} methods return three values: the typed value of the arg, whether the argument was specified and any errors about the argument type. semantic.The GetRequired{Type} methods return only two values, the typed value of the arg and any errors, a missing argument is considered an error in this case.

func NewArguments

func NewArguments(obj values.Object) Arguments

type Importer added in v0.10.0

type Importer interface {
	semantic.Importer
	ImportPackageObject(path string) (*Package, bool)
}

Importer produces a package given an import path

type Interpreter

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

func NewInterpreter

func NewInterpreter() *Interpreter

func (*Interpreter) Eval

func (itrp *Interpreter) Eval(node semantic.Node, scope Scope, importer Importer) ([]values.Value, error)

Eval evaluates the expressions composing a Flux package and returns any side effects that occured.

type Package added in v0.10.0

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

func NewPackage added in v0.14.0

func NewPackage(name string) *Package

func NewPackageWithValues added in v0.14.0

func NewPackageWithValues(name string, obj values.Object) *Package

func (*Package) Array added in v0.14.0

func (p *Package) Array() values.Array

func (*Package) Bool added in v0.14.0

func (p *Package) Bool() bool

func (*Package) Copy added in v0.14.0

func (p *Package) Copy() *Package

func (*Package) Duration added in v0.14.0

func (p *Package) Duration() values.Duration

func (*Package) Equal added in v0.14.0

func (p *Package) Equal(rhs values.Value) bool

func (*Package) Float added in v0.14.0

func (p *Package) Float() float64

func (*Package) Function added in v0.14.0

func (p *Package) Function() values.Function

func (*Package) Get added in v0.14.0

func (p *Package) Get(name string) (values.Value, bool)

func (*Package) Int added in v0.14.0

func (p *Package) Int() int64

func (*Package) IsNull added in v0.14.0

func (p *Package) IsNull() bool

func (*Package) Len added in v0.14.0

func (p *Package) Len() int

func (*Package) Name added in v0.10.0

func (p *Package) Name() string

func (*Package) Object added in v0.14.0

func (p *Package) Object() values.Object

func (*Package) PolyType added in v0.14.0

func (p *Package) PolyType() semantic.PolyType

func (*Package) Range added in v0.14.0

func (p *Package) Range(f func(name string, v values.Value))

func (*Package) Regexp added in v0.14.0

func (p *Package) Regexp() *regexp.Regexp

func (*Package) Set added in v0.14.0

func (p *Package) Set(name string, v values.Value)

func (*Package) SideEffects added in v0.10.0

func (p *Package) SideEffects() []values.Value

func (*Package) Str added in v0.14.0

func (p *Package) Str() string

func (*Package) String added in v0.14.0

func (p *Package) String() string

func (*Package) Time added in v0.14.0

func (p *Package) Time() values.Time

func (*Package) Type added in v0.14.0

func (p *Package) Type() semantic.Type

func (*Package) UInt added in v0.14.0

func (p *Package) UInt() uint64

type Resolver

type Resolver interface {
	Resolve() (semantic.Node, error)
}

Resolver represents a value that can resolve itself

type Scope

type Scope interface {
	// Lookup a name in the current scope
	Lookup(name string) (values.Value, bool)

	// Bind a variable in the current scope
	Set(name string, v values.Value)

	// Create a new scope by nesting the current scope
	// If the passed in object is not nil, its values will be added to the new nested scope.
	Nest(values.Object) Scope

	// Return the parent of the current scope
	Pop() Scope

	// Number of visible names in scope
	Size() int

	// Range over all variable bindings in scope applying f
	Range(f func(k string, v values.Value))

	// Range over all variable bindings only in the current scope
	LocalRange(f func(k string, v values.Value))

	// Set the return value of the scope
	SetReturn(values.Value)

	// Retrieve the return values of the scope
	Return() values.Value

	// Create a copy of the scope
	Copy() Scope
}

func NewNestedScope added in v0.14.0

func NewNestedScope(s Scope, obj values.Object) Scope

func NewScope

func NewScope() Scope

type Value

type Value interface {
	// Type reports the type of value
	Type() semantic.Type
	// Value returns the actual value represented.
	Value() interface{}
	// Property returns a new value which is a property of this value.
	Property(name string) (values.Value, error)
}

Value represents any value that can be the result of evaluating any expression.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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