Documentation
¶
Index ¶
- Variables
- func AsBool(v Value, err error) (bool, error)
- type BoolValue
- func (v BoolValue) AsBool() (bool, error)
- func (v BoolValue) AsInt() (int, error)
- func (v BoolValue) AsString() (string, error)
- func (BoolValue) Call(*Scope, []Value) (Value, error)
- func (b BoolValue) Eq(v Value) (bool, error)
- func (BoolValue) Index(Value) (Value, error)
- func (BoolValue) Selector(sel string) (Value, error)
- type Closure
- func (Closure) AsBool() (bool, error)
- func (Closure) AsInt() (int, error)
- func (Closure) AsString() (string, error)
- func (Closure) Call(*Scope, []Value) (Value, error)
- func (Closure) Eq(Value) (bool, error)
- func (c Closure) Evaluate(arg Value, scope *Scope) (Value, error)
- func (Closure) Index(i Value) (Value, error)
- func (Closure) Selector(sel string) (Value, error)
- type Compiler
- func (compiler *Compiler) EnterStatementBlock(c *parser.StatementBlockContext)
- func (compiler *Compiler) EnterStatementList(c *parser.StatementListContext)
- func (c *Compiler) Error() error
- func (compiler *Compiler) ExitArguments(c *parser.ArgumentsContext)
- func (compiler *Compiler) ExitAssignmentExpression(c *parser.AssignmentExpressionContext)
- func (compiler *Compiler) ExitBlockClosureExpression(c *parser.BlockClosureExpressionContext)
- func (compiler *Compiler) ExitClosureExpression(c *parser.ClosureExpressionContext)
- func (compiler *Compiler) ExitDefinitionExpression(c *parser.DefinitionExpressionContext)
- func (compiler *Compiler) ExitDotExpression(c *parser.DotExpressionContext)
- func (compiler *Compiler) ExitEqualityExpression(c *parser.EqualityExpressionContext)
- func (compiler *Compiler) ExitExpressionStatement(c *parser.ExpressionStatementContext)
- func (compiler *Compiler) ExitFunctionCallExpression(c *parser.FunctionCallExpressionContext)
- func (compiler *Compiler) ExitIdentifierExpression(c *parser.IdentifierExpressionContext)
- func (compiler *Compiler) ExitIndexExpression(c *parser.IndexExpressionContext)
- func (compiler *Compiler) ExitLiteralExpression(c *parser.LiteralExpressionContext)
- func (compiler *Compiler) ExitLogicalAndExpression(c *parser.LogicalAndExpressionContext)
- func (compiler *Compiler) ExitLogicalOrExpression(c *parser.LogicalOrExpressionContext)
- func (compiler *Compiler) ExitLvalue(c *parser.LvalueContext)
- func (compiler *Compiler) ExitNotExpression(c *parser.NotExpressionContext)
- func (compiler *Compiler) ExitStatementBlock(c *parser.StatementBlockContext)
- func (compiler *Compiler) ExitStatementList(c *parser.StatementListContext)
- type EdgeValue
- func (e EdgeValue) Add(v2 Value) (Value, error)
- func (e EdgeValue) AsBool() (bool, error)
- func (EdgeValue) AsInt() (int, error)
- func (e EdgeValue) AsString() (string, error)
- func (EdgeValue) Call(*Scope, []Value) (Value, error)
- func (e EdgeValue) Eq(val Value) (bool, error)
- func (EdgeValue) Index(i Value) (Value, error)
- func (e EdgeValue) Selector(sel string) (Value, error)
- type ErrInvalidArguments
- type ErrInvalidFunctionCall
- type ErrSyntax
- type ErrUnknownIdentifier
- type ErrUnknownSelector
- type Evaluatable
- type FunctionValue
- func (FunctionValue) AsBool() (bool, error)
- func (FunctionValue) AsInt() (int, error)
- func (FunctionValue) AsString() (string, error)
- func (f FunctionValue) Call(scope *Scope, args []Value) (Value, error)
- func (FunctionValue) Eq(Value) (bool, error)
- func (FunctionValue) Index(i Value) (Value, error)
- func (FunctionValue) Selector(sel string) (Value, error)
- type NodeValue
- func (v NodeValue) Add(v2 Value) (Value, error)
- func (v NodeValue) AsBool() (bool, error)
- func (NodeValue) AsInt() (int, error)
- func (v NodeValue) AsString() (string, error)
- func (NodeValue) Call(*Scope, []Value) (Value, error)
- func (v NodeValue) Eq(val Value) (bool, error)
- func (NodeValue) Index(i Value) (Value, error)
- func (v NodeValue) Selector(sel string) (Value, error)
- type NullValue
- func (NullValue) AsBool() (bool, error)
- func (NullValue) AsInt() (int, error)
- func (NullValue) AsString() (string, error)
- func (NullValue) Call(*Scope, []Value) (Value, error)
- func (NullValue) Eq(v Value) (bool, error)
- func (NullValue) Index(i Value) (Value, error)
- func (NullValue) Selector(sel string) (Value, error)
- type NumberValue
- func (v NumberValue) AsBool() (bool, error)
- func (v NumberValue) AsInt() (int, error)
- func (v NumberValue) AsString() (string, error)
- func (NumberValue) Call(*Scope, []Value) (Value, error)
- func (v NumberValue) Eq(value Value) (bool, error)
- func (NumberValue) Index(Value) (Value, error)
- func (NumberValue) Selector(sel string) (Value, error)
- type PropertiesValue
- func (value PropertiesValue) AsBool() (bool, error)
- func (PropertiesValue) AsInt() (int, error)
- func (PropertiesValue) AsString() (string, error)
- func (PropertiesValue) Call(*Scope, []Value) (Value, error)
- func (value PropertiesValue) Eq(v Value) (bool, error)
- func (value PropertiesValue) Index(index Value) (Value, error)
- func (value PropertiesValue) Selector(sel string) (Value, error)
- type Scope
- type StringSliceValue
- func (value StringSliceValue) Add(v2 Value) (Value, error)
- func (value StringSliceValue) AsBool() (bool, error)
- func (StringSliceValue) AsInt() (int, error)
- func (value StringSliceValue) AsString() (string, error)
- func (StringSliceValue) Call(*Scope, []Value) (Value, error)
- func (value StringSliceValue) Eq(v Value) (bool, error)
- func (value StringSliceValue) Index(index Value) (Value, error)
- func (value StringSliceValue) Selector(sel string) (Value, error)
- type StringValue
- func (value StringValue) AsBool() (bool, error)
- func (value StringValue) AsInt() (int, error)
- func (value StringValue) AsString() (string, error)
- func (StringValue) Call(*Scope, []Value) (Value, error)
- func (value StringValue) Eq(v Value) (bool, error)
- func (StringValue) Index(Value) (Value, error)
- func (value StringValue) Selector(sel string) (Value, error)
- type Value
- type ValueArrayValue
- func (value ValueArrayValue) Add(v2 Value) (Value, error)
- func (value ValueArrayValue) AsBool() (bool, error)
- func (ValueArrayValue) AsInt() (int, error)
- func (value ValueArrayValue) AsString() (string, error)
- func (ValueArrayValue) Call(*Scope, []Value) (Value, error)
- func (ValueArrayValue) Eq(Value) (bool, error)
- func (value ValueArrayValue) Index(index Value) (Value, error)
- func (value ValueArrayValue) Selector(sel string) (Value, error)
Constants ¶
This section is empty.
Variables ¶
var ( TrueValue = BoolValue(true) FalseValue = BoolValue(false) )
Boolean literals
var ( ErrEvaluation = errors.New("Evaluation error") ErrNotCallable = errors.New("Not callable") ErrNotIndexable = errors.New("Not indexable") ErrNoEdgesInResult = errors.New("No edges in result") ErrMultipleEdgesInResult = errors.New("Multiple edges in result") ErrNoNodesInResult = errors.New("No nodes in result") ErrMultipleNodesInResult = errors.New("Multiple nodes in result") ErrNotANumber = errors.New("Not a number") ErrNotAString = errors.New("Not a string") ErrIncomparable = errors.New("Incomparable values") ErrNotLValue = errors.New("Not LValue") ErrCannotIterate = errors.New("Cannot iterate") ErrCannotAccumulate = errors.New("Cannot accumulate collection of values") ErrIncompatibleValue = errors.New("Incompatible value") ErrNotAClosure = errors.New("Not a closure") ErrClosureOrBooleanExpected = errors.New("Closure or a boolean value expected") ErrInvalidArgumentType = errors.New("Invalid argument type") ErrInvalidStatementList = errors.New("Invalid statement list") ErrInvalidExpression = errors.New("Invalid expression") ErrNotExpression = errors.New("Not an expression") )
Script compilation/evaluation errors
Functions ¶
Types ¶
type BoolValue ¶
type BoolValue bool
BoolValue is a boolean value on the stack
type Closure ¶
type Closure struct {
Symbol string
F Evaluatable
// contains filtered or unexported fields
}
A Closure is a function that captures the current scope, with an argument
type Compiler ¶
type Compiler struct {
*parser.BaseglListener
// contains filtered or unexported fields
}
Compiler is the graph language script compiler
func (*Compiler) EnterStatementBlock ¶
func (compiler *Compiler) EnterStatementBlock(c *parser.StatementBlockContext)
func (*Compiler) EnterStatementList ¶
func (compiler *Compiler) EnterStatementList(c *parser.StatementListContext)
func (*Compiler) ExitArguments ¶
func (compiler *Compiler) ExitArguments(c *parser.ArgumentsContext)
func (*Compiler) ExitAssignmentExpression ¶
func (compiler *Compiler) ExitAssignmentExpression(c *parser.AssignmentExpressionContext)
func (*Compiler) ExitBlockClosureExpression ¶
func (compiler *Compiler) ExitBlockClosureExpression(c *parser.BlockClosureExpressionContext)
func (*Compiler) ExitClosureExpression ¶
func (compiler *Compiler) ExitClosureExpression(c *parser.ClosureExpressionContext)
func (*Compiler) ExitDefinitionExpression ¶
func (compiler *Compiler) ExitDefinitionExpression(c *parser.DefinitionExpressionContext)
func (*Compiler) ExitDotExpression ¶
func (compiler *Compiler) ExitDotExpression(c *parser.DotExpressionContext)
func (*Compiler) ExitEqualityExpression ¶
func (compiler *Compiler) ExitEqualityExpression(c *parser.EqualityExpressionContext)
func (*Compiler) ExitExpressionStatement ¶
func (compiler *Compiler) ExitExpressionStatement(c *parser.ExpressionStatementContext)
func (*Compiler) ExitFunctionCallExpression ¶
func (compiler *Compiler) ExitFunctionCallExpression(c *parser.FunctionCallExpressionContext)
func (*Compiler) ExitIdentifierExpression ¶
func (compiler *Compiler) ExitIdentifierExpression(c *parser.IdentifierExpressionContext)
func (*Compiler) ExitIndexExpression ¶
func (compiler *Compiler) ExitIndexExpression(c *parser.IndexExpressionContext)
func (*Compiler) ExitLiteralExpression ¶
func (compiler *Compiler) ExitLiteralExpression(c *parser.LiteralExpressionContext)
func (*Compiler) ExitLogicalAndExpression ¶
func (compiler *Compiler) ExitLogicalAndExpression(c *parser.LogicalAndExpressionContext)
func (*Compiler) ExitLogicalOrExpression ¶
func (compiler *Compiler) ExitLogicalOrExpression(c *parser.LogicalOrExpressionContext)
func (*Compiler) ExitLvalue ¶
func (compiler *Compiler) ExitLvalue(c *parser.LvalueContext)
func (*Compiler) ExitNotExpression ¶
func (compiler *Compiler) ExitNotExpression(c *parser.NotExpressionContext)
func (*Compiler) ExitStatementBlock ¶
func (compiler *Compiler) ExitStatementBlock(c *parser.StatementBlockContext)
func (*Compiler) ExitStatementList ¶
func (compiler *Compiler) ExitStatementList(c *parser.StatementListContext)
type EdgeValue ¶
EdgeValue is zero or more edges
type ErrInvalidArguments ¶
ErrInvalidArgument is returned when a method is called with an incompatible argument
func (ErrInvalidArguments) Error ¶
func (e ErrInvalidArguments) Error() string
type ErrInvalidFunctionCall ¶
type ErrInvalidFunctionCall string
ErrInvalidFunctionCall is returned if the function call cannot be completed
func (ErrInvalidFunctionCall) Error ¶
func (e ErrInvalidFunctionCall) Error() string
type ErrUnknownIdentifier ¶
type ErrUnknownIdentifier string
ErrUnknownIdentifier is returned if an identifier is not in scope
func (ErrUnknownIdentifier) Error ¶
func (e ErrUnknownIdentifier) Error() string
type ErrUnknownSelector ¶
type ErrUnknownSelector struct {
Selector string
}
ErrUnknownSelector is returned when a dot-expression uses an unknown selector for the type
func (ErrUnknownSelector) Error ¶
func (e ErrUnknownSelector) Error() string
type Evaluatable ¶
func Parse ¶
func Parse(input string) (Evaluatable, error)
Parse parses the given input string as a script and returns an evaluatable object
type FunctionValue ¶
type NullValue ¶
type NullValue struct {
// contains filtered or unexported fields
}
NullValue is the null script result value
type NumberValue ¶
type NumberValue string
NumberValue is a numeric value on the stack
func (NumberValue) AsBool ¶
func (v NumberValue) AsBool() (bool, error)
AsBool returns true if value is nonzero
func (NumberValue) AsInt ¶
func (v NumberValue) AsInt() (int, error)
AsInt returns the inv value, or error if value cannot be converted to int
func (NumberValue) AsString ¶
func (v NumberValue) AsString() (string, error)
AsString returns value as string
func (NumberValue) Call ¶
func (NumberValue) Call(*Scope, []Value) (Value, error)
Call returns ErrNotCallable
func (NumberValue) Eq ¶
func (v NumberValue) Eq(value Value) (bool, error)
Eq compares the string values of the numbers
type PropertiesValue ¶
type PropertiesValue struct {
Properties map[string]*ls.PropertyValue
// contains filtered or unexported fields
}
PropertiesValue is a map[string]*PropertyValue on the stack
func (PropertiesValue) AsBool ¶
func (value PropertiesValue) AsBool() (bool, error)
func (PropertiesValue) AsInt ¶
func (PropertiesValue) AsInt() (int, error)
type Scope ¶
type Scope struct {
// contains filtered or unexported fields
}
Scope keeps the symbols visible at any point during the execution of a script. A nil scope is a valid scope
type StringSliceValue ¶
type StringSliceValue []string
StringSliceValue is a []string on the stack
func (StringSliceValue) AsBool ¶
func (value StringSliceValue) AsBool() (bool, error)
func (StringSliceValue) AsInt ¶
func (StringSliceValue) AsInt() (int, error)
func (StringSliceValue) AsString ¶
func (value StringSliceValue) AsString() (string, error)
type StringValue ¶
type StringValue string
StringValue is a string on the stack
func (StringValue) AsBool ¶
func (value StringValue) AsBool() (bool, error)
func (StringValue) AsInt ¶
func (value StringValue) AsInt() (int, error)
func (StringValue) AsString ¶
func (value StringValue) AsString() (string, error)
type Value ¶
type Value interface {
// Selector selects a field/method from the underlying value.
Selector(string) (Value, error)
// Index selects an value from an indexable value
Index(Value) (Value, error)
// Call a method/function with arguments
Call(*Scope, []Value) (Value, error)
// Eq checks equivalence
Eq(Value) (bool, error)
// Return value as an integer, or return error if it cannot be represented as an integer
AsInt() (int, error)
// Return value as a boolean. Returns false for empty string, empty collection, etc.
AsBool() (bool, error)
AsString() (string, error)
}
Value represents a value on the evaluation stack
func EvaluateWith ¶
EvaluateWith parses and evaluates a script with the given scope
type ValueArrayValue ¶
type ValueArrayValue []Value
ValueArrayValue is a []Value on the stack
func (ValueArrayValue) AsBool ¶
func (value ValueArrayValue) AsBool() (bool, error)
func (ValueArrayValue) AsInt ¶
func (ValueArrayValue) AsInt() (int, error)
func (ValueArrayValue) AsString ¶
func (value ValueArrayValue) AsString() (string, error)