Documentation ¶
Index ¶
- Variables
- func AssignTypeAtPath(source any, path ObjectPath, newType reflect.Type) error
- func GetValueAtPath(source any, path ObjectPath, out *reflect.Value) error
- func ParsePathString(s string, path *Elements) error
- type Context
- type Element
- type ElementType
- type Elements
- type ObjectPath
- func (p *ObjectPath) DeleteAt(index int, n int) error
- func (p *ObjectPath) IsAbsolutePath() bool
- func (p *ObjectPath) IsEqualTo(other *ObjectPath) bool
- func (p *ObjectPath) IsRelativePath() bool
- func (p *ObjectPath) Normalize() error
- func (p *ObjectPath) Pop() error
- func (p *ObjectPath) Push(element Element) error
- func (p *ObjectPath) String() string
- func (p *ObjectPath) ToAbsolutePath(referencePath *ObjectPath) error
- type ParsingState
Constants ¶
This section is empty.
Variables ¶
var ElementRoot = Element{"", ElementTypeRoot}
ElementRoot is a special Element that indicates the root element
var ElementSelfReference = Element{".", ElementTypeSelfReference}
ElementSelfReference is a special Element that indicates a self reference. It has no effect on the path
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 ¶
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 ¶
MakeElement creates a new Element with the given name
func (*Element) IsRootElement ¶
IsRootElement returns true if the Element is the root element
func (*Element) IsUpwardsReference ¶
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 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) 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 )