golsp

package
v0.0.0-...-490387d Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const ARGS = "__args__"
View Source
const DIRNAME = "__dirname__"
View Source
const FILENAME = "__filename__"
View Source
const UNDEFINED = "undefined"

names of special builtin identifiers

Variables

View Source
var Builtins = Scope{}
View Source
var LiteralDelimiterTypes = map[string]STNodeType{
	"\"": STNodeTypeStringLiteral,
	"#":  STNodeTypeComment,
}
View Source
var LiteralDelimiters = map[string]string{"\"": "\"", "#": "\n"}
View Source
var OperatorTypes = map[string]OperatorType{
	"...": OperatorTypeSpread,
	":":   OperatorTypeZip,
	".":   OperatorTypeDot,
}
View Source
var Operators = []string{"...", ":", "."}
View Source
var TokenDelimiterTypes = map[string]STNodeType{
	"":  STNodeTypeScope,
	"[": STNodeTypeExpression,
	"{": STNodeTypeList,
	"(": STNodeTypeMap,
}
View Source
var TokenDelimiters = map[string]string{
	"":  "",
	"[": "]",
	"]": "",
	"{": "}",
	"}": "",
	"(": ")",
	")": "",
}

Functions

func InitializeBuiltins

func InitializeBuiltins(dirname string, filename string, args []string)

InitializeBuiltins: Initialize the default builtin scope ('Builtins') with builtin identifiers

func RuntimeWaitGroup

func RuntimeWaitGroup() *sync.WaitGroup

func ToNumber

func ToNumber(obj Object) (float64, error)

ToNumber: Extract a number from a number object. This function cannot convert non-number objects to numbers `obj`: the number object this function returns a number (as a float64) and an optional error

func ToString

func ToString(obj Object) (string, error)

ToString: Extract a string from a string object. This function cannot convert non-string objects to strings `obj`: the string object this function returns a string and an optional error

func Tokenize

func Tokenize(input string) []string

Tokenize: tokenize a string `input`: the string to tokenize this function returns a list of tokens

Types

type BuiltinFunction

type BuiltinFunction func(Scope, []Object) Object

type Function

type Function struct {
	Name             string
	FunctionPatterns [][]STNode
	FunctionBodies   []STNode
	BuiltinFunc      BuiltinFunction
}

func CopyFunction

func CopyFunction(fn Function) Function

CopyFunction: Copy a Function struct `fn`: the function to copy this function returns a copy of fn

type Item

type Item struct {
	Object Object
	// contains filtered or unexported fields
}

type List

type List struct {
	First  *Item
	Last   *Item
	Length int
	// contains filtered or unexported fields
}

func ListFromSlice

func ListFromSlice(slice []Object) List

func SpreadNode

func SpreadNode(scope Scope, node STNode) List

SpreadNode: Apply the spread operator to a syntax tree node `scope`: the scope within which the node is being spread `node`: the node to spread this function returns the List of Objects that the node spreads to

func (*List) Append

func (l *List) Append(obj Object)

func (*List) Copy

func (l *List) Copy() List

func (*List) Index

func (l *List) Index(index int) Object

func (*List) Join

func (self *List) Join(other List)

func (*List) Next

func (l *List) Next(item *Item, index int) *Item

func (*List) Slice

func (l *List) Slice(begin int, end int) Object

func (*List) SliceStep

func (l *List) SliceStep(begin int, end int, step int, sliceAll bool) Object

func (*List) ToSlice

func (l *List) ToSlice() []Object

type Object

type Object struct {
	Scope    Scope
	Type     ObjectType
	Function Function
	Value    STNode
	Elements List
	Map      map[string]Object
	MapKeys  []Object
}

func BuiltinComparisonFunction

func BuiltinComparisonFunction(op string) Object

BuiltinComparisonFunction: This function produces a builtin comparison function for the specified operator `op`: the comparison operator, one of == != > < >= <= this function retuns the produced builtin function

func BuiltinConst

func BuiltinConst(scope Scope, arguments []Object) Object

func BuiltinDef

func BuiltinDef(scope Scope, arguments []Object) Object

see 'assign'

func BuiltinDo

func BuiltinDo(scope Scope, arguments []Object) Object

BuiltinDo: The builtin 'do' function. This function evaluates a series of statements within an enclosed, isolated scope this function returns the result of evaluating the final statement in the scope

func BuiltinFunctionObject

func BuiltinFunctionObject(name string, fn BuiltinFunction) Object

BuiltinFunctionObject: Produce a function object from a BuiltinFunction-type function `name`: the name of the function `fn`: the builtin function this function returns the Object containing the builtin function

func BuiltinGo

func BuiltinGo(scope Scope, arguments []Object) Object

BuiltinGo: The builtin 'go' function. This function concurrently evaluates a series of statements within an enclosed, isolated scope this function returns UNDEFINED

func BuiltinIf

func BuiltinIf(scope Scope, args []Object) Object

BuiltinIf: the builtin 'if' function. This function evaluates a predicate and evaluates one of two expressions depending on the result of the predicate the function returns the result of the expression that is evaluated, or UNDEFINED

func BuiltinLambda

func BuiltinLambda(scope Scope, arguments []Object) Object

BuiltinLambda: The builtin 'lambda' function. This produces a function-type object with one pattern and one expression this function returns the function object that is produced

func BuiltinMathFunction

func BuiltinMathFunction(op string) Object

BuiltinMathFunction: Produce a builtin function for a given math operator `op`: the math operator, one of + - * / % this function returns a Object containing the builtin function for the math operator

func BuiltinPrintf

func BuiltinPrintf(scope Scope, arguments []Object) Object

BuiltinPrintf: The builtin 'printf' function. This function formats a Go-style format string with a set of arguments and writes the result to stdout this function returns the formatted string

func BuiltinRequire

func BuiltinRequire(scope Scope, args []Object) Object

BuiltinRequire: The builtin 'require' function. This function evaluates a file and returns the Object that the file exports.

func BuiltinSleep

func BuiltinSleep(scope Scope, arguments []Object) Object

BuiltinSleep: the builtin 'sleep' function. This function waits for a specified number of milliseconds this function returns UNDEFINED

func BuiltinSprintf

func BuiltinSprintf(scope Scope, args []Object) Object

BuiltinSprintf: The builtin 'sprintf' function. This function formats a Go-style format string with a set of arguments this function returns the formatted string

func BuiltinWhen

func BuiltinWhen(scope Scope, args []Object) Object

BuiltinWhen: the builtin 'when' function. This function takes a set of predicate-body pairs (expressed as zipped expressions), evaluates the predicates one by one and evaluates a 'body' when it reaches a predicate that is true. this function returns the result of the body expression that is evaluated, or UNDEFINED

func CallFunction

func CallFunction(fnobj Object, args List) Object

CallFunction: call a function object with a list of arguments `fnobj`: the function object `args`: the list of arguments this function returns the result of the function call

func CopyObject

func CopyObject(object Object) Object

CopyObject: Copy an Object `object`: the object to copy this function returns a copy of object. Note that it does not copy object.Value since that property is never modified

func Eval

func Eval(scope Scope, root STNode) Object

Eval: Evaluate a syntax tree node within a scope `scope`: the scope within which to evaluate the node `root`: the root node to evaluate this function returns the result of evaluating the node as an Object

func EvalArgs

func EvalArgs(scp Scope, args []Object) []Object

EvalArgs: evaluate a list of arguments passed to builtin functions, primarily used to handle spreading `scp`: the scope within which to evaluate the arguments `args`: the arguments to evaluate this function returns the evaluated arguments as a list of Objects

func EvalMap

func EvalMap(glmap Object, arguments List) Object

EvalMap: Lookup key(s) in a map `glmap`: the map object `arguments`: the key or keys to look up this function returns the object or list of objects that the key(s) map to

func EvalSlice

func EvalSlice(list Object, arguments List) Object

EvalSlice: Evaluate a slice expression, i.e `[list begin end step]` `list`: the list or string that is sliced `arguments`: the arguments passed in the expression this function returns a slice of the list/string or UNDEFINED

func ListObject

func ListObject(slice []string) Object

ListObject: Produce a list object from a slice of strings. This function cannot produce lists that contain non-string objects `slice`: the slice this function returns the produced Object

func LookupIdentifier

func LookupIdentifier(scope Scope, identifier string) Object

LookupIdentifier: lookup an identifier within a particular scope `scope`: the scope in which to search for the identifier `identifier`: the name of the identifier this function returns the object corresponding to the identifier or UNDEFINED

func MapObject

func MapObject(gomap map[string]Object) Object

MapObject: Produce a map object from a map of strings to Objects. This function cannot produce maps that bind numbers to objects `gomap`: the map this function returns the produced Object

func NumberObject

func NumberObject(num float64) Object

NumberObject: Produce a number object from a number `num`: the number this function returns the produced Object

func Run

func Run(dirname string, filename string, args []string, program string) Object

Run: Run a Golsp program `program`: the program to run `dirname`: the directory of the program file `filename`: the name of the program file `args`: command line arguments passed to the program this function returns the result of running the program

func StringObject

func StringObject(str string) Object

StringObject: Produce a string object from a string `str`: the string this function returns the produced Object

func UndefinedObject

func UndefinedObject() Object

UndefinedObject: Produce the UNDEFINED identifier object. Used because structs and other data structures are mutable by default and cannot be stored in consts this function returns the UNDEFINED Object

type ObjectType

type ObjectType int
const (
	ObjectTypeBuiltinArgument ObjectType = -1
	ObjectTypeLiteral         ObjectType = 0
	ObjectTypeFunction        ObjectType = 1
	ObjectTypeList            ObjectType = 2
	ObjectTypeMap             ObjectType = 3
)

type OperatorType

type OperatorType int
const (
	OperatorTypeSpread OperatorType = 0
	OperatorTypeZip    OperatorType = 1
	OperatorTypeDot    OperatorType = 2
)

type STNode

type STNode struct {
	Head     string
	Type     STNodeType
	Children []STNode
	Spread   bool
	Zip      *STNode
	Dot      *STNode
}

func MakeST

func MakeST(tokens []string) STNode

MakeST: construct a syntax tree from a list of tokens `tokens`: list of tokens to parse

type STNodeType

type STNodeType int
const (
	STNodeTypeScope         STNodeType = 0
	STNodeTypeExpression    STNodeType = 1
	STNodeTypeStringLiteral STNodeType = 2
	STNodeTypeNumberLiteral STNodeType = 3
	STNodeTypeList          STNodeType = 4
	STNodeTypeMap           STNodeType = 5
	STNodeTypeIdentifier    STNodeType = 6
	STNodeTypeComment       STNodeType = 7
)

type Scope

type Scope struct {
	Parent      *Scope
	Identifiers map[string]Object
	Constants   map[string]bool
}

func IsolateScope

func IsolateScope(scope Scope) Scope

IsolateScope: 'Isolate' a scope object by copying all values from its parent scopes into the scope struct, effectively orphaning it and flattening its inheritance tree `scope`: the scope to isolate this function returns the isolated scope

func MakeScope

func MakeScope(parent *Scope) Scope

MakeScope: construct a new child scope that descends from a parent scope `parent`: the parent scope this function returns a new Scope struct whose Parent points to parent

Jump to

Keyboard shortcuts

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