Documentation ¶
Overview ¶
Package scpt provides an interpreter for my simple applescript-like scripting language
Index ¶
- Variables
- func AddFuncs(fnMap FuncMap)
- func AddVars(varMap map[string]interface{})
- func CallFunction(call *FuncCall) (interface{}, error)
- func IsFuncCall(val interface{}) bool
- func ParseValue(val *Value) (interface{}, error)
- func UnwrapArgs(args []*Arg) (map[string]interface{}, error)
- type AST
- type Arg
- type Bool
- type Command
- type ExprRightSeg
- type Expression
- type FuncCall
- type FuncDef
- type FuncMap
- type Goroutine
- type If
- type MapKVPair
- type RptLoop
- type Value
- type Var
- type VarVal
- type WhlLoop
Constants ¶
This section is empty.
Variables ¶
var Funcs = FuncMap{
"str": toString,
"num": parseNumber,
"bool": parseBool,
"break": setBreakLoop,
"append": appendArray,
"exit": scptExit,
"return": setReturn,
"print": scptPrint,
}
Funcs stores the functions allowed for use in a script
var Vars = map[string]interface{}{}
Vars stores any variables set during script runtime
Functions ¶
func AddFuncs ¶
func AddFuncs(fnMap FuncMap)
AddFuncs adds all functions from the provided FuncMap into the Funcs variable
func AddVars ¶
func AddVars(varMap map[string]interface{})
AddVars adds all functions from the provided map into the Vars variable
func CallFunction ¶
CallFunction executes a given function call in the form of a FuncCall struct
func IsFuncCall ¶
func IsFuncCall(val interface{}) bool
IsFuncCall checks if val is a FuncCall struct
func ParseValue ¶
ParseValue parses a Value struct into a go value
func UnwrapArgs ¶
UnwrapArgs takes a slice of Arg structs and returns a map storing the argument name and its value. If the argument has no name, its key will be an empty string
Types ¶
type AST ¶
AST stores the root of the Abstract Syntax Tree for scpt
func (*AST) DumpPretty ¶
type Bool ¶
type Bool bool
Bool stores boolean values encountered while parsing a script. It is required for the Capture method
type Command ¶
type Command struct { Pos lexer.Position Vars []*Var `( @@` Ifs []*If `| @@` RptLoops []*RptLoop `| @@` WhlLoops []*WhlLoop `| @@` Defs []*FuncDef `| @@` Goroutines []*Goroutine `| @@` Calls []*FuncCall `| @@ )` }
Command stores any commands encountered while parsing a script
type ExprRightSeg ¶
ExprRightSeg stores segments of the right side of an expression
type Expression ¶
type Expression struct { Pos lexer.Position Left *Value `@@` RightSegs []*ExprRightSeg `@@*` }
Expression stores any expressions encountered while parsing a script for later evaluation
type FuncDef ¶
type FuncDef struct { Pos lexer.Position Name *string `"define" @Ident @("-" Ident)* "{"` InnerCmds []*Command `@@* "}"` }
FuncDef stores any function definitions encountered while parsing a script
type RptLoop ¶
type RptLoop struct { Pos lexer.Position Times *int `"repeat" @Number "times" "{"` IndexVar *string `(@Ident "in")?` InnerCmds []*Command `@@* "}"` }
RptLoop stores any repeat loops encountered while parsing a script
type Value ¶
type Value struct { Pos lexer.Position String *string ` @String` Number *float64 `| @Number` Bool *Bool `| @("true" | "false")` SubCmd *FuncCall `| "(" @@ ")"` VarVal *VarVal `| @@` Expr *Expression `| "{" @@ "}"` Map []*MapKVPair `| "[" (@@ ("," @@)* )? "]"` Array []*Value `| "[" (@@ ("," @@)* )? "]"` Opposite *Value `| "!" @@` }
Value stores any literal values encountered while parsing a script
type Var ¶
type Var struct { Pos lexer.Position Key string `"set" @Ident` Index *Value `("[" @@ "]")?` Value *Value `"to" @@` }
Var stores any variables encountered while parsing a script