rel

package
Version: v0.313.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: Apache-2.0 Imports: 28 Imported by: 7

Documentation

Overview

TODO: the context here maybe need to be initialized with proper values like fs

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(EmptySet{})
	False = None
	True  = Set(TrueSet{})
)

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 Joiner added in v0.106.0

func Joiner(
	combine func(common Names, a, b Tuple) Tuple,
	partitionNames func(left, right, common NamesSlice) (leftOut, rightOut NamesSlice),
) func(a, b Set) (Set, error)

Joiner returns a function that computes the relational 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…

The combine function determines how to combine matching tuples from a and b. The partitionName function determines the columns that are to be included in the output based from left and right Relations. The function is only called when both Sets are Relations.

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 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 ValueLess added in v0.291.0

func ValueLess(a, b Value) bool

func ValueTypeAsString added in v0.182.0

func ValueTypeAsString(v Value) string

ValueTypeAsString returns a string that describes the type of the value in a human-readable form.

func WrapContextErr added in v0.143.0

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

WrapContextErr wraps an error in a ContextErr

Types

type AndExpr

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

func (AndExpr) Eval

func (e AndExpr) Eval(ctx context.Context, 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() ValueEnumerator

func (Array) CallAll added in v0.3.0

func (a Array) CallAll(_ context.Context, arg Value, b SetBuilder) 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(ctx context.Context, _ Scope) (Value, error)

Eval returns the string.

func (Array) Export

func (a Array) Export(ctx context.Context) interface{}

Export exports an Array as a slice.

func (Array) Format added in v0.291.0

func (a Array) Format(f fmt.State, verb rune)

String returns a string representation of an Array.

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, error)) (Set, error)

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.

Where value is an ArrayItemTuple, its item is inserted at its at index. If a value is already present at the index, this is an error.

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.

Value is expected to be an ArrayItemTuple; no other values can be present in an array, so any other type will be a no-op. Both the value's at (index) and item must exactly match an element of the array in order to remove it.

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(ctx context.Context, 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(ctx context.Context, local Scope) (Value, error)

Eval returns the tuple.

func (ArrayItemTuple) Export

func (t ArrayItemTuple) Export(ctx context.Context) interface{}

Export exports a Tuple.

func (ArrayItemTuple) Format added in v0.291.0

func (t ArrayItemTuple) Format(f fmt.State, verb rune)

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, error)) (Tuple, error)

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(ctx context.Context, 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(ctx context.Context, local Scope, value Value) (context.Context, 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(ctx context.Context, 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 NativeFnBody) 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.

func NewUintAttr added in v0.280.0

func NewUintAttr(name string, value uint64) Attr

NewIuntAttr return an attr for a uint64 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 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(
	ctx context.Context, 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(ctx context.Context, 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 Bytes

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

Bytes is a set of Values.

func (Bytes) ArrayEnumerator

func (b Bytes) ArrayEnumerator() ValueEnumerator

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(_ context.Context, arg Value, sb SetBuilder) 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 Byteses for equality. Any other type returns false.

func (Bytes) EqualBytes added in v0.238.0

func (b Bytes) EqualBytes(c Bytes) bool

func (Bytes) Eval

func (b Bytes) Eval(ctx context.Context, _ Scope) (Value, error)

Eval returns the string.

func (Bytes) Export

func (b Bytes) Export(_ context.Context) interface{}

Export exports a Bytes as a string.

func (Bytes) Format added in v0.291.0

func (b Bytes) Format(f fmt.State, verb rune)

Format formats a Bytes.

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, error)) (Set, error)

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(ctx context.Context, local Scope) (Value, error)

Eval returns the tuple.

func (BytesByteTuple) Export

func (t BytesByteTuple) Export(_ context.Context) interface{}

Export exports a Tuple.

func (BytesByteTuple) Format added in v0.291.0

func (t BytesByteTuple) Format(f fmt.State, verb rune)

Format formats a BytesByteTuple.

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, error)) (Tuple, error)

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 BytesByteTuple.

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(ctx context.Context, 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() ValueEnumerator

func (Closure) CallAll added in v0.3.0

func (c Closure) CallAll(ctx context.Context, arg Value, b SetBuilder) error

FIXME: context not used properly

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(ctx context.Context, local Scope) (Value, error)

Eval returns the Value

func (Closure) Export

func (c Closure) Export(ctx context.Context) interface{}

Export exports a Closure.

func (Closure) Format added in v0.291.0

func (c Closure) Format(f fmt.State, verb rune)

Format formats the expression.

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(v Value) (Value, error)) (Set, error)

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(ctx context.Context, 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(ctx context.Context, 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) Conditions added in v0.163.0

func (e CondPatternControlVarExpr) Conditions() []PatternExprPair

Conditions returns the cond's conditions.

func (CondPatternControlVarExpr) Control added in v0.163.0

func (e CondPatternControlVarExpr) Control() Expr

Control returns the cond's control expr.

func (CondPatternControlVarExpr) Eval added in v0.3.0

func (e CondPatternControlVarExpr) Eval(ctx context.Context, 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 (e 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

NewContextErr creates a 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

GetScope gets the scope of a ContextErr.

func (ContextErr) GetSource added in v0.59.0

func (c ContextErr) GetSource() parser.Scanner

GetSource gets the source of a ContextErr.

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(ctx context.Context, 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 AsDict added in v0.303.0

func AsDict(v Value) (Dict, bool)

AsDict checks whether a Value is a valid dictionary.

func (Dict) ArrayEnumerator

func (d Dict) ArrayEnumerator() ValueEnumerator

func (Dict) CallAll added in v0.3.0

func (d Dict) CallAll(_ context.Context, arg Value, b SetBuilder) 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(ctx context.Context, local Scope) (Value, error)

func (Dict) Export

func (d Dict) Export(_ context.Context) interface{}

func (Dict) Format added in v0.291.0

func (d Dict) Format(f fmt.State, verb rune)

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(f func(v Value) (Value, error)) (Set, error)

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(ctx context.Context, local Scope) (Value, error)

Eval returns the tuple.

func (DictEntryTuple) Export

func (t DictEntryTuple) Export(ctx context.Context) interface{}

Export exports a Tuple.

func (DictEntryTuple) Format added in v0.291.0

func (t DictEntryTuple) Format(f fmt.State, verb rune)

Format formats a DictEntryTuple.

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, error)) (Tuple, error)

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 DictEntryTuple.

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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, local Scope, value Value) (context.Context, 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(ctx context.Context, 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 DynIdent added in v0.153.0

type DynIdent string

type DynIdentExpr added in v0.153.0

type DynIdentExpr struct {
	IdentExpr
}

func (DynIdentExpr) Eval added in v0.153.0

func (e DynIdentExpr) Eval(ctx context.Context, local Scope) (Value, error)

Eval returns the value from scope corresponding to the ident.

type DynIdentPattern added in v0.153.0

type DynIdentPattern string

func (DynIdentPattern) Bind added in v0.153.0

func (p DynIdentPattern) Bind(ctx context.Context, scope Scope, value Value) (context.Context, Scope, error)

func (DynIdentPattern) Bindings added in v0.153.0

func (p DynIdentPattern) Bindings() []string

func (DynIdentPattern) String added in v0.153.0

func (p DynIdentPattern) String() string

type DynLetExpr added in v0.155.0

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

DynLetExpr implements "let bindings; expr", where bindings must evaluates to a tuple whose attributes are all dynamic names. These names will be bound dynamically for evaluation of expr.

func (*DynLetExpr) Eval added in v0.155.0

func (e *DynLetExpr) Eval(ctx context.Context, local Scope) (Value, error)

Eval evaluates expr with the contents of bindings bound as dynamic variables.

func (*DynLetExpr) String added in v0.155.0

func (e *DynLetExpr) String() string

String returns a string representation of the expression.

type EmptySet added in v0.243.0

type EmptySet struct{}

func (EmptySet) ArrayEnumerator added in v0.243.0

func (e EmptySet) ArrayEnumerator() ValueEnumerator

func (EmptySet) CallAll added in v0.243.0

func (EmptySet) Count added in v0.243.0

func (e EmptySet) Count() int

func (EmptySet) Enumerator added in v0.243.0

func (e EmptySet) Enumerator() ValueEnumerator

func (EmptySet) Equal added in v0.243.0

func (e EmptySet) Equal(i interface{}) bool

func (EmptySet) Eval added in v0.243.0

func (e EmptySet) Eval(ctx context.Context, local Scope) (Value, error)

func (EmptySet) Export added in v0.243.0

func (e EmptySet) Export(context.Context) interface{}

func (EmptySet) Format added in v0.291.0

func (e EmptySet) Format(f fmt.State, verb rune)

func (EmptySet) Has added in v0.243.0

func (e EmptySet) Has(Value) bool

func (EmptySet) Hash added in v0.243.0

func (e EmptySet) Hash(seed uintptr) uintptr

func (EmptySet) IsTrue added in v0.243.0

func (e EmptySet) IsTrue() bool

func (EmptySet) Kind added in v0.243.0

func (e EmptySet) Kind() int

func (EmptySet) Less added in v0.243.0

func (e EmptySet) Less(v Value) bool

func (EmptySet) Map added in v0.243.0

func (e EmptySet) Map(func(Value) (Value, error)) (Set, error)

func (EmptySet) Negate added in v0.243.0

func (e EmptySet) Negate() Value

func (EmptySet) Source added in v0.243.0

func (e EmptySet) Source() parser.Scanner

func (EmptySet) String added in v0.243.0

func (e EmptySet) String() string

func (EmptySet) Where added in v0.243.0

func (e EmptySet) Where(func(Value) (bool, error)) (Set, error)

func (EmptySet) With added in v0.243.0

func (e EmptySet) With(v Value) Set

func (EmptySet) Without added in v0.243.0

func (e EmptySet) Without(Value) Set

type Expr

type Expr interface {
	// All exprs can be serialized to strings with the String() method.
	fmt.Stringer

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

	// Source returns the Scanner that locates the expression in a source file.
	Source() parser.Scanner
}

Expr represents an arr.ai expression.

func NewAddArrowExpr added in v0.91.0

func NewAddArrowExpr(scanner parser.Scanner, lhs, rhs Expr) Expr

NewAddArrowExpr returns a new BinExpr which supports operator `+>`.

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 NewComposeExpr added in v0.106.0

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

NewComposeExpr evaluates a <-> b.

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, error)

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 NewDotIdent added in v0.50.0

func NewDotIdent(source parser.Scanner) Expr

func NewDynLetExpr added in v0.155.0

func NewDynLetExpr(scanner parser.Scanner, bindings, expr Expr) Expr

NewDynLetExpr returns a new DynLetExpr.

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 NewIdentExpr

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

NewIdentExpr returns a new identifier.

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 NewJoinCommonExpr added in v0.106.0

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

NewJoinCommonExpr evaluates a -&- b.

func NewJoinExistsExpr added in v0.106.0

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

NewJoinExistsExpr evaluates a --- b.

func NewJoinExpr

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

NewJoinExpr evaluates a <&> b.

func NewLeftMatchExpr added in v0.106.0

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

NewLeftMatchExpr evaluates a <&- b.

func NewLeftResidueExpr added in v0.106.0

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

NewLeftResidueExpr 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, inverse bool, 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 string, 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 NewRightMatchExpr added in v0.106.0

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

NewRightMatchExpr evaluates a -&> b.

func NewRightResidueExpr added in v0.106.0

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

NewRightResidueExpr evaluates a --> b.

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, error)

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 NewSingleNestExpr added in v0.122.0

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

NewSingleNestExpr returns a new SingleNestExpr.

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 NewTupleProjectExpr added in v0.121.0

func NewTupleProjectExpr(scanner parser.Scanner, base Expr, inverse bool, attrs []string) Expr

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() ValueEnumerator

func (ExprClosure) CallAll added in v0.3.0

func (c ExprClosure) CallAll(_ context.Context, arg Value, b SetBuilder) 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(ctx context.Context, _ Scope) (Value, error)

Eval returns the Value

func (ExprClosure) Export

func (c ExprClosure) Export(ctx context.Context) interface{}

Export exports a ExprClosure.

func (ExprClosure) Format added in v0.291.0

func (c ExprClosure) Format(f fmt.State, verb rune)

Format formats the expression.

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, error)) (Set, error)

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 (ExprPattern) Bind added in v0.24.0

func (p ExprPattern) Bind(ctx context.Context, scope Scope, value Value) (context.Context, 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
}

ExprScanner represents the source location of an Expr.

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(ctx context.Context, scope Scope, value Value) (context.Context, 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(ctx context.Context, scope Scope, value Value) (context.Context, 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(ctx context.Context, local Scope, value Value) (context.Context, Scope, error)

func (FallbackPattern) String added in v0.84.0

func (p FallbackPattern) String() string

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(ctx context.Context, local Scope) (Value, error)

Eval returns the Value

func (*Function) Format added in v0.291.0

func (f *Function) Format(s fmt.State, verb rune)

Format formats the expression.

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() ValueEnumerator

func (GenericSet) CallAll added in v0.3.0

func (s GenericSet) CallAll(_ context.Context, arg Value, b SetBuilder) 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(ctx context.Context, local Scope) (Value, error)

Eval returns the set.

func (GenericSet) Export

func (s GenericSet) Export(ctx context.Context) interface{}

Export exports a genericSet as an array of exported Values.

func (GenericSet) Format added in v0.291.0

func (s GenericSet) Format(f fmt.State, verb rune)

Format formats a genericSet.

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, error)) (Set, error)

Map maps values per f.

func (GenericSet) Negate

func (s GenericSet) Negate() Value

Negate returns {(negateTag): s}.

func (GenericSet) OrderedValues

func (s GenericSet) OrderedValues() ValueEnumerator

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(v 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(ctx context.Context, local Scope) (Value, error)

Eval returns the tuple.

func (*GenericTuple) Export

func (t *GenericTuple) Export(ctx context.Context) interface{}

Export exports a Tuple.

func (*GenericTuple) Format added in v0.291.0

func (t *GenericTuple) Format(f fmt.State, verb rune)

Format formats a GenericTuple.

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, error)) (Tuple, error)

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 (IdentExpr) Eval

func (e IdentExpr) Eval(ctx context.Context, 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 IdentPattern

type IdentPattern string

func (IdentPattern) Bind

func (p IdentPattern) Bind(ctx context.Context, scope Scope, value Value) (context.Context, Scope, error)

func (IdentPattern) Bindings added in v0.71.0

func (p IdentPattern) Bindings() []string

func (IdentPattern) Ident added in v0.153.0

func (p IdentPattern) Ident() string

func (IdentPattern) String

func (p IdentPattern) String() string

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(ctx context.Context, 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

Less defines a comparator that returns true iff a < b.

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(ctx context.Context, _ 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 MatchInt

type MatchInt func(i int)

func (MatchInt) Match

func (m MatchInt) 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, error)

RelationAttrs returns the set of names for a relation type, or an error 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 NamesSlice added in v0.258.0

type NamesSlice []string

func (NamesSlice) EqualNamesSlice added in v0.258.0

func (n NamesSlice) EqualNamesSlice(n2 NamesSlice) bool

func (NamesSlice) EqualTupleAttrs added in v0.258.0

func (n NamesSlice) EqualTupleAttrs(t Tuple) bool

func (NamesSlice) GetSorted added in v0.263.0

func (n NamesSlice) GetSorted() NamesSlice

func (NamesSlice) LessNamesSlice added in v0.258.0

func (n NamesSlice) LessNamesSlice(n2 NamesSlice) bool

func (NamesSlice) String added in v0.258.0

func (n NamesSlice) String() string

type NativeFnBody added in v0.145.0

type NativeFnBody func(context.Context, Value) (Value, error)

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() ValueEnumerator

func (*NativeFunction) CallAll added in v0.3.0

func (f *NativeFunction) CallAll(ctx context.Context, arg Value, b SetBuilder) 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(ctx context.Context, local Scope) (Value, error)

Eval returns the Value

func (*NativeFunction) Export

func (f *NativeFunction) Export(_ context.Context) interface{}

Export exports a NativeFunction.

func (*NativeFunction) Format added in v0.291.0

func (f *NativeFunction) Format(s fmt.State, verb rune)

Format formats the expression.

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, error)) (Set, error)

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(ctx context.Context, 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
}

NoReturnError is an error signififying that there was no return value.

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(ctx context.Context, _ Scope) (Value, error)

Eval returns the number.

func (Number) Export

func (n Number) Export(_ context.Context) interface{}

Export exports a Number.

func (Number) Float64

func (n Number) Float64() float64

Float64 returns the value of the number.

func (Number) Format added in v0.291.0

func (n Number) Format(f fmt.State, verb rune)

String returns a string representation of a 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(ctx context.Context, local Scope) (_ Value, err error)

func (*OffsetExpr) String

func (o *OffsetExpr) String() string

type OrExpr

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

func (OrExpr) Eval

func (e OrExpr) Eval(ctx context.Context, local Scope) (Value, error)

func (OrExpr) String

func (e OrExpr) String() string

type OrderableSet added in v0.267.0

type OrderableSet interface {
	Set
	OrderedValues() ValueEnumerator
}

OrderableSet is a type used to repr GenericSet and UnionSet to avoid duplications.

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(ctx context.Context, scope Scope, value Value) (context.Context, 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.

func NewExprPattern added in v0.24.0

func NewExprPattern(expr Expr) Pattern

func NewIdentPattern

func NewIdentPattern(name string) 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 (p PatternExprPair) Bind(
	ctx context.Context,
	local Scope,
	value Value,
) (context.Context, Scope, error)

Bind implements Pattern.Bind.

func (PatternExprPair) Expr added in v0.163.0

func (p PatternExprPair) Expr() Expr

Expr returns the PatternExprPair's Expr.

func (PatternExprPair) Pattern added in v0.163.0

func (p PatternExprPair) Pattern() Pattern

Pattern returns the PatternExprPair's Pattern.

func (PatternExprPair) String added in v0.17.0

func (p 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(ctx context.Context, 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(ctx context.Context, 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 struct {
	// contains filtered or unexported fields
}

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

func (Relation) ArrayEnumerator added in v0.258.0

func (r Relation) ArrayEnumerator() ValueEnumerator

func (Relation) AttrsName added in v0.258.0

func (r Relation) AttrsName() NamesSlice

func (Relation) CallAll added in v0.258.0

func (r Relation) CallAll(_ context.Context, v Value, sb SetBuilder) error

func (Relation) Count added in v0.258.0

func (r Relation) Count() int

func (Relation) Enumerator added in v0.258.0

func (r Relation) Enumerator() ValueEnumerator

func (Relation) Equal added in v0.258.0

func (r Relation) Equal(i interface{}) bool

func (Relation) EqualRelation added in v0.258.0

func (r Relation) EqualRelation(r2 Relation) bool

func (Relation) Eval added in v0.258.0

func (r Relation) Eval(ctx context.Context, local Scope) (Value, error)

func (Relation) Export added in v0.258.0

func (r Relation) Export(ctx context.Context) interface{}

func (Relation) Format added in v0.291.0

func (r Relation) Format(f fmt.State, verb rune)

func (Relation) Has added in v0.258.0

func (r Relation) Has(v Value) bool

func (Relation) Hash added in v0.258.0

func (r Relation) Hash(seed uintptr) uintptr

func (Relation) IsTrue added in v0.258.0

func (r Relation) IsTrue() bool

func (Relation) Join added in v0.258.0

func (r Relation) Join(r2 Relation, keys, leftOutput, rightOutput NamesSlice) Set

Join joins two relation based on the keys and defined outputs. Only does natural Join.

func (Relation) Kind added in v0.258.0

func (r Relation) Kind() int

func (Relation) Less added in v0.258.0

func (r Relation) Less(v Value) bool

func (Relation) Map added in v0.258.0

func (r Relation) Map(f func(Value) (Value, error)) (Set, error)

func (Relation) Negate added in v0.258.0

func (r Relation) Negate() Value

func (Relation) OrderedValues added in v0.283.0

func (r Relation) OrderedValues() ValueEnumerator

func (Relation) OrderedValuesEnumerator added in v0.258.0

func (r Relation) OrderedValuesEnumerator(names NamesSlice) *RelationValuesEnumerator

func (Relation) Source added in v0.258.0

func (r Relation) Source() parser.Scanner

func (Relation) String added in v0.258.0

func (r Relation) String() string

func (Relation) Where added in v0.258.0

func (r Relation) Where(p func(Value) (bool, error)) (_ Set, err error)

func (Relation) With added in v0.258.0

func (r Relation) With(v Value) Set

func (Relation) Without added in v0.258.0

func (r Relation) Without(v Value) Set

type RelationValuesEnumerator added in v0.258.0

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

RelationValuesEnumerator enumerates the values as Values.

func (*RelationValuesEnumerator) Next added in v0.258.0

func (e *RelationValuesEnumerator) Next() bool

func (*RelationValuesEnumerator) Values added in v0.258.0

func (e *RelationValuesEnumerator) Values() Values

type SafeTailCallback added in v0.3.0

type SafeTailCallback func(context.Context, 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(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, 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
	ArrayEnumerator() ValueEnumerator // iterates in ascending order.

	// Transform
	With(Value) Set
	Without(Value) Set
	Map(func(Value) (Value, error)) (Set, error)
	Where(func(Value) (bool, error)) (Set, error)
	CallAll(context.Context, Value, SetBuilder) error
	// contains filtered or unexported methods
}

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 MustNewDict added in v0.179.0

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

MustNewDict constructs a dict as a relation {|@, @value|...}, or panics if construction fails.

func MustNewSet added in v0.179.0

func MustNewSet(values ...Value) Set

MustNewSet constructs a genericSet from a set of Values, or panics if construction fails.

func NConcatenate

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

NConcatenate applies concatenate to one or more sets.

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, relAttrs, 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 a byte array as a relation.

func NewDict

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

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

func NewOffsetArray

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

NewOffsetArray constructs an offset array as a relation.

func NewOffsetBytes

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

NewOffsetBytes constructs an offset byte array as a relation.

func NewOffsetString

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

NewOffsetString constructs an offset string as a relation.

func NewSet

func NewSet(values ...Value) (Set, error)

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 a string as a relation.

func PowerSet

func PowerSet(s Set) (Set, error)

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 SingleAttrNest added in v0.122.0

func SingleAttrNest(a Set, relAttrs Names, attr string) Set

SingleAttrNest nests a single attribute as a set.

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 value that is in either input Set (or both).

func Unnest

func Unnest(a Set, attr string) (Set, error)

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

type SetBuilder added in v0.238.0

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

func NewSetBuilder added in v0.238.0

func NewSetBuilder() SetBuilder

func (*SetBuilder) Add added in v0.238.0

func (b *SetBuilder) Add(v Value)

func (*SetBuilder) Finish added in v0.238.0

func (b *SetBuilder) Finish() (Set, error)

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(ctx context.Context, 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 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(ctx context.Context, local Scope, value Value) (context.Context, 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 SingleNestExpr added in v0.122.0

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

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

func (*SingleNestExpr) Eval added in v0.122.0

func (e *SingleNestExpr) Eval(ctx context.Context, local Scope) (Value, error)

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

func (*SingleNestExpr) String added in v0.122.0

func (e *SingleNestExpr) String() string

String returns a string representation of the expression.

type String

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

String is a set of Values.

func AsString

func AsString(v Value) (String, bool)

AsString returns String and the empty set as String or false otherwise.

func (String) ArrayEnumerator

func (s String) ArrayEnumerator() ValueEnumerator

func (String) CallAll added in v0.3.0

func (s String) CallAll(_ context.Context, arg Value, b SetBuilder) 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) EqualString added in v0.238.0

func (s String) EqualString(t String) bool

func (String) Eval

func (s String) Eval(ctx context.Context, _ Scope) (Value, error)

Eval returns the string.

func (String) Export

func (s String) Export(_ context.Context) interface{}

Export exports a String as a string.

func (String) Format added in v0.291.0

func (s String) Format(f fmt.State, verb rune)

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, error)) (Set, error)

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(ctx context.Context, local Scope) (Value, error)

Eval returns the tuple.

func (StringCharTuple) Export

func (t StringCharTuple) Export(_ context.Context) interface{}

Export exports a Tuple.

func (StringCharTuple) Format added in v0.291.0

func (t StringCharTuple) Format(f fmt.State, verb rune)

Format formats a StringCharTuple.

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, error)) (Tuple, error)

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 StringCharTuple.

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(ctx context.Context, 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 TrueSet added in v0.252.0

type TrueSet struct{}

TrueSet is a special set that represents True/{()}.

func (TrueSet) ArrayEnumerator added in v0.252.0

func (t TrueSet) ArrayEnumerator() ValueEnumerator

func (TrueSet) CallAll added in v0.252.0

func (TrueSet) Count added in v0.252.0

func (TrueSet) Count() int

func (TrueSet) Enumerator added in v0.252.0

func (TrueSet) Enumerator() ValueEnumerator

func (TrueSet) Equal added in v0.252.0

func (TrueSet) Equal(i interface{}) bool

func (TrueSet) Eval added in v0.252.0

func (t TrueSet) Eval(ctx context.Context, local Scope) (Value, error)

func (TrueSet) Export added in v0.252.0

func (TrueSet) Export(context.Context) interface{}

func (TrueSet) Format added in v0.291.0

func (TrueSet) Format(f fmt.State, verb rune)

func (TrueSet) Has added in v0.252.0

func (TrueSet) Has(v Value) bool

func (TrueSet) Hash added in v0.252.0

func (TrueSet) Hash(seed uintptr) uintptr

func (TrueSet) IsTrue added in v0.252.0

func (TrueSet) IsTrue() bool

func (TrueSet) Kind added in v0.252.0

func (TrueSet) Kind() int

func (TrueSet) Less added in v0.252.0

func (t TrueSet) Less(v Value) bool

func (TrueSet) Map added in v0.252.0

func (TrueSet) Map(f func(Value) (Value, error)) (Set, error)

func (TrueSet) Negate added in v0.252.0

func (t TrueSet) Negate() Value

func (TrueSet) Source added in v0.252.0

func (TrueSet) Source() parser.Scanner

func (TrueSet) String added in v0.252.0

func (TrueSet) String() string

func (TrueSet) Where added in v0.252.0

func (t TrueSet) Where(p func(Value) (bool, error)) (Set, error)

func (TrueSet) With added in v0.252.0

func (t TrueSet) With(v Value) Set

func (TrueSet) Without added in v0.252.0

func (t TrueSet) Without(v Value) Set

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, error)) (Tuple, error)
	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 MergeTuples added in v0.274.0

func MergeTuples(tuple Tuple, tuple2 Tuple) Tuple

MergeTuples takes two tuples and performs a deep merge

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

func TupleProjectAllBut added in v0.106.0

func TupleProjectAllBut(t Tuple, names Names) Tuple

TupleProjectAllBut returns the projection of t over all of its attributes except those specified in names.

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(ctx context.Context, 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(ctx context.Context, local Scope) (Value, 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, error)

func (TuplePattern) Bind

func (p TuplePattern) Bind(ctx context.Context, local Scope, value Value) (context.Context, 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 TupleProjectExpr added in v0.121.0

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

func (*TupleProjectExpr) Eval added in v0.121.0

func (tp *TupleProjectExpr) Eval(ctx context.Context, local Scope) (Value, error)

func (*TupleProjectExpr) String added in v0.121.0

func (tp *TupleProjectExpr) 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(ctx context.Context, 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 UnionSet added in v0.248.0

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

func (UnionSet) ArrayEnumerator added in v0.248.0

func (u UnionSet) ArrayEnumerator() ValueEnumerator

func (UnionSet) CallAll added in v0.248.0

func (u UnionSet) CallAll(ctx context.Context, arg Value, sb SetBuilder) error

func (UnionSet) Count added in v0.248.0

func (u UnionSet) Count() int

func (UnionSet) Enumerator added in v0.248.0

func (u UnionSet) Enumerator() ValueEnumerator

func (UnionSet) Equal added in v0.248.0

func (u UnionSet) Equal(s interface{}) bool

func (UnionSet) Eval added in v0.248.0

func (u UnionSet) Eval(ctx context.Context, local Scope) (Value, error)

func (UnionSet) Export added in v0.248.0

func (u UnionSet) Export(ctx context.Context) interface{}

func (UnionSet) Format added in v0.291.0

func (u UnionSet) Format(f fmt.State, verb rune)

func (UnionSet) Has added in v0.248.0

func (u UnionSet) Has(v Value) bool

func (UnionSet) Hash added in v0.248.0

func (u UnionSet) Hash(seed uintptr) uintptr

func (UnionSet) IsTrue added in v0.248.0

func (u UnionSet) IsTrue() bool

func (UnionSet) Kind added in v0.248.0

func (u UnionSet) Kind() int

func (UnionSet) Less added in v0.248.0

func (u UnionSet) Less(v Value) bool

func (UnionSet) Map added in v0.248.0

func (u UnionSet) Map(f func(Value) (Value, error)) (Set, error)

func (UnionSet) Negate added in v0.248.0

func (u UnionSet) Negate() Value

func (UnionSet) OrderedValues added in v0.248.0

func (u UnionSet) OrderedValues() ValueEnumerator

func (UnionSet) Source added in v0.248.0

func (u UnionSet) Source() parser.Scanner

func (UnionSet) String added in v0.248.0

func (u UnionSet) String() string

func (UnionSet) Where added in v0.248.0

func (u UnionSet) Where(f func(Value) (bool, error)) (Set, error)

func (UnionSet) With added in v0.248.0

func (u UnionSet) With(v Value) Set

func (UnionSet) Without added in v0.248.0

func (u UnionSet) Without(v Value) Set

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(ctx context.Context, 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 {
	fmt.Formatter

	frozen.Key

	// Values are Exprs.
	Expr

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

	// IsTrue 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(context.Context) interface{}
	// contains filtered or unexported methods
}

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(ctx context.Context, a, b Value, _ Scope) (Value, error)

func NewExprClosure

func NewExprClosure(scope Scope, e Expr) Value

NewExprClosure returns a new ExprClosure.

func NewNativeFunction

func NewNativeFunction(name string, fn NativeFnBody) Value

NewNativeFunction returns a new function.

func NewNativeLambda

func NewNativeLambda(fn NativeFnBody) 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 SetCall added in v0.3.0

func SetCall(ctx context.Context, s Set, arg Value) (Value, error)

SetCall is a convenience wrapper to call a set and return the result or an error if there isn't exactly one result.

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)

type Values added in v0.258.0

type Values []Value

Values is used as a high performance tuple in the Relation struct.

func (Values) Equal added in v0.258.0

func (v Values) Equal(i interface{}) bool

func (Values) Format added in v0.291.0

func (v Values) Format(f fmt.State, verb rune)

func (Values) Hash added in v0.258.0

func (v Values) Hash(seed uintptr) uintptr

func (Values) String added in v0.258.0

func (v Values) String() string

Jump to

Keyboard shortcuts

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