xpathleaf

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
var (
	WithLocals     func(ctx any, l *Locals) any
	WithBindingsOf func(ctx, base any) any
)

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.

View Source
var BindHost func(ctx any, name xdm.QName) func(callCtx any) any

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.

View Source
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.

View Source
var NewStepMemo func() any

NewStepMemo returns an empty memo for a StepMemoHost. 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
}

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

func (l *Locals) Detach(n int) *Locals

Detach takes the bindings above the first n off the stack, for Reattach to put back.

func (*Locals) Frozen

func (l *Locals) Frozen() *Locals

Frozen is a copy of the visible bindings that later pushes and truncations do not change.

func (*Locals) Len

func (l *Locals) Len() int

Len is the number of bindings on the stack, visible or not.

func (*Locals) Lookup

func (l *Locals) Lookup(uri, local string) (xdm.Sequence, bool)

Lookup finds the topmost visible binding of the name.

func (*Locals) Off

func (l *Locals) Off() bool

Off reports whether the stack is suspended or closed: the goroutine running now must not bind on it.

func (*Locals) Push

func (l *Locals) Push(name xdm.QName, val xdm.Sequence)

Push binds name to val above every binding already on the stack.

func (*Locals) Reattach

func (l *Locals) Reattach(d *Locals)

Reattach pushes back what Detach took off.

func (*Locals) SetBase

func (l *Locals) SetBase(n int) int

SetBase hides the bindings below n from lookups and returns the old base.

func (*Locals) Suspend

func (l *Locals) Suspend() (resume func())

Suspend turns the stack off and hides every binding on it from lookups, until the returned resume. It does nothing to a nil or an off stack.

func (*Locals) Truncate

func (l *Locals) Truncate(n int)

Truncate drops the bindings above the first n.

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.

Jump to

Keyboard shortcuts

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