eval

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValueNoArg valueType = -1
	ValueBool  valueType = iota
	ValueInt
	ValueFloat
	ValueString
	ValueStringDecimal
	ValueList
	ValueMap
	ValueSet
	ValueNull
)

const definitions for various sysl.Value types

Variables

View Source
var (

	// GoFuncMap is Map of Function Names to goFunc{}
	GoFuncMap = map[string]goFunc{
		"Contains":      {reflect.ValueOf(strings.Contains), []*sysl.Type{stringType, stringType}, boolType},
		"Count":         {reflect.ValueOf(strings.Count), []*sysl.Type{stringType, stringType}, intType},
		"Fields":        {reflect.ValueOf(strings.Fields), []*sysl.Type{stringType}, listStringType},
		"FindAllString": {reflect.ValueOf(FindAllString), []*sysl.Type{stringType, stringType, intType}, listStringType},
		"HasPrefix":     {reflect.ValueOf(strings.HasPrefix), []*sysl.Type{stringType, stringType}, boolType},
		"HasSuffix":     {reflect.ValueOf(strings.HasSuffix), []*sysl.Type{stringType, stringType}, boolType},
		"Join":          {reflect.ValueOf(strings.Join), []*sysl.Type{listStringType, stringType}, stringType},
		"LastIndex":     {reflect.ValueOf(strings.LastIndex), []*sysl.Type{stringType, stringType}, intType},
		"MatchString":   {reflect.ValueOf(MatchString), []*sysl.Type{stringType, stringType}, boolType},
		"Replace":       {reflect.ValueOf(strings.Replace), []*sysl.Type{stringType, stringType, stringType, intType}, stringType},
		"Split":         {reflect.ValueOf(strings.Split), []*sysl.Type{stringType, stringType}, listStringType},
		"Title":         {reflect.ValueOf(strings.Title), []*sysl.Type{stringType}, stringType},
		"ToLower":       {reflect.ValueOf(strings.ToLower), []*sysl.Type{stringType}, stringType},
		"ToTitle":       {reflect.ValueOf(strings.ToTitle), []*sysl.Type{stringType}, stringType},
		"ToUpper":       {reflect.ValueOf(strings.ToUpper), []*sysl.Type{stringType}, stringType},
		"Trim":          {reflect.ValueOf(strings.Trim), []*sysl.Type{stringType, stringType}, stringType},
		"TrimLeft":      {reflect.ValueOf(strings.TrimLeft), []*sysl.Type{stringType, stringType}, stringType},
		"TrimPrefix":    {reflect.ValueOf(strings.TrimPrefix), []*sysl.Type{stringType, stringType}, stringType},
		"TrimRight":     {reflect.ValueOf(strings.TrimRight), []*sysl.Type{stringType, stringType}, stringType},
		"TrimSpace":     {reflect.ValueOf(strings.TrimSpace), []*sysl.Type{stringType}, stringType},
		"TrimSuffix":    {reflect.ValueOf(strings.TrimSuffix), []*sysl.Type{stringType, stringType}, stringType},
	}
)

Functions

func AddItemToValueMap

func AddItemToValueMap(m *sysl.Value, name string, val *sysl.Value)

expects m.Value to be of type Value_Map

func AppendItemToValueList

func AppendItemToValueList(m *sysl.Value_List, val *sysl.Value)

func Eval

func Eval(txApp *sysl.Application, assign Scope, e *sysl.Expr) *sysl.Value

Eval expr TODO: Add type checks

func EvaluateView

func EvaluateView(mod *sysl.Module, appName, viewName string, s Scope) *sysl.Value

EvaluateView evaluate the view using the Scope

func FindAllString

func FindAllString(pattern, word string, n int) []string

FindAllString exposes regexp.FindAllString to sysl transforms

func IsCollectionType

func IsCollectionType(obj *sysl.Value) bool

IsCollectionType does obj holds multiple instances of the same thing?

func MakeValueBool

func MakeValueBool(val bool) *sysl.Value

MakeValueBool returns sysl.Value of type Value_B (bool)

func MakeValueI64

func MakeValueI64(val int64) *sysl.Value

MakeValueI64 returns sysl.Value of type Value_I (int64)

func MakeValueList

func MakeValueList(values ...*sysl.Value) *sysl.Value

MakeValueList returns sysl.Value of type Value_List_ ([]*sysl.Value)

func MakeValueMap

func MakeValueMap() *sysl.Value

MakeValueMap returns sysl.Value of type Value_Map_ (map[string]*sysl.Value)

func MakeValueSet

func MakeValueSet() *sysl.Value

MakeValueSet returns sysl.Value of type Value_Set ([]*sysl.Value)

func MakeValueString

func MakeValueString(val string) *sysl.Value

MakeValueString returns sysl.Value of type Value_S (string)

func MatchString

func MatchString(pattern, word string) bool

MatchString exposes regexp.MatchString to sysl transforms

func TypeToValue

func TypeToValue(t *sysl.Type) *sysl.Value

Types

type DefaultBinExprStrategy

type DefaultBinExprStrategy struct{}

DefaultBinExprStrategy is to evaluate lhs and rhs expr's first and then pass it to fn

type LHSOverRHSStrategy

type LHSOverRHSStrategy struct{}

LHSOverRHSStrategy binds rhs expression over each element of the LHS. Assumes lhs is a collection

type Scope

type Scope map[string]*sysl.Value

Scope holds the value of the variables during the execution of a transform

func (Scope) AddApp

func (s Scope) AddApp(name string, app *sysl.Application)

AddApp add sysl.App to scope

func (Scope) AddInt

func (s Scope) AddInt(name string, val int64)

AddInt add int to scope

func (Scope) AddString

func (s Scope) AddString(name string, val string)

AddString add string to scope

type Strategy

type Strategy interface {
	// contains filtered or unexported methods
}

Strategy interface to evaluate binary expr

Jump to

Keyboard shortcuts

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