Documentation ¶
Index ¶
- Variables
- type Document
- type ErrWithPosition
- type Identifier
- type Node
- func (n *Node) AddArg(arg interface{}) error
- func (n *Node) AddArgValue(arg Value)
- func (n *Node) AddChild(child Node)
- func (n *Node) GetProp(key Identifier) Value
- func (n *Node) HasProp(key Identifier) bool
- func (n *Node) RemoveProp(key Identifier)
- func (n *Node) SetProp(key Identifier, value interface{}) error
- func (n *Node) SetPropValue(key Identifier, value Value)
- type TypeHint
- type TypeTag
- type Value
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidSyntax is a base error for when // a parser comes across a document that is not spec-compliant. ErrInvalidSyntax = errors.New("invalid syntax") // ErrInvalidEncoding is a base error for when // an invalid UTF8 byte sequence is encountered. ErrInvalidEncoding = errors.New("document is not UTF-8 encoded") // ErrUnexpectedEOF is a base error for when // the data abruptly ends e.g. inside a string. ErrUnexpectedEOF = io.ErrUnexpectedEOF // ErrInvalidValueType happens when a raw value cannot be cast to a kdl.Value. ErrInvalidValueType = errors.New("cannot transform to a valid kdl.Value type") )
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
Nodes []Node
}
Document is a top-level unit of the KDL format.
func ParseBytes ¶
func ParseString ¶
func (*Document) WriteString ¶
WriteString marshals the Document to a new string.
type ErrWithPosition ¶
type ErrWithPosition struct { Err error // The original error. Line int // Line where the error occurred, 1-indexed. Column int // Column where the error occurred, 0-indexed. }
ErrWithPosition wraps an error, adding information where in the document did it occur.
func (*ErrWithPosition) Error ¶
func (e *ErrWithPosition) Error() string
Error formats an error message.
func (*ErrWithPosition) Unwrap ¶
func (e *ErrWithPosition) Unwrap() error
Unwrap returns the original error.
type Identifier ¶
type Identifier string
Identifier is a fancy name for a string in place of a node's name, type hint or a property key.
type Node ¶
type Node struct { TypeHint TypeHint // Optional hint about the type of this node. Name Identifier // Name of the node. Args []Value // Ordered arguments of the node. Props map[Identifier]Value // Unordered properties of the node. CAN BE NIL. Children []Node // Ordered children of the node. }
Node is an object in a KDL Document.
func (*Node) AddArgValue ¶ added in v0.2.0
AddArgValue adds a Value as an order-sensitive argument of this Node.
func (*Node) GetProp ¶ added in v0.2.0
func (n *Node) GetProp(key Identifier) Value
GetProp returns a property of this Node.
func (*Node) HasProp ¶ added in v0.2.0
func (n *Node) HasProp(key Identifier) bool
HasProp returns true if this Node has a property of that name.
func (*Node) RemoveProp ¶ added in v0.2.0
func (n *Node) RemoveProp(key Identifier)
RemoveProp removes a property from this Node.
func (*Node) SetProp ¶
func (n *Node) SetProp(key Identifier, value interface{}) error
SetProp sets or replaces a property of this Node.
func (*Node) SetPropValue ¶ added in v0.2.0
func (n *Node) SetPropValue(key Identifier, value Value)
SetPropValue sets or replaces a property of this Node.
type TypeHint ¶
type TypeHint struct {
// contains filtered or unexported fields
}
TypeHint is an optional Identifier associated with a Value.
func (TypeHint) Get ¶
func (h TypeHint) Get() (Identifier, bool)
Get returns the inner type hint, if it exists.
func (TypeHint) MustGet ¶
func (h TypeHint) MustGet() Identifier
MustGet returns the inner type hint or panics, if it does not exist.
type TypeTag ¶
type TypeTag byte
TypeTag discriminates between Value types.
const ( TypeInvalid TypeTag = iota // The described Value is in an invalid state. TypeNull // The described Value holds a null. TypeBool // The described Value holds a boolean. TypeString // The described Value holds a string. TypeInteger // The described Value holds an integer. TypeFloat // The described Value holds a floating point number. )
type Value ¶
Value can be used either as an argument or a property to a Node.
func NewBoolValue ¶
NewBoolValue constructs a Value that holds a boolean.
func NewFloatValue ¶
NewFloatValue constructs a Value that holds a float.
func NewIntegerValue ¶
NewIntegerValue constructs a Value that holds an integer.
func NewNullValue ¶
NewNullValue constructs a Value that holds a null.
func NewStringValue ¶
NewStringValue constructs a Value that holds a string.
func ValueOf ¶ added in v0.2.0
ValueOf tries to construct a Value from a provided object. The resulting Value, if valid, will not have a type hint.
func (Value) BoolValue ¶ added in v0.2.0
BoolValue returns the inner bool value or panics, if the Value is not a boolean.
func (Value) FloatValue ¶ added in v0.2.0
FloatValue returns the inner float value or panics, if the Value is not a floating point number.
func (Value) IntegerValue ¶ added in v0.2.0
IntegerValue returns the inner int value or panics, if the Value is not an integer.
func (Value) StringValue ¶ added in v0.2.0
StringValue returns the inner string value or panics, if the Value is not a string.