Documentation ¶
Index ¶
- Variables
- func AppendQuotedString(b []byte, s string, quote byte) []byte
- func AppendRawString(b []byte, s string) []byte
- func AppendUnquotedString(b []byte, s string, quote byte) ([]byte, error)
- func QuoteString(s string) string
- func UnquoteString(s string) (string, error)
- type Document
- type Node
- func (n *Node) AddArgument(value interface{}, typeAnnot TypeAnnotation) *Value
- func (n *Node) AddArgumentToken(t tokenizer.Token, typeAnnot tokenizer.Token) error
- func (n *Node) AddNode(child *Node)
- func (n *Node) AddProperty(name string, value interface{}, typeAnnot TypeAnnotation) *Value
- func (n *Node) AddPropertyToken(name tokenizer.Token, value tokenizer.Token, typeAnnot tokenizer.Token) (*Value, error)
- func (n *Node) AddPropertyValue(name string, value *Value, typeAnnot TypeAnnotation) *Value
- func (n *Node) ExpectArguments(count int)
- func (n *Node) ExpectChildren(count int)
- func (n *Node) SetName(name string)
- func (n *Node) SetNameToken(t tokenizer.Token) error
- func (n *Node) String() string
- func (n *Node) TextString() string
- func (n *Node) ValueString() string
- func (n *Node) WriteTextValueTo(w io.Writer) (int64, error)
- func (n *Node) WriteTo(w io.Writer) (int64, error)
- func (n *Node) WriteToOptions(w io.Writer, opts NodeWriteOptions) (int64, error)
- func (n *Node) WriteValueTo(w io.Writer) (int64, error)
- type NodeWriteOptions
- type Properties
- func (p Properties) Add(name string, val *Value)
- func (p *Properties) Alloc()
- func (p Properties) Allocated() bool
- func (p Properties) Exist() bool
- func (p Properties) Get(key string) (*Value, bool)
- func (p Properties) Len() int
- func (p Properties) String() string
- func (p Properties) UnformattedString() string
- func (p Properties) Unordered() map[string]*Value
- type SuffixedDecimal
- type TypeAnnotation
- type Value
- type ValueFlag
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = errors.New("invalid quoted string")
Functions ¶
func AppendQuotedString ¶
AppendQuotedString appends s, quoted for use as a KDL FormattedString, to b, and returns the expanded buffer.
AppendQuotedString is based on the JSON string quoting function from the MIT-Licensed ZeroLog, Copyright (c) 2017 Olivier Poitrey, but has been heavily modified to improve performance and use KDL string escapes instead of JSON.
func AppendRawString ¶
AppendRawString appends s, quoted for use as a KDL RawString, to b and returns the expanded buffer.
func AppendUnquotedString ¶
AppendUnquotedString appends s, unquoted from KDL FormattedString notation, to b and returns the expanded buffer.
AppendUnquotedString was originally based on the JSON string quoting function from the MIT-Licensed ZeroLog, Copyright (c) 2017 Olivier Poitrey, but has been heavily modified to unquote KDL quoted strings.
func QuoteString ¶
QuoteString returns s quoted for use as a KDL FormattedString
func UnquoteString ¶
UnquoteString returns s unquoted from KDL FormattedString notation
Types ¶
type Document ¶
type Document struct {
Nodes []*Node
}
Document is the top-level container for a KDL document
type Node ¶
type Node struct { // Name is name of the node Name *Value // Type is the type annotation of the node, or an empty string if none Type TypeAnnotation // Arguments is the list of arguments for the node, or nil if none Arguments []*Value // Properties is the list of properties for the node, or nil if none Properties Properties // Children is the list of child nodes for the node, or nil if none Children []*Node }
Node represents a single node in a KDL document
func (*Node) AddArgument ¶
func (n *Node) AddArgument(value interface{}, typeAnnot TypeAnnotation) *Value
AddArgument adds an argument to this node, with the given type annotation (which may be ""), and returns the added Value
func (*Node) AddArgumentToken ¶
AddArgumentToken adds an argument to this node from a Token, with the given type annotation (which may be ""), and returns a non-nil error on failure
func (*Node) AddProperty ¶
func (n *Node) AddProperty(name string, value interface{}, typeAnnot TypeAnnotation) *Value
AddProperty adds a property to this node with the given name, value, and type annotation (which may be ""), and returns the added Value
func (*Node) AddPropertyToken ¶
func (n *Node) AddPropertyToken(name tokenizer.Token, value tokenizer.Token, typeAnnot tokenizer.Token) (*Value, error)
AddPropertyToken adds a property to this node from the given name and value Token and type annotation (which may be "") and returns the added Value and a non-nil error on failure
func (*Node) AddPropertyValue ¶
func (n *Node) AddPropertyValue(name string, value *Value, typeAnnot TypeAnnotation) *Value
func (*Node) ExpectArguments ¶
func (*Node) ExpectChildren ¶
func (*Node) SetNameToken ¶
SetNameToken sets the name of the node from a Token, and returns a non-nil error on failure
func (*Node) String ¶
String returns the complete KDL representation of this node, including its type annotation and name
func (*Node) TextString ¶
TextString returns a text representation of this node, without its type annotation or name. If the node contains exactly one argument, zero properties, and zero children, it writes the unquoted string representation of the only argument.
func (*Node) ValueString ¶
ValueString returns the KDL representation of this node, without its type annotation or name.
func (*Node) WriteTextValueTo ¶
WriteTextValueTo writes a text representation of the arguments, properties, and children of node. If node contains exactly one argument, zero properties, and zero children, it writes the unquoted string representation of the only argument.
func (*Node) WriteTo ¶
WriteTo writes the complete KDL representation of this node, including its type annotation or name.
func (*Node) WriteToOptions ¶
WriteToOptions writes the KDL representation of this node with the specified options.
type NodeWriteOptions ¶
type NodeWriteOptions struct { // LeadingTrailingSpace specifies whether leading space (indentation) and newlines are included in the output LeadingTrailingSpace bool // NameAndType specifies whether the node's name and type annotation are included in the output NameAndType bool // Depth specifies the indentation depth Depth int // Indent specifies the byte string to use for each indentation level Indent []byte // IgnoreFlags specifies that the formatting flags for the node's value(s) should be ignored IgnoreFlags bool }
NodeWriteOptions controls how a node is written using WriteToOptions.
type Properties ¶
Properties represents a list of properties for a Node
func (Properties) Add ¶
func (p Properties) Add(name string, val *Value)
Add adds a property to the list
func (Properties) Allocated ¶
func (p Properties) Allocated() bool
Allocated indicates whether the property list has been allocated
func (Properties) Exist ¶
func (p Properties) Exist() bool
Exist indicates whether any properties exist
func (Properties) Get ¶
func (p Properties) Get(key string) (*Value, bool)
Get returns Properties[key]
func (Properties) String ¶
func (p Properties) String() string
String returns the KDL representation of the property list, formatting numbers per their flags
func (Properties) UnformattedString ¶
func (p Properties) UnformattedString() string
UnformattedString returns the KDL representation of the property list, formatting numbers in decimal
func (Properties) Unordered ¶
func (p Properties) Unordered() map[string]*Value
Unordered returns the unordered property map; this simply passes through p in this implementation but is provided as it is necessary in the deterministic version
type SuffixedDecimal ¶
func ParseSuffixedDecimal ¶
func ParseSuffixedDecimal(b []byte) (SuffixedDecimal, error)
func (SuffixedDecimal) AsDuration ¶
func (s SuffixedDecimal) AsDuration() (time.Duration, error)
func (SuffixedDecimal) AsNumber ¶
func (s SuffixedDecimal) AsNumber() (interface{}, error)
func (SuffixedDecimal) String ¶
func (s SuffixedDecimal) String() string
type TypeAnnotation ¶
type TypeAnnotation string
TypeAnnotation represents a type annotation in a KDL document
type Value ¶
type Value struct { // Type is the value type, if an annotation was provided Type TypeAnnotation // Value is the actual value Value interface{} // Flag is any flag assigned for use in output Flag ValueFlag }
Value represents a value in a KDL document
func ValueFromToken ¶
ValueFromToken creates and returns a Value representing the content of t, or a non-nil error on failure
func (*Value) FormattedString ¶
FormattedString is similar to String, but bare strings are converted to quoted strings.
This is suitable for returning arguments and property values while preserving their original formatting.
func (*Value) NodeNameString ¶
NodeNameString returns the simplest possible KDL representation of this Value, including type annotation, formatting numbers in decimal notation and strings as bare strings if possible, otherwise quoted.
This is suitable for returning a valid node name.
func (*Value) ResolvedValue ¶
func (v *Value) ResolvedValue() interface{}
ResolvedValue returns the unquoted, unescaped, un-type-hinted Go representation of this value via an interface{}: - numbers are returned as the appropriate numeric type (int64, float64, *big.Int, *big.Float, etc), - bools are returned as a bool - nulls are returned as nil - strings are returned as strings containing the unquoted representation of the string
func (*Value) String ¶
String returns the KDL representation of this Value, including type annotation, formatting numbers and strings per their Flags.
This returns the exact input KDL (if any) that was used to generate this Value.
func (*Value) UnformattedString ¶
UnformattedString is similar to String, but bare strings are converted to quoted strings and numbers are formatted in decimal notation.
This is suitable for returning arguments and property values while ignoring their original formatting.
func (*Value) ValueString ¶
ValueString returns the unquoted, unescaped, un-type-hinted representation of this Value; numbers are formatted per their Flags, strings are always unquoted.
This is suitable for passing as a []byte value to UnmarshalText.
type ValueFlag ¶
type ValueFlag uint8
ValueFlag represents flags for a Value
const ( // FlagNone indicates no flag is set FlagNone ValueFlag = iota // FlagRaw specifies that this Value should be output in RawString notation (r"foo\n") FlagRaw // FlagQuoted specifies that this Value should be output in FormattedString notation ("foo\\n") FlagQuoted // FlagBinary specifies that this Value should be output in binary notation (0b10101010) FlagBinary // FlagOctal specifies that this Value should be output in octal notation (0o751) FlagOctal // FlagHexadecimal specifies that this Value should be output in hexadecimal notation (0xdeadbeef) FlagHexadecimal )