interpreter

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: AGPL-3.0, AGPL-3.0-or-later Imports: 7 Imported by: 0

Documentation

Overview

Package interpreter provides an implementation of an IFQL interpreter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eval

func Eval(program *semantic.Program, scope *Scope, d Domain) error

Types

type Arguments

type Arguments interface {
	Get(name string) (Value, bool)
	GetRequired(name string) (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) (Function, bool, error)
	GetArray(name string, t semantic.Kind) (Array, bool, error)
	GetObject(name string) (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) (Function, error)
	GetRequiredArray(name string, t semantic.Kind) (Array, error)
	GetRequiredObject(name string) (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.

type Array

type Array struct {
	Elements []Value
	// contains filtered or unexported fields
}

Array represents an sequence of elements All elements must be the same type

func NewArray added in v0.0.6

func NewArray(elementType semantic.Type) Array

func (Array) AsStrings

func (a Array) AsStrings() []string

func (Array) Property added in v0.0.5

func (a Array) Property(name string) (Value, error)

func (Array) Type

func (a Array) Type() semantic.Type

func (Array) Value added in v0.0.5

func (a Array) Value() interface{}

type Domain

type Domain interface{}

Domain represents any specific domain being used during evaluation.

type Function

type Function interface {
	Call(args Arguments, d Domain) (Value, error)
	// Resolve rewrites the function resolving any identifiers not listed in the function params.
	Resolve() (*semantic.FunctionExpression, error)
}

Function represents a callable type

type Object added in v0.0.5

type Object struct {
	Properties map[string]Value
}

Object represents an association of keys to values. Object values may be of any type.

func (Object) Property added in v0.0.5

func (m Object) Property(name string) (Value, error)

func (Object) Type added in v0.0.5

func (m Object) Type() semantic.Type

func (Object) Value added in v0.0.5

func (m Object) Value() interface{}

type Scope

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

func NewScope

func NewScope() *Scope

func (*Scope) Copy added in v0.0.6

func (s *Scope) Copy() *Scope

Copy returns a copy of the scope and its parents.

func (*Scope) Lookup

func (s *Scope) Lookup(name string) (Value, bool)

func (*Scope) Names added in v0.0.6

func (s *Scope) Names() []string

func (*Scope) Nest

func (s *Scope) Nest() *Scope

Nest returns a new nested scope.

func (*Scope) Return

func (s *Scope) Return() Value

Return reports the return value for this scope. If no return value has been set a value with type semantic.TInvalid is returned.

func (*Scope) Set

func (s *Scope) Set(name string, value Value)

func (*Scope) SetReturn

func (s *Scope) SetReturn(value Value)

SetReturn sets the return value of this 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) (Value, error)
}

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

func NewBoolValue

func NewBoolValue(v bool) Value

func NewDurationValue

func NewDurationValue(v time.Duration) Value

func NewFloatValue

func NewFloatValue(v float64) Value

func NewIntValue

func NewIntValue(v int64) Value

func NewStringValue

func NewStringValue(v string) Value

func NewTimeValue

func NewTimeValue(v time.Time) Value

func NewUIntValue

func NewUIntValue(v uint64) Value

Jump to

Keyboard shortcuts

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