Documentation
¶
Overview ¶
Package xpathleaf lets a host package inside this module mark a function it registers with package xpath as a leaf, without adding exported API to xpath. A leaf never calls back into user code, never keeps the context past its return and never writes to it, so a call to one counts recursion depth on the caller's context in place instead of copying it (see xpath's Function.leaf). host.go carries the other hooks a host needs on the same terms.
Index ¶
- Variables
- type Host
- type Limits
- type Locals
- func (l *Locals) Close()
- func (l *Locals) Detach(n int) *Locals
- func (l *Locals) Frozen() *Locals
- func (l *Locals) FrozenOnly(keep func(uri, local string) bool) *Locals
- func (l *Locals) Items() int64
- func (l *Locals) Len() int
- func (l *Locals) Lookup(uri, local string) (xdm.Sequence, bool)
- func (l *Locals) Off() bool
- func (l *Locals) Push(name xdm.QName, val xdm.Sequence)
- func (l *Locals) Reattach(d *Locals)
- func (l *Locals) SetBase(n int) int
- func (l *Locals) Suspend() (resume func())
- func (l *Locals) Truncate(n int)
- type LocalsHost
- type NativeResolver
- type StableLibrary
- type StepMemoHost
Constants ¶
This section is empty.
Variables ¶
var ( GetHost func(ctx any) *Host WithHost func(ctx any, h *Host) any SetHost func(ctx any, h *Host) WithFocusHost func(ctx any, item xdm.Item, pos, size int, h *Host) any )
Package xpath sets these in its init. ctx is a *xpath.Context; WithHost and WithFocusHost return a copy of it, SetHost writes in place and is only for a context the caller has just made and not yet shared.
var ( ResolveDocumentIn func(r, ctx any, uri, base string) (*xdm.Tree, error) CallItem func(ctx any, fn *xdm.FunctionItem, args []xdm.Sequence) (xdm.Sequence, error) )
Package xpath sets these in its init. ResolveDocumentIn loads uri through r, an xpath.ContextDocumentResolver, for a call made at ctx, a *xpath.Context, as fn:doc does. CallItem calls fn at ctx as a dynamic call does.
var ( SetLimits func(ctx any, l Limits) Charged func(ctx any) (nodes, bytes int64) Refund func(ctx any, nodes, bytes int64) )
Package xpath sets these in its init. ctx is a *xpath.Context. SetLimits writes the limits of a context the caller has just made with NewContext and not yet shared; a nested evaluation that adopts the budget takes them with it. Charged reports the result-node and byte counters, and Refund lowers them by what the host knows is no longer held (never below zero). Neither touches the NodesBuilt and BytesBuilt totals.
Package xpath sets these in its init; ctx and base are *xpath.Context. WithLocals returns a child scope of ctx resolving names through l. WithBindingsOf returns a copy of ctx whose variable bindings are base's.
BindHost, set by the host, is consulted when package xpath turns the library function name into a function item (a named function reference, fn:function-lookup, or a partial application) at ctx, a *xpath.Context. A non-nil result maps the context of each later call of the item to the one the function runs under, putting back the host state it read at ctx: an XSLT function such as key() keeps answering for the transformation the item was made in, as it did when each transformation built its own library.
var LockYield func(l any) func()
LockYield lets go of l, an *xpath.EvalLock, when it is shared and the calling goroutine holds it, and returns what takes it back; otherwise it does nothing. Once a host call has shared the lock, the goroutine evaluating holds it: one of several goroutines that take turns evaluating with one runtime (xslt's streamed xsl:fork and xsl:merge), suspended holding it, would leave the next waiting forever. So each lets go at the end of its turn. Package xpath sets it in its init.
var Mark func(fn any)
Mark marks fn, which must be a *xpath.Function, as a leaf. Package xpath sets it in its init, so it is non-nil wherever xpath is linked in.
var NewStepMemo func() any
NewStepMemo returns an empty memo for a StepMemoHost. Package xpath sets it in its init.
var WithExpr func(c, e any) any
WithExpr returns a copy of c, an *xpath.Compiled, that evaluates e, an xpath.Expr parsed as c was, optimised as a compile optimises, under every static property c was compiled with. XSLT's burst execution evaluates a select expression in parts this way (xslt/streamburst.go). Package xpath sets it in its init.
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host struct {
// Runtime is the host's own state (XSLT: the transform runtime).
Runtime any
// Current is what fn:current() returns, a single item or, cleared, nil.
// CurrentSet says it is bound at all. A sequence rather than the item, so
// that current() returns it without allocating.
Current xdm.Sequence
CurrentSet bool
// Absent is set across a dynamic function call, where fn:current()
// behaves as if the context item were absent (XSLT XTDE1360).
Absent bool
// Unbound holds host-defined bits of context components this context is
// known to have cleared (XSLT: grouping, merge, regex captures).
Unbound uint8
// Depth is the host's recursion depth where this context was made (XSLT:
// the template depth), so that a host function called from it continues
// the count rather than restarting from where Runtime was bound.
Depth int
}
Host is a host language's dynamic state, carried on an xpath.Context in one unexported field and copied with it, as the focus is. XSLT keeps its transform runtime and fn:current() here rather than in variable bindings, whose every lookup walked the whole binding chain.
A Host on a context is never written: a change makes a new one.
type Limits ¶ added in v2.3.0
type Limits struct {
Nodes, Bytes int64
NodesBuilt, BytesBuilt int64
Entities *xdm.ParseOptions
}
Limits are the bounds an evaluation's result-node and string-byte counters are checked against, for a host that offers its caller more than the package defaults. Nodes and Bytes bound the counters, which a host may refund (Refund); zero is xpath.MaxNodes or xpath.MaxBytes and a negative value is no bound. NodesBuilt and BytesBuilt, when positive, bound every node and byte charged, refunds notwithstanding; zero or negative is none. Entities, when non-nil, holds the entity limits (the xdm.ParseOptions Max*Entity* and MaxExternal* fields; the rest is ignored) that fn:parse-xml parses with; nil is the xdm defaults.
type Locals ¶
type Locals struct {
// contains filtered or unexported fields
}
Locals is a host's stack of local variable bindings, for a host whose local scopes nest strictly: XSLT's variables and parameters, each in scope from its declaration to the end of its sequence constructor. Binding one is an append and leaving its scope a truncation, where an xpath.Context.WithVar per binding copies the scope and allocates a node every time.
One context scope (WithLocals) makes the whole stack visible to lookups, which search it from the top down to Base. A host raises Base on entering a template or function body, which sees its own locals and the globals but not its caller's. The stack is written in place, so a value that outlives the scopes it reads, such as an inline function, captures a copy (Frozen). It is used by the one goroutine running the evaluation, and by no other: while that goroutine is in host code, or once the evaluation has ended, it is off (Suspend, Close), and whatever else runs against the host binds its locals elsewhere.
func (*Locals) Close ¶
func (l *Locals) Close()
Close empties the stack and turns it off for good: the evaluation using it has ended.
func (*Locals) Detach ¶
Detach takes the bindings above the first n off the stack, for Reattach to put back.
func (*Locals) Frozen ¶
Frozen is a copy of the visible bindings that later pushes and truncations do not change.
func (*Locals) FrozenOnly ¶ added in v2.1.0
FrozenOnly is Frozen keeping only the bindings keep accepts.
func (*Locals) Items ¶ added in v2.3.0
Items is the total number of items the bindings on the stack hold.
func (*Locals) Off ¶
Off reports whether the stack is suspended or closed: the goroutine running now must not bind on it.
type LocalsHost ¶
type LocalsHost interface{ Locals() *Locals }
LocalsHost is implemented by a Host.Runtime that binds on a Locals.
type NativeResolver ¶
type NativeResolver interface{ NativeResolver() }
NativeResolver is implemented by a document or collection resolver of this module, which gives the context it is handed to no host code. Package xpath treats any other resolver taking a context as host code (see its hostCall).
type StableLibrary ¶
type StableLibrary interface {
// WrappedLibrary returns the xpath.FunctionLibrary the wrapper consults.
WrappedLibrary() any
}
StableLibrary is implemented by a host's xpath.FunctionLibrary wrapper whose answers depend only on its own comparable fields, the library it wraps and Context.StaticHost. Package xpath caches a call site's resolution through such a wrapper, keyed on the wrapper's value; a wrapper that does not implement it is looked up on every call.
type StepMemoHost ¶
type StepMemoHost interface{ StepMemo() any }
StepMemoHost is implemented by a Host.Runtime that gives package xpath somewhere to remember step walks over parsed trees for as long as the runtime lives (see xpath's stepMemo). StepMemo returns what NewStepMemo made for it. A host that implements it promises not to change a parsed tree while that runtime evaluates.