Documentation ¶
Index ¶
- func Eval(ctx *Context, iter Iterator) error
- func Query(params *QueryParams) (interface{}, error)
- func RegisterBuiltinFunc(name ast.Var, fun BuiltinFunc)
- func ValueToFloat64(v ast.Value, ctx *Context) (float64, error)
- func ValueToInterface(v ast.Value, ctx *Context) (interface{}, error)
- func ValueToSlice(v ast.Value, ctx *Context) ([]interface{}, error)
- func ValueToString(v ast.Value, ctx *Context) (string, error)
- type BuiltinFunc
- type Context
- func (ctx *Context) BindRef(ref ast.Ref, value ast.Value) *Context
- func (ctx *Context) BindVar(variable ast.Var, value ast.Value) *Context
- func (ctx *Context) Binding(k ast.Value) ast.Value
- func (ctx *Context) Child(rule *ast.Rule, locals *storage.Bindings) *Context
- func (ctx *Context) Current() *ast.Expr
- func (ctx *Context) Step() *Context
- type Iterator
- type QueryParams
- type StdoutTracer
- type Tracer
- type Undefined
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Eval ¶
Eval runs the evaluation algorithm on the contxet and calls the iterator foreach context that contains bindings that satisfy all of the expressions inside the body.
func Query ¶
func Query(params *QueryParams) (interface{}, error)
Query returns the document identified by the path.
If the storage node identified by the path is a collection of rules, then the TopDown algorithm is run to generate the virtual document defined by the rules.
func RegisterBuiltinFunc ¶
func RegisterBuiltinFunc(name ast.Var, fun BuiltinFunc)
RegisterBuiltinFunc adds a new built-in function to the evaluation engine.
func ValueToFloat64 ¶
ValueToFloat64 returns the underlying Go value associated with an AST value. If the value is a reference, the reference is fetched from storage.
func ValueToInterface ¶
ValueToInterface returns the underlying Go value associated with an AST value. If the value is a reference, the reference is fetched from storage. Composite AST values such as objects and arrays are converted recursively.
func ValueToSlice ¶
ValueToSlice returns the underlying Go value associated with an AST value. If the value is a reference, the reference is fetched from storage.
Types ¶
type BuiltinFunc ¶
BuiltinFunc defines the interface that the evaluation engine uses to invoke built-in functions. Users can implement their own built-in functions and register them with the evaluation engine.
Callers are given the current evaluation Context ctx with the expression expr to be evaluated. Callers can assume that the expression has been plugged with bindings from the current context. If the built-in function determines that the expression has evaluated successfully it should bind any output variables and invoke the iterator with the context produced by binding the output variables.
type Context ¶
type Context struct { Query ast.Body Globals *storage.Bindings Locals *storage.Bindings Index int Previous *Context DataStore *storage.DataStore Tracer Tracer }
Context contains the state of the evaluation process.
TODO(tsandall): profile perf/memory usage with current approach; the current approach copies the Context structure for each step and binding. This avoids the need to undo steps and bindings each time the proof fails but this may be too expensive.
func NewContext ¶
NewContext creates a new Context with no bindings.
func (*Context) BindRef ¶
BindRef returns a new Context with bindings that map the reference to the value.
func (*Context) BindVar ¶
BindVar returns a new Context with bindings that map the variable to the value.
If the caller attempts to bind a variable to itself (e.g., "x = x"), no mapping is added. This is effectively a no-op.
If the call would introduce a recursive binding, nil is returned. This represents an undefined context that cannot be evaluated. E.g., "x = [x]".
Binding a variable to some value also updates existing bindings to that variable.
TODO(tsandall): potential optimization:
The current implementation eagerly flattens the bindings by updating existing bindings each time a new binding is added. E.g., if Bind(y, [1,2,x]) and Bind(x, 3) are called (one after the other), the binding for "y" will be updated. It may be possible to defer this to a later stage, e.g., when plugging the values.
func (*Context) Child ¶
Child returns a new context to evaluate a rule that was referenced by this context.
type QueryParams ¶
type QueryParams struct { DataStore *storage.DataStore Globals *storage.Bindings Tracer Tracer Path []interface{} }
QueryParams defines input parameters for the query interface.
func NewQueryParams ¶
func NewQueryParams(ds *storage.DataStore, globals *storage.Bindings, path []interface{}) (q *QueryParams)
NewQueryParams returns a new QueryParams q.
type StdoutTracer ¶
type StdoutTracer struct{}
StdoutTracer writes trace messages to stdout.
func (*StdoutTracer) Trace ¶
func (t *StdoutTracer) Trace(ctx *Context, f string, a ...interface{})
Trace writes a trace message to stdout.