script

package
v0.0.0-...-3978320 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Stdlib = []StdlibFunc{
	StdlibFunc{"id", LiftFunction(builtinId), "Returns its argument", "everything", "parameter :: *"},
	StdlibFunc{"equals", LiftFunction(builtinEquals), "Returns true if the arguments are of the same type and have the same value", "everything", "parameter :: *"},
	StdlibFunc{"env_lookup", LiftFunction(builtinEnvLookup), "Lookup key in environment. Usually called implicitly when using '$'", "lists", "key :: string"},
	StdlibFunc{"concat", LiftFunction(builtinConcat), "Concatate stringable arguments", "strings", "v1 :: string, v2 :: string, ..."},
	StdlibFunc{"lower", ShouldLift(strings.ToLower), "Returns a copy of the string v with all Unicode characters mapped to their lower case", "strings", "v :: string"},
	StdlibFunc{"upper", ShouldLift(strings.ToUpper), "Returns a copy of the string v with all Unicode characters mapped to their upper case", "strings", "v :: string"},
	StdlibFunc{"title", ShouldLift(strings.ToTitle), "Returns a copy of the string v with all Unicode characters mapped to their title case", "strings", "v :: string"},
	StdlibFunc{"split", ShouldLift(strings.Split), "Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators. If sep is empty, Split splits after each UTF-8 sequence.", "strings", "sep :: string"},
	StdlibFunc{"path_exists", ShouldLift(util.PathExists), "Returns true if the path exists, false if not", "strings", ""},
	StdlibFunc{"file_exists", ShouldLift(util.FileExists), "Returns true if the path exists and if it's not a directory, false otherwise", "strings", ""},
	StdlibFunc{"dir_exists", ShouldLift(util.IsDir), "Returns true if the path exists and if it is a directory, false otherwise", "strings", ""},
	StdlibFunc{"join", ShouldLift(strings.Join), "Join concatenates the elements of a to create a single string. The separator string sep is placed between elements in the resulting string. ", "lists", "sep :: string"},
	StdlibFunc{"replace", ShouldLift(strings.Replace), "Replace returns a copy of the string s with the first n non-overlapping instances of old replaced by new. If old is empty, it matches at the beginning of the string and after each UTF-8 sequence, yielding up to k+1 replacements for a k-rune string. If n < 0, there is no limit on the number of replacements.", "strings", "old :: string, new :: string, n :: integer"},
	StdlibFunc{"base64_encode", ShouldLift(base64.StdEncoding.EncodeToString), "Encode string to base64", "strings", ""},
	StdlibFunc{"base64_decode", ShouldLift(base64.StdEncoding.DecodeString), "Decode string from base64", "strings", ""},
	StdlibFunc{"trim", ShouldLift(strings.TrimSpace), "Returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode. ", "strings", ""},
	StdlibFunc{"list_index", LiftFunction(builtinListIndex), "Index a list at position `n`. Usually accessed implicitly using indexing syntax (eg. `list[0]`)", "lists", "n :: integer"},
	StdlibFunc{"length", LiftFunction(builtinListLength), "Returns the length of the list", "lists", "n :: integer"},
	StdlibFunc{"list_slice", LiftFunction(builtinListSlice), "Slice a list. Usually accessed implicitly using slice syntax (eg. `list[0:5]`)", "lists", "i :: integer, j :: integer"},
	StdlibFunc{"add", ShouldLift(builtinAdd), "Add two integers", "integers", "y :: integer"},
	StdlibFunc{"timestamp", ShouldLift(builtinTimestamp), "Returns a UNIX timestamp", "", ""},
	StdlibFunc{"read_file", ShouldLift(builtinReadfile), "Read the contents of a file", "strings", ""},
	StdlibFunc{"track_major_version", trackMajorVersion, "Track major version", "strings", ""},
	StdlibFunc{"track_minor_version", trackMinorVersion, "Track minor version", "strings", ""},
	StdlibFunc{"track_patch_version", trackPatchVersion, "Track patch version", "strings", ""},
	StdlibFunc{"track_version", trackVersion, "Track version", "strings", ""},
	StdlibFunc{"not", LiftFunction(builtinNOT), "Logical NOT operation", "bool", ""},
	StdlibFunc{"and", LiftFunction(builtinAND), "Logical AND operation", "bool", "b2 :: bool"},
	StdlibFunc{"or", LiftFunction(builtinOR), "Logical OR operation", "bool", "b2 :: bool"},
	StdlibFunc{"lt", LiftFunction(builtinLT), "Returns true if first argument is less than the second argument", "integer", "i2 :: integer"},
	StdlibFunc{"lte", LiftFunction(builtinLTE), "Returns true if first argument is less than or equal to the second argument", "integer", "i2 :: integer"},
	StdlibFunc{"gt", LiftFunction(builtinGT), "Returns true if first argument is greater than second argument", "integer", "i2 :: integer"},
	StdlibFunc{"gte", LiftFunction(builtinGTE), "Returns true if first argument is greater than or equal to second argument", "integer", "i2 :: integer"},
}

Functions

func EvalToGoValue

func EvalToGoValue(script Script, env *ScriptEnvironment) (interface{}, error)

func ExpectApplyAtom

func ExpectApplyAtom(s Script) *apply

func ExpectBoolAtom

func ExpectBoolAtom(s Script) bool

func ExpectDict

func ExpectDict(s Script) map[string]interface{}

func ExpectDictAtom

func ExpectDictAtom(s Script) map[string]Script

func ExpectFunctionAtom

func ExpectFunctionAtom(s Script) scriptFuncType

func ExpectIntegerAtom

func ExpectIntegerAtom(s Script) int

func ExpectLambdaAtom

func ExpectLambdaAtom(v Script) *lambda

func ExpectStringAtom

func ExpectStringAtom(s Script) string

func IsApplyAtom

func IsApplyAtom(s Script) bool

func IsBoolAtom

func IsBoolAtom(s Script) (ok bool)

func IsDictAtom

func IsDictAtom(s Script) bool

func IsFunctionAtom

func IsFunctionAtom(s Script) bool

func IsIntegerAtom

func IsIntegerAtom(s Script) (ok bool)

func IsLambdaAtom

func IsLambdaAtom(v Script) bool

func IsListAtom

func IsListAtom(s Script) (ok bool)

func IsStringAtom

func IsStringAtom(s Script) (ok bool)

func ParseAndEvalToGoValue

func ParseAndEvalToGoValue(scriptStr string, env *ScriptEnvironment) (interface{}, error)

func ParseAndEvalToString

func ParseAndEvalToString(scriptStr string, env *ScriptEnvironment) (string, error)

Types

type Function

type Function struct {
	Func scriptFuncType
	Doc  string
}

Functions

func ExpectFunction

func ExpectFunction(s Script) *Function

func (*Function) Equals

func (s *Function) Equals(s2 Script) bool

func (*Function) Eval

func (f *Function) Eval(env *ScriptEnvironment) (Script, error)

func (*Function) Type

func (f *Function) Type() ValueType

func (*Function) Value

func (f *Function) Value() (interface{}, error)

type Script

type Script interface {
	Eval(*ScriptEnvironment) (Script, error)
	Value() (interface{}, error)
	Type() ValueType
	Equals(Script) bool
}

func ExpectListAtom

func ExpectListAtom(s Script) []Script

func Lift

func Lift(val interface{}) (Script, error)

func LiftBool

func LiftBool(b bool) Script

func LiftDict

func LiftDict(d map[string]Script) Script

func LiftFunction

func LiftFunction(f scriptFuncType) Script

func LiftGoFunc

func LiftGoFunc(f interface{}) Script

func LiftInteger

func LiftInteger(i int) Script

func LiftList

func LiftList(l []Script) Script

func LiftString

func LiftString(s string) Script

func NewApply

func NewApply(to Script, args []Script) Script

func NewLambda

func NewLambda(args []string, body Script) Script

func ParseScript

func ParseScript(str string) (Script, error)

func ShouldLift

func ShouldLift(v interface{}) Script

func ShouldParse

func ShouldParse(str string) Script

type ScriptEnvironment

type ScriptEnvironment map[string]Script

func NewScriptEnvironment

func NewScriptEnvironment() *ScriptEnvironment

func NewScriptEnvironmentFromMap

func NewScriptEnvironmentFromMap(m map[string]Script) *ScriptEnvironment

func NewScriptEnvironmentWithGlobals

func NewScriptEnvironmentWithGlobals(globals map[string]Script) *ScriptEnvironment

type StdlibFunc

type StdlibFunc struct {
	Id     string
	Func   Script
	Doc    string
	ActsOn string
	Args   string
}

type ValueType

type ValueType interface {
	Name() string
	IsFunc() bool
	IsInteger() bool
	IsList() bool
	IsBool() bool
	IsMap() bool
	IsString() bool
	IsLambda() bool
}

func NewType

func NewType(typ string) ValueType

Jump to

Keyboard shortcuts

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