inspect

package
v0.24.8 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package inspect provides depth first iteration a tapestry command or slice of commands.

Index

Constants

This section is empty.

Variables

View Source
var ErrDone = errors.New("done visiting")

can be used to early exit from visiting caller still has to check for this to disambiguate the returned error

Functions

func Visit

func Visit(i typeinfo.Instance, evt Events) (err error)

turn the iterator into an event style callbacks

Types

type Callbacks

type Callbacks struct {
	OnFlow   func(It) error
	OnField  func(It) error
	OnSlot   func(It) error
	OnRepeat func(It) error
	OnValue  func(It) error
	OnEnd    func(It) error
}

implements the Events interface

func (Callbacks) End

func (c Callbacks) End(w It) (err error)

func (Callbacks) Field

func (c Callbacks) Field(w It) (err error)

func (Callbacks) Flow

func (c Callbacks) Flow(w It) (err error)

func (Callbacks) Repeat

func (c Callbacks) Repeat(w It) (err error)

func (Callbacks) Slot

func (c Callbacks) Slot(w It) (err error)

func (Callbacks) Value

func (c Callbacks) Value(w It) (err error)

type Ender

type Ender func(It, error) error

signature for OnEnd

type Events

type Events interface {
	Flow(It) error
	// called for every member of a flow.
	Field(It) error
	// called for a member slot: can be an empty slot.
	Slot(It) error
	// called for a member that repeats; can be an empty list.
	Repeat(It) error
	// called for each str or num in a flow, or in a repeat.
	// because it isnt a container, there is no matching end.
	Value(It) error
	// called after each flow, slot, or repeat.
	End(It) error
}

fix? this should probably be passing type info and not walker itself

func OnEnd

func OnEnd(evt Events, cb Ender) Events

after evt.End() run a function. the function receives the error that the End function returned. the callback can "upgrade" errors ( from no error to some error ) but otherwise the callback should return the error it received.

type It

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

If a command, a slot for a command, and slices of commands or slots, can all be thought of as containers of values, where values are primitive values or other containers, then It provides a depth first traversal of those values. In this context, a slice of primitives values is handled treated as a single value.

func Walk

func Walk(i typeinfo.Instance) It

Provides iteration of tapestry commands. The returned It starts pointing to the passed container, calling Next advances to each element of the container in turn. Containers can be a single command, a slot for a command, or slices of commands or slots; other values have undefined results and may panic.

func (*It) CompactValue

func (w *It) CompactValue() (ret any)

returns the value of the current focus as it would appear in file. enums use lower_case strings, while bool uses true/false. falls back to the container itself if Next() has yet to be called.

func (*It) Float

func (w *It) Float() float64

turn a Number value into a float; panics otherwise.

func (*It) GetSlot

func (w *It) GetSlot(ptr any) (okay bool)

read the target of a slot

func (*It) IsZero

func (w *It) IsZero() (okay bool)

returns whether the focused value is at its default value. falls back to the container itself if Next() has yet to be called.

func (*It) Len

func (w *It) Len() (ret int)

Returns the number of repeated elements in the current container; doesn't change over the course of iteration. Filled slots have one element; empty slots zero elements.

func (*It) Markup

func (w *It) Markup(ensure bool) (ret map[string]any)

metadata for the currently focused element. only valid flow; returns nil otherwise

func (*It) Next

func (w *It) Next() (okay bool)

advance the focus within the current collection.

func (*It) RawValue

func (w *It) RawValue() r.Value

fix: backwards compatibility. what are the use cases and what should be brought in here?

func (*It) Repeating

func (w *It) Repeating() bool

tbd: merge with typeinfo similar to inspect?

func (*It) Resize

func (w *It) Resize(cnt int)

change the size of the container

func (*It) SetSlot

func (w *It) SetSlot(val typeinfo.Instance) (okay bool)

write a value into the target of a slot.

func (*It) SetValue

func (w *It) SetValue(val any) (okay bool)

fix? feels like this should match the way Get works. write a value into the target of an iterator. returns false if the value is incompatible ( uses go rules of conversion when needed to complete the assignment )

func (*It) String

func (w *It) String() (ret string)

turn a Str value into a string; panics otherwise. as a special case, knows to transform boolean values to "true" or "false"

func (*It) Term

func (w *It) Term() (ret typeinfo.Term)

only valid for the members of a flow; panics otherwise

func (*It) TypeInfo

func (w *It) TypeInfo() typeinfo.T

the autogenerated description of the currently focused element.

func (*It) Walk

func (w *It) Walk() (ret It)

returns a new walker for the currently focused element; panics if the focused element isn't a valid container.

type Stack

type Stack struct {
	Events
	// contains filtered or unexported fields
}

implements Events by delegating calls to whatever is on the top of the stack.

func (*Stack) Pop

func (s *Stack) Pop() (err error)

func (*Stack) Push

func (s *Stack) Push(next Events) (_ error)

always returns nil

func (*Stack) Replace

func (s *Stack) Replace(next Events)

Jump to

Keyboard shortcuts

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