rel

package
v0.88.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: Apache-2.0 Imports: 22 Imported by: 8

Documentation

Index

Constants

View Source
const ArrayItemAttr = "@item"
View Source
const BytesByteAttr = "@byte"

BytesByteAttr is the standard name for the value-attr of a character tuple.

View Source
const DictValueAttr = "@value"
View Source
const StringCharAttr = "@char"

StringCharAttr is the standard name for the value-attr of a character tuple.

Variables

View Source
var (
	None  = Set(GenericSet{frozen.Set{}})
	False = None
	True  = None.With(EmptyTuple)
)

genericSet equivalents for Boolean true and false

View Source
var EmptyNames = Names(frozen.Set{})

EmptyNames is the empty set of names.

View Source
var LexerNamePat = `([$@A-Za-z_][0-9$@A-Za-z_]*)`

LexerNamePat defines valid unquoted identifiers. This really belongs in rel/syntax/lex.go, but that creates a dep cycle.

Functions

func ASTBranchFromValue

func ASTBranchFromValue(b Tuple) ast.Branch

func ASTLeafFromValue

func ASTLeafFromValue(s String) ast.Leaf

func ASTNodeFromValue

func ASTNodeFromValue(value Value) ast.Node

func AssertEqualValues

func AssertEqualValues(t *testing.T, expected, actual Value) bool

AssertEqualValues asserts that the two values are Equal.

func AssertExprErrorEquals added in v0.27.0

func AssertExprErrorEquals(t *testing.T, expr Expr, msg string) bool

AssertExprErrorEquals asserts that the expr returns an error with the given message when evaluated.

func AssertExprErrors added in v0.27.0

func AssertExprErrors(t *testing.T, expr Expr) bool

AssertExprErrors asserts that the expr returns an error when evaluated.

func AssertExprEvalsToType

func AssertExprEvalsToType(t *testing.T, expected interface{}, expr Expr) bool

AssertExprEvalsToType asserts that the exprs evaluate to the same value.

func AssertExprPanics

func AssertExprPanics(t *testing.T, expr Expr) bool

AssertExprPanics asserts that the expr panics when evaluated.

func AssertExprsEvalToSameValue

func AssertExprsEvalToSameValue(t *testing.T, expected, expr Expr) bool

AssertExprsEvalToSameValue asserts that the exprs evaluate to the same value.

func AttrEnumeratorToMap

func AttrEnumeratorToMap(e AttrEnumerator) map[string]Value

AttrEnumeratorToMap transcribes its Attrs in a map.

func Combine

func Combine(a, b Tuple, op CombineOp) map[string]Pair

Combine returns a map of names to pairs of corresponding Values from a and b. Which names appear in the output is determined by the masks provided in op.

func DictTupleMatcher

func DictTupleMatcher() func(v Value) (key, value Value, matches bool)

func EqualValues

func EqualValues(expected, actual Value) bool

func MakeBinValExpr

func MakeBinValExpr(op string, eval valueEval) func(scanner parser.Scanner, a, b Expr) Expr

MakeBinValExpr returns a function that creates a binExpr for the given logical operator.

func MarshalToJSON

func MarshalToJSON(value Value) []byte

MarshalToJSON marshals the given value to JSON with sets escaped as s -> {"{||}": s}.

func NewSeqArrowExpr added in v0.36.0

func NewSeqArrowExpr(withAt bool) func(scanner parser.Scanner, lhs Expr, fn Expr) Expr

NewSequenceMapExpr returns a new SequenceMapExpr.

func Repr

func Repr(v Value) string

func RequireEqualValues

func RequireEqualValues(t *testing.T, expected, actual Value)

RequireEqualValues requires that the two values are Equal.

func RequireExprsEvalToSameValue

func RequireExprsEvalToSameValue(t *testing.T, expected, expr Expr)

RequireExprsEvalToSameValue requires that the exprs evaluate to the same value.

func TupleNameRepr

func TupleNameRepr(name string) string

func TupleOrderedNames

func TupleOrderedNames(t *GenericTuple) []string

TupleOrderedNames returns the names of this tuple in sorted order.

func WrapContext added in v0.68.0

func WrapContext(err error, expr Expr, scope Scope) error

Types

type AndExpr

type AndExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

func (AndExpr) Eval

func (e AndExpr) Eval(local Scope) (Value, error)

func (AndExpr) String

func (e AndExpr) String() string

type Array

type Array struct {
	// contains filtered or unexported fields
}

Array is an ordered collection of Values.

func AsArray

func AsArray(v Value) (Array, bool)

func (Array) ArrayEnumerator

func (a Array) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (Array) CallAll added in v0.3.0

func (a Array) CallAll(arg Value) (Set, error)

func (Array) Count

func (a Array) Count() int

Count returns the number of elements in the Array.

func (Array) Enumerator

func (a Array) Enumerator() ValueEnumerator

Enumerator returns an enumerator over the Values in the Array.

func (Array) Equal

func (a Array) Equal(v interface{}) bool

Equal tests two Sets for equality. Any other type returns false.

func (Array) Eval

func (a Array) Eval(_ Scope) (Value, error)

Eval returns the string.

func (Array) Export

func (a Array) Export() interface{}

Export exports an Array as a slice.

func (Array) Has

func (a Array) Has(value Value) bool

Has returns true iff the given Value is in the Array.

func (Array) Hash

func (a Array) Hash(seed uintptr) uintptr

Hash computes a hash for a Array.

func (Array) IsTrue

func (a Array) IsTrue() bool

IsTrue returns true if the tuple has attributes.

func (Array) Kind

func (a Array) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (Array) Less

func (a Array) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (Array) Map

func (a Array) Map(f func(v Value) Value) Set

Map maps values per f.

func (Array) Negate

func (a Array) Negate() Value

Negate returns {@neg: a}.

func (Array) Shift added in v0.5.0

func (a Array) Shift(offset int) Array

Shift increments the Array's offset

func (Array) Source

func (a Array) Source() parser.Scanner

Source returns a scanner locating the Array's source code.

func (Array) String

func (a Array) String() string

String returns a string representation of an Array.

func (Array) Values

func (a Array) Values() []Value

Values returns the slice of values in the array. Holes in the indices are represented by nil elements.

Callers must not reassign elements of the returned slice.

func (Array) Where

func (a Array) Where(p func(v Value) (bool, error)) (Set, error)

Where returns a new Array with all the Values satisfying predicate p.

func (Array) With

func (a Array) With(value Value) Set

With returns the original Array with given value added. Iff the value was already present, the original Array is returned.

func (Array) Without

func (a Array) Without(value Value) Set

Without returns the original Array without the given value. Iff the value was already absent, the original Array is returned.

type ArrayExpr

type ArrayExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

ArrayExpr represents an expr that evaluates to an Array.

func (ArrayExpr) Eval

func (e ArrayExpr) Eval(local Scope) (Value, error)

Eval returns the subject.

func (ArrayExpr) String

func (e ArrayExpr) String() string

String returns a string representation of the expression.

type ArrayItemTuple

type ArrayItemTuple struct {
	// contains filtered or unexported fields
}

ArrayItemTuple represents a tuple of the form (@: at, @item: item).

func NewArrayItemTuple

func NewArrayItemTuple(at int, item Value) ArrayItemTuple

NewArrayItemTuple constructs a CharTuple.

func (ArrayItemTuple) Count

func (t ArrayItemTuple) Count() int

Count returns how many attributes are in the Tuple.

func (ArrayItemTuple) Enumerator

func (t ArrayItemTuple) Enumerator() AttrEnumerator

Enumerator returns an enumerator over the Values in the CharTuple.

func (ArrayItemTuple) Equal

func (t ArrayItemTuple) Equal(v interface{}) bool

Equal tests two Tuples for equality. Any other type returns false.

func (ArrayItemTuple) Eval

func (t ArrayItemTuple) Eval(local Scope) (Value, error)

Eval returns the tuple.

func (ArrayItemTuple) Export

func (t ArrayItemTuple) Export() interface{}

Export exports a Tuple.

func (ArrayItemTuple) Get

func (t ArrayItemTuple) Get(name string) (Value, bool)

Get returns the Value associated with a name, and true iff it was found.

func (ArrayItemTuple) HasName

func (t ArrayItemTuple) HasName(name string) bool

HasName returns true iff the Tuple has an attribute with the given name.

func (ArrayItemTuple) Hash

func (t ArrayItemTuple) Hash(seed uintptr) uintptr

Hash computes a hash for a CharTuple.

func (ArrayItemTuple) IsTrue

func (t ArrayItemTuple) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (ArrayItemTuple) Kind

func (t ArrayItemTuple) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (ArrayItemTuple) Less

func (t ArrayItemTuple) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (ArrayItemTuple) Map

func (t ArrayItemTuple) Map(f func(Value) Value) Tuple

func (ArrayItemTuple) MustGet

func (t ArrayItemTuple) MustGet(name string) Value

MustGet returns e.Get(name) or panics if an error occurs.

func (ArrayItemTuple) Names

func (t ArrayItemTuple) Names() Names

Names returns the attribute names.

func (ArrayItemTuple) Negate

func (t ArrayItemTuple) Negate() Value

func (ArrayItemTuple) Project

func (t ArrayItemTuple) Project(names Names) Tuple

Project returns a tuple with the given names from this tuple, or nil if any name wasn't found.

func (ArrayItemTuple) Source

func (t ArrayItemTuple) Source() parser.Scanner

Source returns a scanner locating the ArrayItemTuple's source code.

func (ArrayItemTuple) String

func (t ArrayItemTuple) String() string

String returns a string representation of a Tuple.

func (ArrayItemTuple) With

func (t ArrayItemTuple) With(name string, value Value) Tuple

With returns a Tuple with all name/Value pairs in t (except the one for the given name, if present) with the addition of the given name/Value pair.

func (ArrayItemTuple) Without

func (t ArrayItemTuple) Without(name string) Tuple

Without returns a Tuple with all name/Value pairs in t exception the one of the given name.

type ArrayItemTupleExpr

type ArrayItemTupleExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

ArrayItemTupleExpr represents an expr that evaluates to an ArrayItemTuple.

func NewArrayItemTupleExpr

func NewArrayItemTupleExpr(scanner parser.Scanner, at, value Expr) ArrayItemTupleExpr

NewArrayItemTupleExpr returns a new ArrayItemTupleExpr.

func (ArrayItemTupleExpr) Eval

func (e ArrayItemTupleExpr) Eval(local Scope) (_ Value, err error)

Eval returns the subject.

func (ArrayItemTupleExpr) String

func (e ArrayItemTupleExpr) String() string

String returns a string representation of the expression.

type ArrayPattern

type ArrayPattern struct {
	// contains filtered or unexported fields
}

func NewArrayPattern

func NewArrayPattern(elements ...FallbackPattern) ArrayPattern

func (ArrayPattern) Bind

func (p ArrayPattern) Bind(local Scope, value Value) (Scope, error)

func (ArrayPattern) Bindings added in v0.71.0

func (p ArrayPattern) Bindings() []string

func (ArrayPattern) String

func (p ArrayPattern) String() string

type ArrowExpr

type ArrowExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

ArrowExpr returns the tuple applied to a function.

func (*ArrowExpr) Eval

func (e *ArrowExpr) Eval(local Scope) (_ Value, err error)

Eval returns the lhs

func (*ArrowExpr) String

func (e *ArrowExpr) String() string

String returns a string representation of the expression.

type Attr

type Attr struct {
	Name  string
	Value Value
}

Attr is a name/Value pair used to construct a Tuple.

func AttrEnumeratorToSlice

func AttrEnumeratorToSlice(e AttrEnumerator) []Attr

AttrEnumeratorToSlice transcribes its Attrs in a slice.

func NewAttr

func NewAttr(name string, value Value) Attr

NewAttr returns an Attr with the given name and value.

func NewBoolAttr

func NewBoolAttr(name string, value bool) Attr

NewBoolAttr return an attr with a bool value.

func NewFloatAttr

func NewFloatAttr(name string, value float64) Attr

NewFloatAttr return an attr with a float value.

func NewIntAttr

func NewIntAttr(name string, value int) Attr

NewIntAttr return an attr with an int value.

func NewNativeFunctionAttr

func NewNativeFunctionAttr(name string, fn func(Value) (Value, error)) Attr

NewNativeFunctionAttr returns a new Attr with a named key and NativeFunction value.

func NewStringAttr

func NewStringAttr(name string, value []rune) Attr

NewStringAttr return an attr with a string value.

func NewTupleAttr

func NewTupleAttr(name string, attrs ...Attr) Attr

NewTupleAttr return an attr with a new tuple value.

type AttrEnumerator

type AttrEnumerator interface {
	MoveNext() bool
	Current() (string, Value)
}

AttrEnumerator enumerates Values.

type AttrExpr

type AttrExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

AttrExpr represents a single name:expr in a TupleExpr.

func MustNewAttrExpr

func MustNewAttrExpr(scanner parser.Scanner, name string, expr Expr) AttrExpr

func NewAttrExpr

func NewAttrExpr(scanner parser.Scanner, name string, expr Expr) (AttrExpr, error)

NewAttrExpr constructs a new AttrExpr from the given arguments.

func NewWildcardExpr

func NewWildcardExpr(scanner parser.Scanner, lhs Expr) AttrExpr

NewWildcardExpr constructs a new wildcard AttrExpr.

func (*AttrExpr) Apply

func (e *AttrExpr) Apply(
	local Scope, tuple Tuple,
) (Tuple, error)

Apply applies the AttrExpr to the Tuple.

func (*AttrExpr) IsWildcard

func (e *AttrExpr) IsWildcard() bool

IsWildcard returns true iff the AttrExpr is a wildcard expression.

type BinExpr

type BinExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

BinExpr represents a range of operators.

func (*BinExpr) Eval

func (e *BinExpr) Eval(local Scope) (_ Value, err error)

Eval returns the subject

func (*BinExpr) String

func (e *BinExpr) String() string

String returns a string representation of the expression.

type BindMatcher

type BindMatcher struct {
	// contains filtered or unexported fields
}

func Bind

func Bind(target interface{}) BindMatcher

func (BindMatcher) Match

func (m BindMatcher) Match(v Value) bool

type Bytes

type Bytes struct {
	// contains filtered or unexported fields
}

Bytes is a set of Values.

func AsBytes

func AsBytes(s Set) (Bytes, bool)

func (Bytes) ArrayEnumerator

func (b Bytes) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (Bytes) Bytes

func (b Bytes) Bytes() []byte

Bytes returns the bytes of b. The caller must not modify the contents.

func (Bytes) CallAll added in v0.3.0

func (b Bytes) CallAll(arg Value) (Set, error)

func (Bytes) Count

func (b Bytes) Count() int

Count returns the number of elements in the Bytes.

func (Bytes) Enumerator

func (b Bytes) Enumerator() ValueEnumerator

Enumerator returns an enumerator over the Values in the Bytes.

func (Bytes) Equal

func (b Bytes) Equal(v interface{}) bool

Equal tests two Sets for equality. Any other type returns false.

func (Bytes) Eval

func (b Bytes) Eval(_ Scope) (Value, error)

Eval returns the string.

func (Bytes) Export

func (b Bytes) Export() interface{}

Export exports a Bytes as a string.

func (Bytes) Has

func (b Bytes) Has(value Value) bool

Has returns true iff the given Value is in the Bytes.

func (Bytes) Hash

func (b Bytes) Hash(seed uintptr) uintptr

Hash computes a hash for a Bytes.

func (Bytes) IsTrue

func (b Bytes) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (Bytes) Kind

func (b Bytes) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (Bytes) Less

func (b Bytes) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (Bytes) Map

func (b Bytes) Map(f func(v Value) Value) Set

Map maps values per f.

func (Bytes) Negate

func (b Bytes) Negate() Value

Negate returns {(negateTag): b}.

func (Bytes) Source

func (b Bytes) Source() parser.Scanner

Source returns a scanner locating the Bytes's source code.

func (Bytes) String

func (b Bytes) String() string

String returns a string representation of a Bytes.

func (Bytes) Where

func (b Bytes) Where(p func(v Value) (bool, error)) (Set, error)

Where returns a new Bytes with all the Values satisfying predicate p.

func (Bytes) With

func (b Bytes) With(value Value) Set

With returns the original Bytes with given value added. Iff the value was already present, the original Bytes is returned.

func (Bytes) Without

func (b Bytes) Without(value Value) Set

Without returns the original Bytes without the given value. Iff the value was already absent, the original Bytes is returned.

type BytesByteTuple

type BytesByteTuple struct {
	// contains filtered or unexported fields
}

BytesByteTuple represents a tuple of the form (@: at, @byte: byteval).

func NewBytesByteTuple

func NewBytesByteTuple(at int, byteval byte) BytesByteTuple

NewBytesByteTuple constructs a BytesByteTuple.

func (BytesByteTuple) Count

func (t BytesByteTuple) Count() int

Count returns how many attributes are in the Tuple.

func (BytesByteTuple) Enumerator

func (t BytesByteTuple) Enumerator() AttrEnumerator

Enumerator returns an enumerator over the Values in the BytesByteTuple.

func (BytesByteTuple) Equal

func (t BytesByteTuple) Equal(v interface{}) bool

Equal tests two Tuples for equality. Any other type returns false.

func (BytesByteTuple) Eval

func (t BytesByteTuple) Eval(local Scope) (Value, error)

Eval returns the tuple.

func (BytesByteTuple) Export

func (t BytesByteTuple) Export() interface{}

Export exports a Tuple.

func (BytesByteTuple) Get

func (t BytesByteTuple) Get(name string) (Value, bool)

Get returns the Value associated with a name, and true iff it was found.

func (BytesByteTuple) HasName

func (t BytesByteTuple) HasName(name string) bool

HasName returns true iff the Tuple has an attribute with the given name.

func (BytesByteTuple) Hash

func (t BytesByteTuple) Hash(seed uintptr) uintptr

Hash computes a hash for a BytesByteTuple.

func (BytesByteTuple) IsTrue

func (t BytesByteTuple) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (BytesByteTuple) Kind

func (t BytesByteTuple) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (BytesByteTuple) Less

func (t BytesByteTuple) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (BytesByteTuple) Map

func (t BytesByteTuple) Map(f func(Value) Value) Tuple

func (BytesByteTuple) MustGet

func (t BytesByteTuple) MustGet(name string) Value

MustGet returns e.Get(name) or panics if an error occurs.

func (BytesByteTuple) Names

func (t BytesByteTuple) Names() Names

Names returns the attribute names.

func (BytesByteTuple) Negate

func (t BytesByteTuple) Negate() Value

func (BytesByteTuple) Project

func (t BytesByteTuple) Project(names Names) Tuple

Project returns a tuple with the given names from this tuple, or nil if any name wasn't found.

func (BytesByteTuple) Source

func (t BytesByteTuple) Source() parser.Scanner

Source returns a scanner locating the BytesByteTuple's source code.

func (BytesByteTuple) String

func (t BytesByteTuple) String() string

String returns a string representation of a Tuple.

func (BytesByteTuple) With

func (t BytesByteTuple) With(name string, value Value) Tuple

With returns a Tuple with all name/Value pairs in t (except the one for the given name, if present) with the addition of the given name/Value pair.

func (BytesByteTuple) Without

func (t BytesByteTuple) Without(name string) Tuple

Without returns a Tuple with all name/Value pairs in t exception the one of the given name.

type BytesEnumerator

type BytesEnumerator struct {
	// contains filtered or unexported fields
}

BytesEnumerator represents an enumerator over a Bytes.

func (*BytesEnumerator) Current

func (e *BytesEnumerator) Current() Value

Current returns the enumerator'b current Value.

func (*BytesEnumerator) MoveNext

func (e *BytesEnumerator) MoveNext() bool

MoveNext moves the enumerator to the next Value.

type BytesExpr added in v0.3.0

type BytesExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

BytesExpr is an expression that evaluates to a Byte Array

func (BytesExpr) Eval added in v0.3.0

func (b BytesExpr) Eval(local Scope) (Value, error)

func (BytesExpr) String added in v0.3.0

func (b BytesExpr) String() string

type Closure

type Closure struct {
	// contains filtered or unexported fields
}

Closure represents the closure of a function over a scope.

func NewClosure

func NewClosure(scope Scope, f *Function) Closure

NewFunction returns a new function.

func (Closure) ArrayEnumerator added in v0.3.0

func (c Closure) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (Closure) CallAll added in v0.3.0

func (c Closure) CallAll(arg Value) (Set, error)

func (Closure) Count added in v0.3.0

func (c Closure) Count() int

func (Closure) Enumerator added in v0.3.0

func (c Closure) Enumerator() ValueEnumerator

func (Closure) Equal

func (c Closure) Equal(i interface{}) bool

Equal tests two Values for equality. Any other type returns false.

func (Closure) EqualClosure

func (c Closure) EqualClosure(d Closure) bool

Equal tests two Values for equality. Any other type returns false.

func (Closure) Eval

func (c Closure) Eval(local Scope) (Value, error)

Eval returns the Value

func (Closure) Export

func (c Closure) Export() interface{}

Export exports a Closure.

func (Closure) Has added in v0.3.0

func (c Closure) Has(v Value) bool

func (Closure) Hash

func (c Closure) Hash(seed uintptr) uintptr

Hash computes a hash for a Closure.

func (Closure) IsTrue

func (c Closure) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (Closure) Kind

func (c Closure) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (Closure) Less

func (c Closure) Less(d Value) bool

Less returns true iff g is not a number or f.number < g.number.

func (Closure) Map added in v0.3.0

func (c Closure) Map(f func(Value) Value) Set

func (Closure) Negate

func (c Closure) Negate() Value

Negate returns {(negateTag): f}.

func (Closure) Source

func (c Closure) Source() parser.Scanner

Source returns a scanner locating the Closure's source code.

func (Closure) String

func (c Closure) String() string

String returns a string representation of the expression.

func (Closure) Where added in v0.3.0

func (c Closure) Where(p func(v Value) (bool, error)) (Set, error)

func (Closure) With added in v0.3.0

func (c Closure) With(v Value) Set

func (Closure) Without added in v0.3.0

func (c Closure) Without(v Value) Set

type CombineOp

type CombineOp int

CombineOp specifies which pairings to include in Combine().

const (
	OnlyOnLHS CombineOp = 1 << iota // Include elements only found on lhs.
	InBoth                          // Include elements found on both sides.
	OnlyOnRHS                       // Include elements only found on rhs.

	AllPairs = OnlyOnLHS | InBoth | OnlyOnRHS
)

The following masks control which elements to include in Combine().

type CompareExpr

type CompareExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

CompareExpr represents a range of operators.

func NewCompareExpr

func NewCompareExpr(scanner parser.Scanner, args []Expr, comps []CompareFunc, ops []string) CompareExpr

func (CompareExpr) Eval

func (e CompareExpr) Eval(local Scope) (Value, error)

Eval returns the subject

func (CompareExpr) String

func (e CompareExpr) String() string

String returns a string representation of the expression.

type CompareFunc

type CompareFunc func(a, b Value) (bool, error)

type CondExpr

type CondExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

CondExpr returns the tuple applied to a function, the expression looks like: cond (1 > 0: 2 + 1, 3 > 4: 5, _: 10). The original keyword was switch (SwitchExpr), and finally it was chanaged from switch to cond. The keyword cond is more unusual, therefore less likely to be chosen as a regular name, and avoids accidental comparisons with the switch statement in other languages.

func (CondExpr) Eval

func (e CondExpr) Eval(local Scope) (Value, error)

Eval returns the value of true condition, or default condition value.

func (CondExpr) String

func (e CondExpr) String() string

String returns a string representation of the expression.

type CondPatternControlVarExpr added in v0.3.0

type CondPatternControlVarExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

CondPatternControlVarExpr which is used for `cond` pattern matching.

func (CondPatternControlVarExpr) Eval added in v0.3.0

func (expr CondPatternControlVarExpr) Eval(scope Scope) (Value, error)

Eval evaluates to find the first valid condition and return its value.

func (CondPatternControlVarExpr) String added in v0.3.0

func (expr CondPatternControlVarExpr) String() string

type ContextErr added in v0.4.0

type ContextErr struct {
	// contains filtered or unexported fields
}

ContextErr represents the whole stack frame of an error from arrai script.

func NewContextErr added in v0.59.0

func NewContextErr(err error, source parser.Scanner, scope Scope) ContextErr

func (ContextErr) Error added in v0.4.0

func (c ContextErr) Error() string

func (ContextErr) GetImportantFrames added in v0.59.0

func (c ContextErr) GetImportantFrames() []ContextErr

GetImportantFrames returns an array of important frames whose last element is the last frame near the point of failure. Important frames are frames that don't contain the frame under it.

func (ContextErr) GetLastScope added in v0.4.0

func (c ContextErr) GetLastScope() Scope

GetLastScope gets the scope nearest to the error

func (ContextErr) GetScope added in v0.59.0

func (c ContextErr) GetScope() Scope

func (ContextErr) GetSource added in v0.59.0

func (c ContextErr) GetSource() parser.Scanner

func (ContextErr) NextErr added in v0.8.0

func (c ContextErr) NextErr() error

NextErr returns the error contained in ContextErr

type DArrowExpr

type DArrowExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

DArrowExpr returns the set applied elementwise to a function.

func (*DArrowExpr) Eval

func (e *DArrowExpr) Eval(local Scope) (_ Value, err error)

Eval returns the lhs transformed elementwise by fn.

func (*DArrowExpr) String

func (e *DArrowExpr) String() string

String returns a string representation of the expression.

type Dict

type Dict struct {
	// contains filtered or unexported fields
}

Dict is a map from keys to values.

func (Dict) ArrayEnumerator

func (d Dict) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (Dict) CallAll added in v0.3.0

func (d Dict) CallAll(arg Value) (Set, error)

func (Dict) Count

func (d Dict) Count() int

func (Dict) DictEnumerator

func (d Dict) DictEnumerator() *DictEnumerator

func (Dict) Enumerator

func (d Dict) Enumerator() ValueEnumerator

func (Dict) Equal

func (d Dict) Equal(v interface{}) bool

func (Dict) Eval

func (d Dict) Eval(local Scope) (Value, error)

func (Dict) Export

func (d Dict) Export() interface{}

func (Dict) Has

func (d Dict) Has(v Value) bool

func (Dict) Hash

func (d Dict) Hash(seed uintptr) uintptr

func (Dict) IsTrue

func (d Dict) IsTrue() bool

func (Dict) Kind

func (d Dict) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (Dict) Less

func (d Dict) Less(v Value) bool

func (Dict) Map

func (d Dict) Map(m func(Value) Value) Set

func (Dict) Negate

func (d Dict) Negate() Value

func (Dict) OrderedEntries

func (d Dict) OrderedEntries() []DictEntryTuple

func (Dict) Source

func (d Dict) Source() parser.Scanner

Source returns a scanner locating the Dict's source code.

func (Dict) String

func (d Dict) String() string

func (Dict) Where

func (d Dict) Where(p func(v Value) (bool, error)) (Set, error)

func (Dict) With

func (d Dict) With(v Value) Set

func (Dict) Without

func (d Dict) Without(v Value) Set

type DictEntryTuple

type DictEntryTuple struct {
	// contains filtered or unexported fields
}

DictEntryTuple represents a tuple of the form (@: at, @value: item).

func NewDictEntryTuple

func NewDictEntryTuple(at Value, item Value) DictEntryTuple

NewDictEntryTuple constructs a CharTuple.

func (DictEntryTuple) Count

func (t DictEntryTuple) Count() int

Count returns how many attributes are in the Tuple.

func (DictEntryTuple) Enumerator

func (t DictEntryTuple) Enumerator() AttrEnumerator

Enumerator returns an enumerator over the Values in the CharTuple.

func (DictEntryTuple) Equal

func (t DictEntryTuple) Equal(v interface{}) bool

Equal tests two Tuples for equality. Any other type returns false.

func (DictEntryTuple) Eval

func (t DictEntryTuple) Eval(local Scope) (Value, error)

Eval returns the tuple.

func (DictEntryTuple) Export

func (t DictEntryTuple) Export() interface{}

Export exports a Tuple.

func (DictEntryTuple) Get

func (t DictEntryTuple) Get(name string) (Value, bool)

Get returns the Value associated with a name, and true iff it was found.

func (DictEntryTuple) HasName

func (t DictEntryTuple) HasName(name string) bool

HasName returns true iff the Tuple has an attribute with the given name.

func (DictEntryTuple) Hash

func (t DictEntryTuple) Hash(seed uintptr) uintptr

Hash computes a hash for a CharTuple.

func (DictEntryTuple) IsTrue

func (t DictEntryTuple) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (DictEntryTuple) Kind

func (t DictEntryTuple) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (DictEntryTuple) Less

func (t DictEntryTuple) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (DictEntryTuple) Map

func (t DictEntryTuple) Map(f func(Value) Value) Tuple

func (DictEntryTuple) MustGet

func (t DictEntryTuple) MustGet(name string) Value

MustGet returns e.Get(name) or panics if an error occurs.

func (DictEntryTuple) Names

func (t DictEntryTuple) Names() Names

Names returns the attribute names.

func (DictEntryTuple) Negate

func (t DictEntryTuple) Negate() Value

func (DictEntryTuple) Project

func (t DictEntryTuple) Project(names Names) Tuple

Project returns a tuple with the given names from this tuple, or nil if any name wasn't found.

func (DictEntryTuple) Source

func (t DictEntryTuple) Source() parser.Scanner

Source returns a scanner locating the DictEntryTuple's source code.

func (DictEntryTuple) String

func (t DictEntryTuple) String() string

String returns a string representation of a Tuple.

func (DictEntryTuple) With

func (t DictEntryTuple) With(name string, value Value) Tuple

With returns a Tuple with all name/Value pairs in t (except the one for the given name, if present) with the addition of the given name/Value pair.

func (DictEntryTuple) Without

func (t DictEntryTuple) Without(name string) Tuple

Without returns a Tuple with all name/Value pairs in t exception the one of the given name.

type DictEntryTupleExpr

type DictEntryTupleExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

DictEntryTupleExpr represents an expr that evaluates to a DictEntryTuple.

func NewDictEntryTupleExpr

func NewDictEntryTupleExpr(scanner parser.Scanner, at, value Expr) DictEntryTupleExpr

NewDictEntryTupleExpr returns a new dictEntryTupleExpr.

func (DictEntryTupleExpr) Eval

func (e DictEntryTupleExpr) Eval(local Scope) (Value, error)

Eval returns the subject

func (DictEntryTupleExpr) String

func (e DictEntryTupleExpr) String() string

String returns a string representation of the expression.

type DictEnumerator

type DictEnumerator struct {
	// contains filtered or unexported fields
}

func (*DictEnumerator) Current

func (a *DictEnumerator) Current() (key, value Value)

func (*DictEnumerator) MoveNext

func (a *DictEnumerator) MoveNext() bool

type DictExpr

type DictExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

DictExpr represents an expression that yields a dict.

func (DictExpr) Eval

func (e DictExpr) Eval(local Scope) (Value, error)

Eval returns the subject

func (DictExpr) String

func (e DictExpr) String() string

String returns a string representation of the expression.

type DictPattern added in v0.3.0

type DictPattern struct {
	// contains filtered or unexported fields
}

func NewDictPattern added in v0.3.0

func NewDictPattern(entries ...DictPatternEntry) DictPattern

func (DictPattern) Bind added in v0.3.0

func (p DictPattern) Bind(local Scope, value Value) (Scope, error)

func (DictPattern) Bindings added in v0.71.0

func (p DictPattern) Bindings() []string

func (DictPattern) String added in v0.3.0

func (p DictPattern) String() string

type DictPatternEntry added in v0.3.0

type DictPatternEntry struct {
	// contains filtered or unexported fields
}

func NewDictPatternEntry added in v0.3.0

func NewDictPatternEntry(at Expr, pattern FallbackPattern) DictPatternEntry

func (DictPatternEntry) String added in v0.3.0

func (p DictPatternEntry) String() string

type DotExpr

type DotExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

DotExpr returns the tuple or set with a single field replaced by an expression.

func (*DotExpr) Attr

func (x *DotExpr) Attr() string

Attr returns the name of the attribute accessed by the DotExpr.

func (*DotExpr) Eval

func (x *DotExpr) Eval(local Scope) (_ Value, err error)

Eval returns the lhs

func (*DotExpr) String

func (x *DotExpr) String() string

String returns a string representation of the expression.

func (*DotExpr) Subject

func (x *DotExpr) Subject() Expr

Subject returns the DotExpr's LHS.

type Expr

type Expr interface {
	// Require a String() method.
	fmt.Stringer

	// Eval evaluates the expr in a given scope.
	Eval(local Scope) (Value, error)

	Source() parser.Scanner
}

Expr represents an arr.ai expression.

func NewAddExpr

func NewAddExpr(scanner parser.Scanner, a, b Expr) Expr

NewAddExpr evaluates a + b, given two Numbers.

func NewAndExpr

func NewAndExpr(scanner parser.Scanner, a, b Expr) Expr

func NewArrayExpr

func NewArrayExpr(scanner parser.Scanner, elements ...Expr) Expr

NewArrayExpr returns a new Expr that constructs an Array.

func NewArrowExpr

func NewArrowExpr(scanner parser.Scanner, lhs, fn Expr) Expr

NewArrowExpr returns a new ArrowExpr.

func NewBytesExpr added in v0.3.0

func NewBytesExpr(scanner parser.Scanner, elements ...Expr) Expr

func NewCallExpr

func NewCallExpr(scanner parser.Scanner, a, b Expr) Expr

NewCallExpr evaluates a without b, given a set lhs.

func NewCallExprCurry

func NewCallExprCurry(scanner parser.Scanner, f Expr, args ...Expr) Expr

func NewConcatExpr

func NewConcatExpr(scanner parser.Scanner, a, b Expr) Expr

NewConcatExpr evaluates a ++ b.

func NewCondExpr

func NewCondExpr(scanner parser.Scanner, dict Expr) Expr

NewCondExpr returns a new CondExpr.

func NewCondPatternControlVarExpr added in v0.3.0

func NewCondPatternControlVarExpr(scanner parser.Scanner, controlVar Expr, patternExprs ...PatternExprPair) Expr

NewCondPatternControlVarExpr returns a new CondPatternControlVarExpr.

func NewCountExpr

func NewCountExpr(scanner parser.Scanner, a Expr) Expr

NewCountExpr evaluates to the number of elements in a.

func NewDArrowExpr added in v0.33.0

func NewDArrowExpr(scanner parser.Scanner, lhs Expr, fn Expr) Expr

NewDArrowExpr returns a new DArrowExpr.

func NewDictExpr

func NewDictExpr(
	scanner parser.Scanner,
	allowDupKeys bool, dictExprAlways bool, entryExprs ...DictEntryTupleExpr,
) Expr

NewDictExpr returns a new DictExpr from pairs.

func NewDiffExpr

func NewDiffExpr(scanner parser.Scanner, a, b Expr) Expr

NewDiffExpr evaluates a &~ b.

func NewDivExpr

func NewDivExpr(scanner parser.Scanner, a, b Expr) Expr

NewDivExpr evaluates a / b, given two Numbers.

func NewDotExpr

func NewDotExpr(scanner parser.Scanner, lhs Expr, attr string) Expr

NewDotExpr returns a new DotExpr that fetches the given attr from the lhs, which is expected to be a tuple.

func NewEvalExpr

func NewEvalExpr(scanner parser.Scanner, a Expr) Expr

NewEvalExpr evaluates to *a, given a set lhs.

func NewFunction

func NewFunction(scanner parser.Scanner, arg Pattern, body Expr) Expr

NewFunction returns a new function.

func NewIdivExpr

func NewIdivExpr(scanner parser.Scanner, a, b Expr) Expr

NewIdivExpr evaluates ⎣a / b⎦, given two Numbers.

func NewIfElseExpr

func NewIfElseExpr(scanner parser.Scanner, ifTrue, cond, ifFalse Expr) Expr

NewIfElseExpr returns a new IfElseExpr. Deprecated: NewIfElseExpr will be removed, it should use NewCondExpr instead.

func NewIntersectExpr

func NewIntersectExpr(scanner parser.Scanner, a, b Expr) Expr

NewIntersectExpr evaluates a <&> b.

func NewJoinExpr

func NewJoinExpr(scanner parser.Scanner, a, b Expr) Expr

NewJoinExpr evaluates a <&> b.

func NewMaxExpr

func NewMaxExpr(scanner parser.Scanner, a, b Expr) Expr

NewMaxExpr evaluates to the max of expr over all elements in a.

func NewMeanExpr

func NewMeanExpr(scanner parser.Scanner, a, b Expr) Expr

NewMeanExpr evaluates to the mean of expr over all elements in a.

func NewMedianExpr

func NewMedianExpr(scanner parser.Scanner, a, b Expr) Expr

NewMedianExpr evaluates to the median of expr over all elements in a.

func NewMinExpr

func NewMinExpr(scanner parser.Scanner, a, b Expr) Expr

NewMinExpr evaluates to the min of expr over all elements in a.

func NewModExpr

func NewModExpr(scanner parser.Scanner, a, b Expr) Expr

NewModExpr evaluates a % b, given two Numbers.

func NewMulExpr

func NewMulExpr(scanner parser.Scanner, a, b Expr) Expr

NewMulExpr evaluates a * b, given two Numbers.

func NewNegExpr

func NewNegExpr(scanner parser.Scanner, a Expr) Expr

NewNegExpr evaluates to -a.

func NewNestExpr

func NewNestExpr(scanner parser.Scanner, lhs Expr, attrs Names, attr string) Expr

NewNestExpr returns a new NestExpr.

func NewNotExpr

func NewNotExpr(scanner parser.Scanner, a Expr) Expr

NewNotExpr evaluates to !a.

func NewOffsetExpr

func NewOffsetExpr(scanner parser.Scanner, n, s Expr) Expr

NewOffsetExpr returns a new OffsetExpr

func NewOrExpr

func NewOrExpr(scanner parser.Scanner, a, b Expr) Expr

func NewOrderByExpr

func NewOrderByExpr(scanner parser.Scanner, a, key Expr) Expr

NewOrderByExpr evaluates a orderby key, given a set lhs, returning an array.

func NewOrderExpr

func NewOrderExpr(scanner parser.Scanner, a, key Expr) Expr

NewOrderExpr evaluates a order less, given a set lhs, returning an array.

func NewPosExpr

func NewPosExpr(scanner parser.Scanner, a Expr) Expr

NewPosExpr evaluates to a.

func NewPowExpr

func NewPowExpr(scanner parser.Scanner, a, b Expr) Expr

NewPowExpr evaluates a to the power of b, given two Numbers.

func NewPowerSetExpr

func NewPowerSetExpr(scanner parser.Scanner, a Expr) Expr

NewPowerSetExpr evaluates to ^a.

func NewRankExpr added in v0.3.0

func NewRankExpr(scanner parser.Scanner, a, key Expr) Expr

NewRankExpr evaluates a rank tuplef, given a relation lhs, returning a new relation with each lhs tuple augmented by the tuplef attrs containing the corresponding rank.

func NewRecursionExpr added in v0.3.0

func NewRecursionExpr(scanner parser.Scanner, name Expr, fn Expr, fix, fixt Value) Expr

func NewReduceExpr

func NewReduceExpr(scanner parser.Scanner,
	a Expr,
	f *Function,
	format string,
	init func(s Set) (interface{}, error),
	reduce func(acc interface{}, v Value) (interface{}, error),
	output func(acc interface{}) (Value, error),
) Expr

NewReduceExpr evaluates a reduce f, given a set lhs.

func NewRelationExpr

func NewRelationExpr(scanner parser.Scanner, names []string, tuples ...[]Expr) (Expr, error)

NewRelationExpr returns a new relation for the given data.

func NewSafeTailExpr added in v0.3.0

func NewSafeTailExpr(scanner parser.Scanner, fallback, base Expr, tailExprs []SafeTailCallback) Expr

func NewSetExpr

func NewSetExpr(scanner parser.Scanner, elements ...Expr) Expr

NewSetExpr returns a new TupleExpr.

func NewSingleExpr added in v0.3.0

func NewSingleExpr(scanner parser.Scanner, a Expr) Expr

NewSingleExpr evaluates to the single element in a or fails if a count != 1.

func NewSubExpr

func NewSubExpr(scanner parser.Scanner, a, b Expr) Expr

NewSubExpr evaluates a - b, given two Numbers.

func NewSubModExpr

func NewSubModExpr(scanner parser.Scanner, a, b Expr) Expr

NewSubModExpr evaluates a % b, given two Numbers.

func NewSumExpr

func NewSumExpr(scanner parser.Scanner, a, b Expr) Expr

NewSumExpr evaluates to the sum of expr over all elements in a.

func NewSymmDiffExpr

func NewSymmDiffExpr(scanner parser.Scanner, a, b Expr) Expr

NewSymmDiffExpr evaluates a ~~ b.

func NewTupleExpr

func NewTupleExpr(scanner parser.Scanner, attrs ...AttrExpr) Expr

NewTupleExpr returns a new TupleExpr.

func NewTupleExprFromMap

func NewTupleExprFromMap(scanner parser.Scanner, attrMap map[string]Expr) Expr

NewTupleExprFromMap returns a new TupleExpr from a map[string]Expr.

func NewTupleMapExpr

func NewTupleMapExpr(scanner parser.Scanner, lhs Expr, fn Expr) Expr

NewAngleArrowExpr returns a new AtArrowExpr.

func NewUnionExpr

func NewUnionExpr(scanner parser.Scanner, a, b Expr) Expr

NewUnionExpr evaluates a | b.

func NewUnnestExpr

func NewUnnestExpr(scanner parser.Scanner, lhs Expr, attr string) Expr

NewUnnestExpr returns a new UnnestExpr.

func NewWhereExpr

func NewWhereExpr(scanner parser.Scanner, a, pred Expr) Expr

NewWhereExpr evaluates a where pred, given a set lhs.

func NewWithExpr

func NewWithExpr(scanner parser.Scanner, a, b Expr) Expr

NewWithExpr evaluates a with b, given a set lhs.

func NewWithoutExpr

func NewWithoutExpr(scanner parser.Scanner, a, b Expr) Expr

NewWithoutExpr evaluates a without b, given a set lhs.

type ExprClosure

type ExprClosure struct {
	// contains filtered or unexported fields
}

ExprClosure represents the closure of an expression over a scope.

func (ExprClosure) ArrayEnumerator added in v0.3.0

func (ExprClosure) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (ExprClosure) CallAll added in v0.3.0

func (c ExprClosure) CallAll(arg Value) (Set, error)

func (ExprClosure) Count added in v0.3.0

func (ExprClosure) Count() int

func (ExprClosure) Enumerator added in v0.3.0

func (ExprClosure) Enumerator() ValueEnumerator

func (ExprClosure) Equal

func (c ExprClosure) Equal(i interface{}) bool

Equal tests two Values for equality. Any other type returns false.

func (ExprClosure) EqualExprClosure

func (c ExprClosure) EqualExprClosure(d ExprClosure) bool

Equal tests two Values for equality. Any other type returns false.

func (ExprClosure) Eval

func (c ExprClosure) Eval(_ Scope) (Value, error)

Eval returns the Value

func (ExprClosure) Export

func (c ExprClosure) Export() interface{}

Export exports a ExprClosure.

func (ExprClosure) Has added in v0.3.0

func (ExprClosure) Has(Value) bool

func (ExprClosure) Hash

func (c ExprClosure) Hash(seed uintptr) uintptr

Hash computes a hash for a ExprClosure.

func (ExprClosure) IsTrue

func (c ExprClosure) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (ExprClosure) Kind

func (c ExprClosure) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (ExprClosure) Less

func (c ExprClosure) Less(d Value) bool

Less returns true iff g is not a number or f.number < g.number.

func (ExprClosure) Map added in v0.3.0

func (ExprClosure) Map(func(Value) Value) Set

func (ExprClosure) Negate

func (c ExprClosure) Negate() Value

Negate returns {(negateTag): f}.

func (ExprClosure) Source

func (c ExprClosure) Source() parser.Scanner

Source returns a scanner locating the ExprClosure's source code.

func (ExprClosure) String

func (c ExprClosure) String() string

String returns a string representation of the expression.

func (ExprClosure) Where added in v0.3.0

func (ExprClosure) Where(p func(v Value) (bool, error)) (Set, error)

func (ExprClosure) With added in v0.3.0

func (c ExprClosure) With(Value) Set

func (ExprClosure) Without added in v0.3.0

func (ExprClosure) Without(Value) Set

type ExprExpr added in v0.50.0

type ExprExpr struct {
	ExprScanner
	Expr
}

ExprExpr represents an expression that yields a Literal.

func NewExprExpr added in v0.50.0

func NewExprExpr(scanner parser.Scanner, expr Expr) ExprExpr

NewExprExpr returns a new ExprExpr from pairs.

func (ExprExpr) Source added in v0.50.0

func (e ExprExpr) Source() parser.Scanner

type ExprPattern added in v0.24.0

type ExprPattern struct {
	Expr Expr
}

func NewExprPattern added in v0.24.0

func NewExprPattern(expr Expr) ExprPattern

func (ExprPattern) Bind added in v0.24.0

func (p ExprPattern) Bind(scope Scope, value Value) (Scope, error)

func (ExprPattern) Bindings added in v0.71.0

func (p ExprPattern) Bindings() []string

func (ExprPattern) String added in v0.24.0

func (p ExprPattern) String() string

type ExprScanner

type ExprScanner struct {
	Src parser.Scanner
}

func (ExprScanner) Source

func (e ExprScanner) Source() parser.Scanner

Source returns a scanner locating the expression's source code.

type ExprsPattern added in v0.3.0

type ExprsPattern struct {
	// contains filtered or unexported fields
}

func NewExprsPattern added in v0.3.0

func NewExprsPattern(exprs ...Expr) ExprsPattern

func (ExprsPattern) Bind added in v0.3.0

func (p ExprsPattern) Bind(scope Scope, value Value) (Scope, error)

func (ExprsPattern) Bindings added in v0.71.0

func (p ExprsPattern) Bindings() []string

func (ExprsPattern) String added in v0.3.0

func (p ExprsPattern) String() string

type ExtraElementPattern added in v0.3.0

type ExtraElementPattern struct {
	// contains filtered or unexported fields
}

func NewExtraElementPattern added in v0.3.0

func NewExtraElementPattern(ident string) ExtraElementPattern

func (ExtraElementPattern) Bind added in v0.3.0

func (p ExtraElementPattern) Bind(scope Scope, value Value) (Scope, error)

func (ExtraElementPattern) Bindings added in v0.71.0

func (p ExtraElementPattern) Bindings() []string

func (ExtraElementPattern) String added in v0.3.0

func (p ExtraElementPattern) String() string

type FallbackPattern added in v0.84.0

type FallbackPattern struct {
	// contains filtered or unexported fields
}

func NewFallbackPattern added in v0.84.0

func NewFallbackPattern(pattern Pattern, fallback Expr) FallbackPattern

func (FallbackPattern) Bind added in v0.84.0

func (p FallbackPattern) Bind(local Scope, value Value) (Scope, error)

func (FallbackPattern) String added in v0.84.0

func (p FallbackPattern) String() string

type FuncMatcher

type FuncMatcher struct {
	// contains filtered or unexported fields
}

func MatchFunc

func MatchFunc(tuples [][2]Matcher, rest Matcher) FuncMatcher

func (FuncMatcher) Match

func (m FuncMatcher) Match(v Value) bool

type Function

type Function struct {
	ExprScanner
	// contains filtered or unexported fields
}

Function represents a binary relation uniquely mapping inputs to outputs.

func ExprAsFunction

func ExprAsFunction(expr Expr) *Function

ExprAsFunction returns a function for an expr. If the expr is already a function, returns expr. Otherwise, returns expr wrapper in a function with arg '.'.

func (*Function) Arg

func (f *Function) Arg() string

Arg returns a function's formal argument.

func (*Function) Body

func (f *Function) Body() Expr

Body returns a function's body.

func (*Function) Equal

func (f *Function) Equal(i interface{}) bool

Equal tests two Values for equality. Any other type returns false.

func (*Function) EqualFunction

func (f *Function) EqualFunction(g *Function) bool

Equal tests two Values for equality. Any other type returns false.

func (*Function) Eval

func (f *Function) Eval(local Scope) (Value, error)

Eval returns the Value

func (*Function) Hash

func (f *Function) Hash(seed uintptr) uintptr

Hash computes a hash for a Function.

func (*Function) String

func (f *Function) String() string

String returns a string representation of the expression.

type GenericSet

type GenericSet struct {
	// contains filtered or unexported fields
}

GenericSet is a set of Values.

func (GenericSet) Any

func (s GenericSet) Any() Value

Any return any value from the set.

func (GenericSet) ArrayEnumerator

func (s GenericSet) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (GenericSet) CallAll added in v0.3.0

func (s GenericSet) CallAll(arg Value) (Set, error)

func (GenericSet) Count

func (s GenericSet) Count() int

Count returns the number of elements in the genericSet.

func (GenericSet) Enumerator

func (s GenericSet) Enumerator() ValueEnumerator

Enumerator returns an enumerator over the Values in the genericSet.

func (GenericSet) Equal

func (s GenericSet) Equal(v interface{}) bool

Equal tests two Sets for equality. Any other type returns false.

func (GenericSet) Eval

func (s GenericSet) Eval(local Scope) (Value, error)

Eval returns the set.

func (GenericSet) Export

func (s GenericSet) Export() interface{}

Export exports a genericSet as an array of exported Values.

func (GenericSet) Has

func (s GenericSet) Has(value Value) bool

Has returns true iff the given Value is in the genericSet.

func (GenericSet) Hash

func (s GenericSet) Hash(seed uintptr) uintptr

Hash computes a hash for a genericSet.

func (GenericSet) IsTrue

func (s GenericSet) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (GenericSet) Kind

func (s GenericSet) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (GenericSet) Less

func (s GenericSet) Less(v Value) bool

Less returns true iff v.Kind() < genericSet.Kind() or v is a genericSet and t precedes v in a lexicographical comparison of their sorted values.

func (GenericSet) Map

func (s GenericSet) Map(f func(v Value) Value) Set

Map maps values per f.

func (GenericSet) Negate

func (s GenericSet) Negate() Value

Negate returns {(negateTag): s}.

func (GenericSet) OrderedValues

func (s GenericSet) OrderedValues() []Value

OrderedValues returns Values in a canonical ordering.

func (GenericSet) Source

func (s GenericSet) Source() parser.Scanner

Source returns a scanner locating the GenericSet's source code.

func (GenericSet) String

func (s GenericSet) String() string

String returns a string representation of a genericSet.

func (GenericSet) Where

func (s GenericSet) Where(p func(v Value) (bool, error)) (_ Set, err error)

Where returns a new genericSet with all the Values satisfying predicate p.

func (GenericSet) With

func (s GenericSet) With(value Value) Set

With returns the original genericSet with given value added. Iff the value was already present, the original genericSet is returned.

func (GenericSet) Without

func (s GenericSet) Without(value Value) Set

Without returns the original genericSet without the given value. Iff the value was already absent, the original genericSet is returned.

type GenericTuple

type GenericTuple struct {
	// contains filtered or unexported fields
}

GenericTuple is the default implementation of Tuple.

func (*GenericTuple) Canonical

func (t *GenericTuple) Canonical() Tuple

func (*GenericTuple) Count

func (t *GenericTuple) Count() int

Count returns how many attributes are in the Tuple.

func (*GenericTuple) Enumerator

func (t *GenericTuple) Enumerator() AttrEnumerator

Enumerator returns an enumerator over the Values in the GenericTuple.

func (*GenericTuple) Equal

func (t *GenericTuple) Equal(v interface{}) bool

Equal tests two Tuples for equality. Any other type returns false.

func (*GenericTuple) Eval

func (t *GenericTuple) Eval(local Scope) (Value, error)

Eval returns the tuple.

func (*GenericTuple) Export

func (t *GenericTuple) Export() interface{}

Export exports a Tuple.

func (*GenericTuple) Get

func (t *GenericTuple) Get(name string) (Value, bool)

Get returns the Value associated with a name, and true iff it was found.

func (*GenericTuple) HasName

func (t *GenericTuple) HasName(name string) bool

HasName returns true iff the Tuple has an attribute with the given name.

func (*GenericTuple) Hash

func (t *GenericTuple) Hash(seed uintptr) uintptr

Hash computes a hash for a GenericTuple.

func (*GenericTuple) IsTrue

func (t *GenericTuple) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (*GenericTuple) Kind

func (t *GenericTuple) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (*GenericTuple) Less

func (t *GenericTuple) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (*GenericTuple) Map

func (t *GenericTuple) Map(f func(Value) Value) Tuple

func (*GenericTuple) MustGet

func (t *GenericTuple) MustGet(name string) Value

MustGet returns e.Get(name) or panics if an error occurs.

func (*GenericTuple) Names

func (t *GenericTuple) Names() Names

Names returns the attribute names.

func (*GenericTuple) Negate

func (t *GenericTuple) Negate() Value

Negate returns x if t matches {(negateTag): x} else {(negateTag): t}.

func (*GenericTuple) Project

func (t *GenericTuple) Project(names Names) Tuple

Project returns a tuple with the given names from this tuple, or nil if any name wasn't found.

func (*GenericTuple) Source

func (t *GenericTuple) Source() parser.Scanner

Source returns a scanner locating the GenericTuple's source code.

func (*GenericTuple) String

func (t *GenericTuple) String() string

String returns a string representation of a Tuple.

func (*GenericTuple) With

func (t *GenericTuple) With(name string, value Value) Tuple

With returns a Tuple with all name/Value pairs in t (except the one for the given name, if present) with the addition of the given name/Value pair.

func (*GenericTuple) Without

func (t *GenericTuple) Without(name string) Tuple

Without returns a Tuple with all name/Value pairs in t exception the one of the given name.

type GenericTupleEnumerator

type GenericTupleEnumerator struct {
	// contains filtered or unexported fields
}

GenericTupleEnumerator represents an enumerator over a GenericTuple.

func (*GenericTupleEnumerator) Current

func (e *GenericTupleEnumerator) Current() (string, Value)

Current returns the enumerator's current Value.

func (*GenericTupleEnumerator) MoveNext

func (e *GenericTupleEnumerator) MoveNext() bool

MoveNext moves the enumerator to the next Value.

type IdentExpr

type IdentExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

IdentExpr returns the variable referenced by ident.

func NewDotIdent added in v0.50.0

func NewDotIdent(source parser.Scanner) IdentExpr

func NewIdentExpr

func NewIdentExpr(scanner parser.Scanner, ident string) IdentExpr

NewIdentExpr returns a new identifier.

func (IdentExpr) Eval

func (e IdentExpr) Eval(local Scope) (Value, error)

Eval returns the value from scope corresponding to the ident.

func (IdentExpr) Ident

func (e IdentExpr) Ident() string

Ident returns the ident for the IdentExpr.

func (IdentExpr) String

func (e IdentExpr) String() string

String returns a string representation of the expression.

type IfElseExpr

type IfElseExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

IfElseExpr returns the tuple applied to a function. Deprecated: IfElseExpr will be removed, it should use CondExpr instead.

func (*IfElseExpr) Eval

func (e *IfElseExpr) Eval(local Scope) (Value, error)

Eval returns the ifTrue

func (*IfElseExpr) String

func (e *IfElseExpr) String() string

String returns a string representation of the expression.

type Less

type Less func(a, b Value) bool

type Let

type Let func(Value)

func (Let) Match

func (m Let) Match(v Value) bool

type LiteralExpr added in v0.50.0

type LiteralExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

LiteralExpr represents an expression that yields a Literal.

func NewLiteralExpr added in v0.50.0

func NewLiteralExpr(scanner parser.Scanner, literal Value) LiteralExpr

NewLiteralExpr returns a new LiteralExpr from pairs.

func (LiteralExpr) Eval added in v0.50.0

func (e LiteralExpr) Eval(_ Scope) (Value, error)

Eval returns the subject

func (LiteralExpr) Literal added in v0.50.0

func (e LiteralExpr) Literal() Value

func (LiteralExpr) String added in v0.50.0

func (e LiteralExpr) String() string

String returns a string representation of the expression.

type LiteralMatcher

type LiteralMatcher struct {
	// contains filtered or unexported fields
}

func Lit

func Lit(value Value) LiteralMatcher

func (LiteralMatcher) Match

func (m LiteralMatcher) Match(v Value) bool

type MatchAll

type MatchAll []Matcher

func (MatchAll) Match

func (m MatchAll) Match(v Value) bool

type MatchFirst

type MatchFirst []Matcher

func (MatchFirst) Match

func (m MatchFirst) Match(v Value) bool

type MatchInt

type MatchInt func(i int)

func (MatchInt) Match

func (m MatchInt) Match(v Value) bool

type MatchNum

type MatchNum func(n Number)

func (MatchNum) Match

func (m MatchNum) Match(v Value) bool

type Matcher

type Matcher interface {
	Match(Value) bool
}

type MissingAttrError added in v0.3.0

type MissingAttrError struct {
	// contains filtered or unexported fields
}

func (MissingAttrError) Error added in v0.3.0

func (m MissingAttrError) Error() string

type Names

type Names frozen.Set

Names represents a set of names.

func CombineNames

func CombineNames(a, b Tuple, op CombineOp) Names

CombineNames returns names from a and b according to the given mask.

func NewNames

func NewNames(names ...string) Names

NewNames returns a new set of names with the given names.

func RelationAttrs

func RelationAttrs(a Set) (Names, bool)

RelationAttrs returns the set of names for a relation type, or false if the set isn't a regular relation.

func (Names) Any

func (n Names) Any() string

Any returns an arbitrary element from `n`.

func (Names) Count

func (n Names) Count() int

Count returns the number of names in a set of names.

func (Names) Enumerator

func (n Names) Enumerator() *NamesEnumerator

Enumerator returns an enumerator over a set of names.

func (Names) Equal

func (n Names) Equal(i interface{}) bool

Equal returns true iff the given sets of names are equal.

func (Names) Has

func (n Names) Has(name string) bool

Has returns true iff the given name is in the set of names.

func (Names) Hash

func (n Names) Hash(seed uint32) uint32

Hash computes a hash value for the set of names.

func (Names) Intersect

func (n Names) Intersect(o Names) Names

Intersect returns names in both sets.

func (Names) IsSubsetOf

func (n Names) IsSubsetOf(o Names) bool

IsSubsetOf returns true if `n“ is a subset of `o`.

func (Names) IsTrue

func (n Names) IsTrue() bool

Bool returns true iff there are names in the set.

func (Names) Minus

func (n Names) Minus(o Names) Names

Minus returns names in one set not found in the other.

func (Names) Names

func (n Names) Names() []string

Names returns a slice of the names in the set.

func (Names) OrderedNames

func (n Names) OrderedNames() []string

Names returns a sorted slice of the names in the set.

func (Names) String

func (n Names) String() string

String returns a string representation of the set of names.

func (Names) TheOne

func (n Names) TheOne() string

TheOne return the single name in the set; panics otherwise.

func (Names) ToSlice

func (n Names) ToSlice() []string

ToSlice returns a slice of the names in the set.

func (Names) With

func (n Names) With(name string) Names

With returns a set with all the input names and the given name.

func (Names) Without

func (n Names) Without(name string) Names

Without returns a set with all the input names, excluding the given name.

type NamesEnumerator

type NamesEnumerator struct {
	// contains filtered or unexported fields
}

NamesEnumerator represents an enumerator over a set of names.

func (*NamesEnumerator) Current

func (e *NamesEnumerator) Current() string

Current returns the enumerator's current Value.

func (*NamesEnumerator) MoveNext

func (e *NamesEnumerator) MoveNext() bool

MoveNext moves the enumerator to the next Value.

type NativeFunction

type NativeFunction struct {
	// contains filtered or unexported fields
}

NativeFunction represents a binary relation uniquely mapping inputs to outputs.

func (*NativeFunction) ArrayEnumerator added in v0.3.0

func (*NativeFunction) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (*NativeFunction) CallAll added in v0.3.0

func (f *NativeFunction) CallAll(arg Value) (Set, error)

Call calls the NativeFunction with the given parameter.

func (*NativeFunction) Count added in v0.3.0

func (*NativeFunction) Count() int

func (*NativeFunction) Enumerator added in v0.3.0

func (*NativeFunction) Enumerator() ValueEnumerator

func (*NativeFunction) Equal

func (f *NativeFunction) Equal(i interface{}) bool

Equal tests two Values for equality. Any other type returns false.

func (*NativeFunction) Eval

func (f *NativeFunction) Eval(local Scope) (Value, error)

Eval returns the Value

func (*NativeFunction) Export

func (f *NativeFunction) Export() interface{}

Export exports a NativeFunction.

func (*NativeFunction) Has added in v0.3.0

func (*NativeFunction) Has(Value) bool

func (*NativeFunction) Hash

func (f *NativeFunction) Hash(seed uintptr) uintptr

Hash computes a hash for a NativeFunction.

func (*NativeFunction) IsTrue

func (f *NativeFunction) IsTrue() bool

Bool always returns true.

func (*NativeFunction) Kind

func (f *NativeFunction) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (*NativeFunction) Less

func (f *NativeFunction) Less(g Value) bool

Less returns true iff g is not a number or f.number < g.number.

func (*NativeFunction) Map added in v0.3.0

func (*NativeFunction) Map(func(Value) Value) Set

func (*NativeFunction) Name

func (f *NativeFunction) Name() string

Name returns a native function's name.

func (*NativeFunction) Negate

func (f *NativeFunction) Negate() Value

Negate returns {(negateTag): f}.

func (*NativeFunction) Source

func (f *NativeFunction) Source() parser.Scanner

Source returns an empty scanner since NativeFunction doesn't have associated source code.

func (*NativeFunction) String

func (f *NativeFunction) String() string

String returns a string representation of the expression.

func (*NativeFunction) Where added in v0.3.0

func (*NativeFunction) Where(p func(v Value) (bool, error)) (Set, error)

func (*NativeFunction) With added in v0.3.0

func (*NativeFunction) With(Value) Set

func (*NativeFunction) Without added in v0.3.0

func (*NativeFunction) Without(Value) Set

type NestExpr

type NestExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

NestExpr returns the relation with names grouped into a nested relation.

func (*NestExpr) Eval

func (e *NestExpr) Eval(local Scope) (Value, error)

Eval returns e.lhs with e.attrs grouped under e.attr.

func (*NestExpr) String

func (e *NestExpr) String() string

String returns a string representation of the expression.

type NoReturnError added in v0.3.0

type NoReturnError struct {
	// contains filtered or unexported fields
}

func (NoReturnError) Error added in v0.3.0

func (n NoReturnError) Error() string

type Number

type Number float64

Number is a number.

func NewNumber

func NewNumber(n float64) Number

NewNumber returns a Number for the given number.

func (Number) Equal

func (n Number) Equal(v interface{}) bool

Equal tests two Values for equality. Any other type returns false.

func (Number) Eval

func (n Number) Eval(_ Scope) (Value, error)

Eval returns the number.

func (Number) Export

func (n Number) Export() interface{}

Export exports a Number.

func (Number) Float64

func (n Number) Float64() float64

Float64 returns the value of the number.

func (Number) Hash

func (n Number) Hash(seed uintptr) uintptr

Hash computes a hash for a Number.

func (Number) Int

func (n Number) Int() (int, bool)

func (Number) IsTrue

func (n Number) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (Number) Kind

func (n Number) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (Number) Less

func (n Number) Less(v Value) bool

Less returns true iff v is not a number or n < v.

func (Number) Negate

func (n Number) Negate() Value

Negate returns -n.

func (Number) Source

func (n Number) Source() parser.Scanner

Source returns a scanner locating the Number's source code.

func (Number) String

func (n Number) String() string

String returns a string representation of a Number.

type OffsetExpr

type OffsetExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

OffsetExpr is an expression which offsets the provided array by the provided offset

func (*OffsetExpr) Eval

func (o *OffsetExpr) Eval(local Scope) (_ Value, err error)

func (*OffsetExpr) String

func (o *OffsetExpr) String() string

type OffsetValueEnumerator

type OffsetValueEnumerator interface {
	ValueEnumerator
	Offset() int
}

type OrExpr

type OrExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

func (OrExpr) Eval

func (e OrExpr) Eval(local Scope) (Value, error)

func (OrExpr) String

func (e OrExpr) String() string

type Pair

type Pair struct {
	// contains filtered or unexported fields
}

Pair represents a pair of values.

type Pattern

type Pattern interface {
	// Require a String() method.
	fmt.Stringer

	// Bind binds pattern with value and add the binding pair to scope
	Bind(scope Scope, value Value) (Scope, error)

	// Bindings returns all the names a pattern expects to bind
	Bindings() []string
}

Pattern can be inside an Expr, Expr can be a Pattern.

type PatternExprPair added in v0.17.0

type PatternExprPair struct {
	// contains filtered or unexported fields
}

PatternExprPair a Pattern/Expr pair

func NewPatternExprPair added in v0.17.0

func NewPatternExprPair(pattern Pattern, expr Expr) PatternExprPair

NewPatternExprPair returns a new PatternExprPair.

func (PatternExprPair) Bind added in v0.17.0

func (pt PatternExprPair) Bind(local Scope, value Value) (Scope, error)

func (PatternExprPair) Eval added in v0.17.0

func (pt PatternExprPair) Eval(local Scope) (Value, error)

func (PatternExprPair) String added in v0.17.0

func (pt PatternExprPair) String() string

String returns a string representation of a PatternPair.

type RecursionExpr added in v0.3.0

type RecursionExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

func (RecursionExpr) Eval added in v0.3.0

func (r RecursionExpr) Eval(local Scope) (Value, error)

func (RecursionExpr) String added in v0.3.0

func (r RecursionExpr) String() string

type ReduceExpr

type ReduceExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

ReduceExpr represents a range of operators.

func (*ReduceExpr) Eval

func (e *ReduceExpr) Eval(local Scope) (_ Value, err error)

Eval returns the subject

func (*ReduceExpr) String

func (e *ReduceExpr) String() string

String returns a string representation of the expression.

type Relation

type Relation Set

Relation is a Set that only contains Tuples, all of which map the same keys.

type SafeTailCallback added in v0.3.0

type SafeTailCallback func(Value, Scope) (Value, error)

type SafeTailExpr added in v0.3.0

type SafeTailExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

func (*SafeTailExpr) Eval added in v0.3.0

func (s *SafeTailExpr) Eval(local Scope) (value Value, err error)

func (*SafeTailExpr) String added in v0.3.0

func (s *SafeTailExpr) String() string

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope represents an expression scope.

var EmptyScope Scope

EmptyScope is the scope with no variables.

func (Scope) Count

func (s Scope) Count() int

Count returns the number of variables in this Scope.

func (Scope) Enumerator

func (s Scope) Enumerator() *ScopeEnumerator

Enumerator returns an enumerator over the Values in the Scope.

func (Scope) Eval

func (s Scope) Eval(local Scope) (Value, error)

Eval evaluates an expression in a given symbol environment.

func (Scope) Get

func (s Scope) Get(name string) (Expr, bool)

Get returns the Expr for the given name or nil.

func (Scope) MatchedUpdate

func (s Scope) MatchedUpdate(t Scope) (Scope, error)

MatchedUpdate merges s and t. New keys are added as Update, but existing keys fail unless the new value equals the existing value

func (Scope) MatchedWith

func (s Scope) MatchedWith(name string, expr Expr) (Scope, error)

MatchedWith returns a new scope. New keys are added as With, but existing keys fail unless the new value equals the existing value

func (Scope) MustGet

func (s Scope) MustGet(name string) Expr

MustGet returns the Expr for the given name or panics if not found.

func (Scope) Names

func (s Scope) Names() []string

Names returns the attribute names as a slice.

func (Scope) OrderedNames

func (s Scope) OrderedNames() []string

OrderedNames returns the names of this tuple in sorted order.

func (Scope) Project

func (s Scope) Project(names Names) (Scope, error)

Project returns a new scope with just names from the input scope.

func (Scope) String

func (s Scope) String() string

func (Scope) Update

func (s Scope) Update(t Scope) Scope

s.Update(t) merges s and t, choosing t's binding in the event of a name clash. It's like calling s.With(t0).With(t1).With(t2)... for each element of t

func (Scope) With

func (s Scope) With(name string, expr Expr) Scope

With returns a new scope with all the old bindings and a new or replacement binding for the given name to the given Expr.

func (Scope) Without

func (s Scope) Without(name ...string) Scope

Without returns a new scope with with all the old bindings except the ones that correspond to the provided names.

type ScopeEnumerator

type ScopeEnumerator struct {
	// contains filtered or unexported fields
}

ScopeEnumerator represents an enumerator over a Scope.

func (ScopeEnumerator) Current

func (e ScopeEnumerator) Current() (string, Expr)

Current returns the enumerator's current Value.

func (ScopeEnumerator) MoveNext

func (e ScopeEnumerator) MoveNext() bool

MoveNext moves the enumerator to the next Value.

type SeqArrowExpr added in v0.36.0

type SeqArrowExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

SeqArrowExpr returns the tuple applied to a function.

func (*SeqArrowExpr) Eval added in v0.36.0

func (e *SeqArrowExpr) Eval(local Scope) (_ Value, err error)

Eval returns the lhs

func (*SeqArrowExpr) String added in v0.36.0

func (e *SeqArrowExpr) String() string

String returns a string representation of the expression.

type Set

type Set interface {
	Value

	// Access
	Count() int
	Has(Value) bool
	Enumerator() ValueEnumerator

	// Transform
	With(Value) Set
	Without(Value) Set
	Map(func(Value) Value) Set
	Where(func(Value) (bool, error)) (Set, error)
	CallAll(Value) (Set, error)

	ArrayEnumerator() (OffsetValueEnumerator, bool)
}

Set represents a Set of Values.

func CanonicalSet

func CanonicalSet(s Set) Set

func Concatenate

func Concatenate(a, b Set) (Set, error)

Concatenate is equivalent to a <&> (b => . + {.@ + a count}). Naturally, this assumes that every element in b is a tuple with at least an '@' attribute, which is numeric.

E.g., [1, 2] + [3] = [1, 2, 3]; "hell" + "o" = "hello"

func Difference

func Difference(a, b Set) Set

Difference returns every Value from the first Set that is not in the second.

func GenericJoin

func GenericJoin(
	a, b Set,
	getKey func(value Value) Value,
	join func(key Value, a, b Set) Set,
) Set

GenericJoin joins two sets using a key and a joiner

func Intersect

func Intersect(a, b Set) Set

Intersect returns every Value from a that is also in b.

func Join

func Join(a, b Set) Set

Join returns the relation join of a and b. Defn: Join(a{x…,y…}, b{y…,z…}) = ∀{x…,y…,z…}: {x…,y…} ∈ a ∧ {y…,z…} ∈ b

for mutually disjoint x…, y…, z…

func NConcatenate

func NConcatenate(a Set, bs ...Set) (Set, error)

func NIntersect

func NIntersect(a Set, bs ...Set) Set

NIntersect returns every Value from a that is also in all bs.

func NUnion

func NUnion(sets ...Set) Set

func Nest

func Nest(a Set, attrs Names, attr string) Set

Nest groups the given attributes into nested relations.

func NewArray

func NewArray(values ...Value) Set

NewArray constructs an array as a relation.

func NewBool

func NewBool(b bool) Set

NewBool constructs a bool as a relation.

func NewBytes

func NewBytes(b []byte) Set

NewBytes constructs an array as a relation.

func NewDict

func NewDict(allowDupKeys bool, entries ...DictEntryTuple) Set

NewDict constructs a dict as a relation {|@, @value|...}.

func NewOffsetArray

func NewOffsetArray(offset int, values ...Value) Set

NewArray constructs an array as a relation.

func NewOffsetBytes

func NewOffsetBytes(b []byte, offset int) Set

NewBytes constructs an array as a relation.

func NewOffsetString

func NewOffsetString(s []rune, offset int) Set

NewString constructs an array as a relation.

func NewSet

func NewSet(values ...Value) Set

NewSet constructs a genericSet from a set of Values.

func NewSetFrom

func NewSetFrom(intfs ...interface{}) (Set, error)

NewSetFrom constructs a genericSet from interfaces.

func NewString

func NewString(s []rune) Set

NewString constructs an array as a relation.

func PowerSet

func PowerSet(s Set) Set

PowerSet computes the power set of a set.

func Rank added in v0.3.0

func Rank(s Set, rankerf func(v Tuple) (Tuple, error)) (Set, error)

Rank ...

func Reduce

func Reduce(
	a Set,
	getKey func(value Value) Value,
	reduce func(key Value, tuples Set) Set,
) Set

Reduce reduces a set using the given key and reducer functions.

func SymmetricDifference

func SymmetricDifference(a, b Set) Set

SymmetricDifference returns Values in either Set, but not in both.

func Union

func Union(a, b Set) Set

Union returns every Values that is in either input Set or both.

func Unnest

func Unnest(a Set, attr string) Set

Unnest unpacks the attributes of a nested relation into the outer relation.

type SetExpr

type SetExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

SetExpr returns the tuple or set with a single field replaced by an expression.

func (*SetExpr) Eval

func (e *SetExpr) Eval(local Scope) (Value, error)

Eval returns the subject

func (*SetExpr) String

func (e *SetExpr) String() string

String returns a string representation of the expression.

type SetMatcher

type SetMatcher struct {
	// contains filtered or unexported fields
}

func NewSetMatcher

func NewSetMatcher(elem Matcher) SetMatcher

func (SetMatcher) Match

func (m SetMatcher) Match(v Value) bool

type SetPattern added in v0.24.0

type SetPattern struct {
	// contains filtered or unexported fields
}

func NewSetPattern added in v0.24.0

func NewSetPattern(patterns ...Pattern) SetPattern

func (SetPattern) Bind added in v0.24.0

func (p SetPattern) Bind(local Scope, value Value) (Scope, error)

func (SetPattern) Bindings added in v0.71.0

func (p SetPattern) Bindings() []string

func (SetPattern) String added in v0.24.0

func (p SetPattern) String() string

type String

type String struct {
	// contains filtered or unexported fields
}

String is a set of Values.

func AsString

func AsString(s Set) (String, bool)

func (String) ArrayEnumerator

func (s String) ArrayEnumerator() (OffsetValueEnumerator, bool)

func (String) CallAll added in v0.3.0

func (s String) CallAll(arg Value) (Set, error)

func (String) Count

func (s String) Count() int

Count returns the number of elements in the String.

func (String) Enumerator

func (s String) Enumerator() ValueEnumerator

Enumerator returns an enumerator over the Values in the String.

func (String) Equal

func (s String) Equal(v interface{}) bool

Equal tests two Sets for equality. Any other type returns false.

func (String) Eval

func (s String) Eval(_ Scope) (Value, error)

Eval returns the string.

func (String) Export

func (s String) Export() interface{}

Export exports a String as a string.

func (String) Has

func (s String) Has(value Value) bool

Has returns true iff the given Value is in the String.

func (String) Hash

func (s String) Hash(seed uintptr) uintptr

Hash computes a hash for a String.

func (String) IsTrue

func (s String) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (String) Kind

func (s String) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (String) Less

func (s String) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (String) Map

func (s String) Map(f func(v Value) Value) Set

Map maps values per f.

func (String) Negate

func (s String) Negate() Value

Negate returns {(negateTag): s}.

func (String) Source

func (s String) Source() parser.Scanner

Source returns a scanner locating the String's source code.

func (String) String

func (s String) String() string

String returns a string representation of a String.

func (String) Where

func (s String) Where(p func(v Value) (bool, error)) (Set, error)

Where returns a new String with all the Values satisfying predicate p.

func (String) With

func (s String) With(value Value) Set

With returns the original String with given value added. Iff the value was already present, the original String is returned.

func (String) Without

func (s String) Without(value Value) Set

Without returns the original String without the given value. Iff the value was already absent, the original String is returned.

type StringCharTuple

type StringCharTuple struct {
	// contains filtered or unexported fields
}

StringCharTuple represents a tuple of the form (@: at, @char: char).

func NewStringCharTuple

func NewStringCharTuple(at int, char rune) StringCharTuple

NewStringCharTuple constructs a CharTuple.

func (StringCharTuple) Count

func (t StringCharTuple) Count() int

Count returns how many attributes are in the Tuple.

func (StringCharTuple) Enumerator

func (t StringCharTuple) Enumerator() AttrEnumerator

Enumerator returns an enumerator over the Values in the CharTuple.

func (StringCharTuple) Equal

func (t StringCharTuple) Equal(v interface{}) bool

Equal tests two Tuples for equality. Any other type returns false.

func (StringCharTuple) Eval

func (t StringCharTuple) Eval(local Scope) (Value, error)

Eval returns the tuple.

func (StringCharTuple) Export

func (t StringCharTuple) Export() interface{}

Export exports a Tuple.

func (StringCharTuple) Get

func (t StringCharTuple) Get(name string) (Value, bool)

Get returns the Value associated with a name, and true iff it was found.

func (StringCharTuple) HasName

func (t StringCharTuple) HasName(name string) bool

HasName returns true iff the Tuple has an attribute with the given name.

func (StringCharTuple) Hash

func (t StringCharTuple) Hash(seed uintptr) uintptr

Hash computes a hash for a CharTuple.

func (StringCharTuple) IsTrue

func (t StringCharTuple) IsTrue() bool

Bool returns true iff the tuple has attributes.

func (StringCharTuple) Kind

func (t StringCharTuple) Kind() int

Kind returns a number that is unique for each major kind of Value.

func (StringCharTuple) Less

func (t StringCharTuple) Less(v Value) bool

Less returns true iff v is not a number or tuple, or v is a tuple and t precedes v in a lexicographical comparison of their name/value pairs.

func (StringCharTuple) Map

func (t StringCharTuple) Map(f func(Value) Value) Tuple

func (StringCharTuple) MustGet

func (t StringCharTuple) MustGet(name string) Value

MustGet returns e.Get(name) or panics if an error occurs.

func (StringCharTuple) Names

func (t StringCharTuple) Names() Names

Names returns the attribute names.

func (StringCharTuple) Negate

func (t StringCharTuple) Negate() Value

func (StringCharTuple) Project

func (t StringCharTuple) Project(names Names) Tuple

Project returns a tuple with the given names from this tuple, or nil if any name wasn't found.

func (StringCharTuple) Source

func (t StringCharTuple) Source() parser.Scanner

Source returns a scanner locating the StringCharTuple's source code.

func (StringCharTuple) String

func (t StringCharTuple) String() string

String returns a string representation of a Tuple.

func (StringCharTuple) With

func (t StringCharTuple) With(name string, value Value) Tuple

With returns a Tuple with all name/Value pairs in t (except the one for the given name, if present) with the addition of the given name/Value pair.

func (StringCharTuple) Without

func (t StringCharTuple) Without(name string) Tuple

Without returns a Tuple with all name/Value pairs in t exception the one of the given name.

type StringCharTupleExpr

type StringCharTupleExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

StringCharTupleExpr represents an expr that evaluates to a StringCharTuple.

func NewStringCharTupleExpr

func NewStringCharTupleExpr(scanner parser.Scanner, at, char Expr) StringCharTupleExpr

NewStringCharTupleExpr returns a new dictEntryTupleExpr.

func (StringCharTupleExpr) Eval

func (e StringCharTupleExpr) Eval(local Scope) (_ Value, err error)

Eval returns the subject

func (StringCharTupleExpr) String

func (e StringCharTupleExpr) String() string

String returns a string representation of the expression.

type Tuple

type Tuple interface {
	Value

	// Access
	Count() int
	Get(name string) (Value, bool)
	MustGet(name string) Value
	HasName(name string) bool
	Names() Names
	Enumerator() AttrEnumerator

	// Transform
	With(name string, value Value) Tuple
	Without(name string) Tuple
	Map(func(Value) Value) Tuple
	Project(names Names) Tuple
}

Tuple is a mapping from names to Values.

var (
	// EmptyTuple is the tuple with no attributes.
	EmptyTuple Tuple = &GenericTuple{}
)

func ASTBranchToValue

func ASTBranchToValue(b ast.Branch) Tuple

func Merge

func Merge(a, b Tuple) Tuple

Merge returns the merger of a and b, if possible or nil otherwise. Success requires that common names map to equal values.

func MergeLeftToRight

func MergeLeftToRight(t Tuple, ts ...Tuple) Tuple

MergeLeftToRight returns the merger of a and b. Key from tuples to the right override tuples to the left.

func NewTuple

func NewTuple(attrs ...Attr) Tuple

NewTuple constructs a Tuple from attrs. Passes each Val to NewValue().

func NewTupleFromMap

func NewTupleFromMap(m map[string]interface{}) (Tuple, error)

NewTupleFromMap constructs a Tuple from a map of strings to Go values.

func NewXML

func NewXML(tag []rune, attrs []Attr, children ...Value) Tuple

NewXML constructs an XML Tuple from the given data

type TupleBuilder

type TupleBuilder frozen.MapBuilder

func (*TupleBuilder) Finish

func (b *TupleBuilder) Finish() Tuple

func (*TupleBuilder) Put

func (b *TupleBuilder) Put(name string, value Value)

type TupleExpr

type TupleExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

TupleExpr returns a set from a slice of Exprs.

func (*TupleExpr) Eval

func (e *TupleExpr) Eval(local Scope) (Value, error)

Eval returns the subject

func (*TupleExpr) String

func (e *TupleExpr) String() string

String returns a string representation of the expression.

type TupleMapExpr

type TupleMapExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

TupleMapExpr returns the tuple applied to a function.

func (*TupleMapExpr) Eval

func (e *TupleMapExpr) Eval(local Scope) (_ Value, err error)

Eval returns the lhs

func (*TupleMapExpr) String

func (e *TupleMapExpr) String() string

String returns a string representation of the expression.

type TupleMatcher

type TupleMatcher struct {
	// contains filtered or unexported fields
}

func NewTupleMatcher

func NewTupleMatcher(attrs map[string]Matcher, rest Matcher) TupleMatcher

func (TupleMatcher) Match

func (m TupleMatcher) Match(v Value) bool

type TuplePattern

type TuplePattern struct {
	// contains filtered or unexported fields
}

func NewTuplePattern

func NewTuplePattern(attrs ...TuplePatternAttr) TuplePattern

func (TuplePattern) Bind

func (p TuplePattern) Bind(local Scope, value Value) (Scope, error)

func (TuplePattern) Bindings added in v0.71.0

func (p TuplePattern) Bindings() []string

func (TuplePattern) String

func (p TuplePattern) String() string

type TuplePatternAttr added in v0.3.0

type TuplePatternAttr struct {
	// contains filtered or unexported fields
}

func NewTuplePatternAttr added in v0.3.0

func NewTuplePatternAttr(name string, pattern FallbackPattern) TuplePatternAttr

func (*TuplePatternAttr) IsWildcard added in v0.3.0

func (a *TuplePatternAttr) IsWildcard() bool

func (TuplePatternAttr) String added in v0.3.0

func (a TuplePatternAttr) String() string

type UnaryExpr

type UnaryExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

UnaryExpr represents a range of operators.

func (*UnaryExpr) Eval

func (e *UnaryExpr) Eval(local Scope) (Value, error)

Eval returns the subject

func (*UnaryExpr) String

func (e *UnaryExpr) String() string

String returns a string representation of the expression.

type UnnestExpr

type UnnestExpr struct {
	ExprScanner
	// contains filtered or unexported fields
}

UnnestExpr returns the relation with names grouped into a nested relation.

func (*UnnestExpr) AttrToUnnest

func (e *UnnestExpr) AttrToUnnest() string

AttrToUnnest returns the attr name to unnest.

func (*UnnestExpr) Eval

func (e *UnnestExpr) Eval(local Scope) (Value, error)

Eval returns e.lhs with e.attrs grouped under e.attr.

func (*UnnestExpr) String

func (e *UnnestExpr) String() string

String returns a string representation of the expression.

type Value

type Value interface {
	frozen.Key

	// Values are Exprs.
	Expr

	// Kind returns a number that is unique for each major kind of Value.
	Kind() int

	// Bool returns true iff the Value is non-zero or non-empty.
	IsTrue() bool

	// Less return true iff the Value is less than v. Number < Tuple < Set.
	Less(v Value) bool

	// Negate returns the negation of the Value.
	// - For numbers, this is the arithmetic negation of the value.
	// - For the tuple {(negateTag): x}, it returns x.
	// - For all other values, x, it returns {(negateTag): x}.
	Negate() Value

	// Export converts the Value to a natural Go value.
	Export() interface{}
}

Value represents any arr.ai value.

func ASTLeafToValue

func ASTLeafToValue(l ast.Leaf) Value

func ASTNodeToValue

func ASTNodeToValue(n ast.Node) Value

func Call

func Call(a, b Value, _ Scope) (Value, error)

func EvalExpr

func EvalExpr(expr Expr, local Scope) (_ Value, err error)

func MustCallAll added in v0.53.0

func MustCallAll(s Set, v Value) Value

func NewExprClosure

func NewExprClosure(scope Scope, e Expr) Value

NewExprClosure returns a new ExprClosure.

func NewNativeFunction

func NewNativeFunction(name string, fn func(Value) (Value, error)) Value

NewNativeFunction returns a new function.

func NewNativeLambda

func NewNativeLambda(fn func(Value) (Value, error)) Value

NewNativeLambda returns a nameless function.

func NewValue

func NewValue(v interface{}) (Value, error)

NewValue constructs a new value from a Go value.

func OrderBy

func OrderBy(s Set, key func(v Value) (Value, error), less func(a, b Value) bool) ([]Value, error)

OrderBy returns a slice with the sets Values sorted by the given key.

func SetAny added in v0.3.0

func SetAny(s Set) Value

func SetCall added in v0.3.0

func SetCall(s Set, arg Value) (Value, error)

func UnmarshalFromJSON

func UnmarshalFromJSON(data []byte) (Value, error)

UnmarshalFromJSON unmarshals the given value from JSON interpreting escaped sets ({"{||}": s}) accordingly.

func ValueEnumeratorToSlice

func ValueEnumeratorToSlice(e ValueEnumerator) []Value

ValueEnumeratorToSlice transcribes its Values in a slice.

type ValueEnumerator

type ValueEnumerator interface {
	MoveNext() bool
	Current() Value
}

ValueEnumerator enumerates Values.

func OrderedValueEnumerator

func OrderedValueEnumerator(e ValueEnumerator, less Less) ValueEnumerator

type ValueList

type ValueList []Value

ValueList represents a []Value for use in sort.Sort().

func (ValueList) Len

func (vl ValueList) Len() int

func (ValueList) Less

func (vl ValueList) Less(i, j int) bool

func (ValueList) Swap

func (vl ValueList) Swap(i, j int)

Jump to

Keyboard shortcuts

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