objectpath

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ElementRoot = Element{"", ElementTypeRoot}

ElementRoot is a special Element that indicates the root element

View Source
var ElementSelfReference = Element{".", ElementTypeSelfReference}

ElementSelfReference is a special Element that indicates a self reference. It has no effect on the path

View Source
var ElementUpwardsReference = Element{"..", ElementTypeUpwardsReference}

ElementUpwardsReference is a special Element that indicates an upwards reference

Functions

func AssignTypeAtPath

func AssignTypeAtPath(source any, path ObjectPath, newType reflect.Type) error

AssignTypeAtPath assigns the given reflect.Type to the value at the given path in source. The source must be a pointer.

func GetValueAtPath

func GetValueAtPath(source any, path ObjectPath, out *reflect.Value) error

GetValueAtPath returns the value at the given path in source. The source must be a pointer. The value is returned as a reflect.Value in out.

func ParsePathString

func ParsePathString(s string, path *Elements) error

ParsePathString parses a string into a slice of Element.

Types

type Context

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

Context contains the current ParsingState, input string, and other information needed for parsing.

type Element

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

Element is a single element of a ObjectPath

func MakeElement

func MakeElement(name string) Element

MakeElement creates a new Element with the given name

func (*Element) IsRootElement

func (e *Element) IsRootElement() bool

IsRootElement returns true if the Element is the root element

func (*Element) IsUpwardsReference

func (e *Element) IsUpwardsReference() bool

IsUpwardsReference returns true if the Element is the upward reference element

type ElementType

type ElementType int

ElementType defines the type of Element

const (
	// ElementTypeIdentifier is the type of Element that is a normal identifier
	ElementTypeIdentifier ElementType = iota
	// ElementTypeSelfReference is the type of Element that is a self reference ("."). It has no effect on the path.
	ElementTypeSelfReference
	// ElementTypeUpwardsReference is the type of Element that is an upwards reference ("..")
	ElementTypeUpwardsReference
	// ElementTypeRoot is the type of Element that is the root element
	ElementTypeRoot
)

type Elements

type Elements []Element

Elements is a slice of Element

type ObjectPath

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

ObjectPath manages Elements and may be absolute or relative

func NewEmptyPath

func NewEmptyPath() *ObjectPath

func NewObjectPathFromString

func NewObjectPathFromString(s string) (error, *ObjectPath)

NewObjectPathFromString creates a new ObjectPath from a string

func NewSelfReferencePath

func NewSelfReferencePath() *ObjectPath

NewSelfReferencePath creates a new ObjectPath with a single self reference element. The path is relative.

func (*ObjectPath) DeleteAt

func (p *ObjectPath) DeleteAt(index int, n int) error

DeleteAt removes n elements starting at index

func (*ObjectPath) IsAbsolutePath

func (p *ObjectPath) IsAbsolutePath() bool

IsAbsolutePath returns true if the path starts with a root element

func (*ObjectPath) IsEqualTo

func (p *ObjectPath) IsEqualTo(other *ObjectPath) bool

IsEqualTo returns true if the path is equal to the given path

func (*ObjectPath) IsRelativePath

func (p *ObjectPath) IsRelativePath() bool

IsRelativePath returns true if the path does not start with a root element

func (*ObjectPath) Normalize

func (p *ObjectPath) Normalize() error

Normalize an absolute path by resolving upwards references

func (*ObjectPath) Pop

func (p *ObjectPath) Pop() error

Pop removes the last element of the path

func (*ObjectPath) Push

func (p *ObjectPath) Push(element Element) error

Push appends an element to the path

func (*ObjectPath) String

func (p *ObjectPath) String() string

String returns the string representation of the path. This string would lead to the same path when parsed again.

func (*ObjectPath) ToAbsolutePath

func (p *ObjectPath) ToAbsolutePath(referencePath *ObjectPath) error

ToAbsolutePath converts a relative path to an absolute path using the given absolute reference path

type ParsingState

type ParsingState int

ParsingState indicates the current state of the parser.

const (
	// The ParsingStateBeginning ParsingState is the state of the parser directly after a ParsingStateSlash or at the beginning of the string.
	ParsingStateBeginning ParsingState = iota
	// The ParsingStateName ParsingState is the state of the parser when parsing a non-enclosed name, e.g. `foo` in `foo/"bar"`.
	ParsingStateName
	// The ParsingStateEnclosedIdentifier ParsingState is the state of the parser when parsing an enclosed name, e.g. `"bar"` in `foo."bar"`.
	ParsingStateEnclosedIdentifier
	// The ParsingStateEscaping ParsingState is the state of the parser when parsing an escaped character, e.g. `"` after `\` in `foo/"bar\""`.
	ParsingStateEscaping
	// The ParsingStateSlash ParsingState is the state of the parser when parsing a slash, e.g. in `foo/bar`.
	ParsingStateSlash
	// The ParsingStateDot ParsingState is the state of the parser when parsing a dot, e.g. in `../bar`.
	ParsingStateDot
)

Jump to

Keyboard shortcuts

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