Documentation
¶
Index ¶
- Constants
- Variables
- type DefaultLogger
- type Logger
- type Node
- type Parser
- type Table
- func (t *Table) AddIndexed(n *Node) int
- func (t *Table) Equals(o *Table) bool
- func (t *Table) Get(k *Node) *Node
- func (t *Table) GetByString(s string) *Node
- func (t *Table) GetFloat64ByString(s string) (float64, error)
- func (t *Table) GetPath(path ...*Node) (*Table, *Node, error)
- func (t *Table) GetStringByString(s string) (string, error)
- func (t *Table) GetStringPath(path ...string) (*Table, *Node, error)
- func (t *Table) HasKey(k *Node) bool
- func (t *Table) HasKeyByString(s string) bool
- func (t *Table) Keys() []*Node
- func (t *Table) Len() int
- func (t *Table) Set(k, v *Node)
- func (t *Table) String() string
- type Token
- type Tokenizer
Constants ¶
const ( // LogLevelDebug will log debug messages LogLevelDebug = iota // LogLevelErrors will output errors-only LogLevelErrors )
const ( // NodeTypeString is a node containing a string NodeTypeString = iota // NodeTypeIdentifier is a node containing an identifier NodeTypeIdentifier // NodeTypeNumber is a node containing a number NodeTypeNumber // NodeTypeBool is a node containing a bool NodeTypeBool // NodeTypeTable is a node containing a table NodeTypeTable // NodeTypeTableEntry is a node containing a table entry NodeTypeTableEntry )
const ( StateTokenNone = iota StateTokenBareHyphen StateTokenFindNewline StateTokenString StateTokenEscapedChar StateTokenNumber StateTokenIdentifier StateTokenInvalid )
const ( TokenTypeStartTable = iota TokenTypeEndTable TokenTypeStartKey TokenTypeEndKey TokenTypeEquals TokenTypeComma TokenTypeIgnore TokenTypeString TokenTypeNumber TokenTypeIdentifier )
Variables ¶
var ( // ErrNotFound indicates the requested node wasn't found ErrNotFound = errors.New("Node not found") // ErrNotTable indicates the node wasn't a table ErrNotTable = errors.New("Node not a table") // ErrWrongType indicates that the node was the wrong type ErrWrongType = errors.New("Node is wrong type") )
var ( // NaN is not a number NaN = math.NaN() )
Functions ¶
This section is empty.
Types ¶
type DefaultLogger ¶
type DefaultLogger int
DefaultLogger is a wrapper around the log package that conditionally logs based on its log level
func (DefaultLogger) Debugf ¶
func (level DefaultLogger) Debugf(tmpl string, v ...interface{})
Debugf outputs a debug message if logging is set to LogLevelDebug
func (DefaultLogger) Errorf ¶
func (level DefaultLogger) Errorf(tmpl string, v ...interface{})
Errorf outputs and error message
type Logger ¶
type Logger interface {
Debugf(tmpl string, v ...interface{})
Errorf(tmpl string, v ...interface{})
}
A Logger has a debug and error logging function
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node contains a parsed value. This value can be a scalar or a table
func NewNode ¶
NewNode creates a node of the given type with the provided value. It assumes the specified type is appropriate for the value.
func (*Node) Equals ¶
Equals returns whether this node is equal to another. For this to be true the types and values must match. Not all types support equality testing.
func (*Node) GetBool ¶
GetBool returns the value of the node if it's a bool and false if it is not. You should check that the node type is a bool first.
func (*Node) GetFloat64 ¶
GetFloat64 returns the underlying value of the node if it is numeric and NaN if not
func (*Node) GetString ¶
GetString returns the underlying string value of the node if it is a string or identifier type and empty string if not
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles parsing tokens into Nodes
func (*Parser) Peek ¶
Peek returns the node on top of the stack without removing it. It returns nil if the stack is empty.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is the top-level data structure returned by parsing. The table consists of table entries. Each entry has a key and a value, each of type Node.
func (*Table) AddIndexed ¶
AddIndexed appends the node to the table. The key for the new node is the current number of entries. This value is returned.
func (*Table) GetByString ¶
GetByString looks for an entry with a key node of type string matching the provided string value. If no matching node is found nil is returned.
func (*Table) GetFloat64ByString ¶
GetFloatByString looks for an entry in the table with a string key equal to the provided string and a value of type Number. It returns an error if no entry has a matching key or the matching entry node is not a Number.
func (*Table) GetStringByString ¶
GetStringByString looks for an entry in the table with a string key equal to the provided string and a value of type string. It returns an error if no entry has a matching key or the matching entry node is not a string.
func (*Table) GetStringPath ¶
GetStringByPath walks through nested tables to find a node matching the path. All keys in the path must be strings.
func (*Table) HasKey ¶
HasKey checks whether the table has an entry with a key equal to the provided key node.
func (*Table) HasKeyByString ¶
HasKeyByString checks whether the table has an entry with the provided key string. This does not parse numeric strings to compare to numeric keys.
type Tokenizer ¶
type Tokenizer struct {
// contains filtered or unexported fields
}
A Tokenizer processes a string, yielding Tokens.
func NewTokenizer ¶
NewTokenizer creates a new Tokenizer to process the supplied string. It will provide each token to the supplied callback function. If the callback returns an error, tokenization will stop.
func (*Tokenizer) Emit ¶
If there's been no previous error, send a token to the callback and capture any returned error.
func (*Tokenizer) Send ¶
Create a new token from the buffer of the specified type, Emit() the token, then clear the buffer.
func (*Tokenizer) SetStateToken ¶
Set the current state. If the specified state is invalid, nothing happens.