aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/pelletier/go-toml
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pelletier/go-toml')
-rw-r--r--vendor/github.com/pelletier/go-toml/keysparsing.go11
-rw-r--r--vendor/github.com/pelletier/go-toml/lexer.go24
-rw-r--r--vendor/github.com/pelletier/go-toml/parser.go71
-rw-r--r--vendor/github.com/pelletier/go-toml/tomltree_conversions.go45
4 files changed, 81 insertions, 70 deletions
diff --git a/vendor/github.com/pelletier/go-toml/keysparsing.go b/vendor/github.com/pelletier/go-toml/keysparsing.go
index b67664f..d62ca5f 100644
--- a/vendor/github.com/pelletier/go-toml/keysparsing.go
+++ b/vendor/github.com/pelletier/go-toml/keysparsing.go
@@ -4,6 +4,7 @@ package toml
import (
"bytes"
+ "errors"
"fmt"
"unicode"
)
@@ -47,7 +48,7 @@ func parseKey(key string) ([]string, error) {
} else {
if !wasInQuotes {
if buffer.Len() == 0 {
- return nil, fmt.Errorf("empty key group")
+ return nil, errors.New("empty table key")
}
groups = append(groups, buffer.String())
buffer.Reset()
@@ -67,23 +68,23 @@ func parseKey(key string) ([]string, error) {
return nil, fmt.Errorf("invalid bare character: %c", char)
}
if !inQuotes && expectDot {
- return nil, fmt.Errorf("what?")
+ return nil, errors.New("what?")
}
buffer.WriteRune(char)
expectDot = false
}
}
if inQuotes {
- return nil, fmt.Errorf("mismatched quotes")
+ return nil, errors.New("mismatched quotes")
}
if escapeNext {
- return nil, fmt.Errorf("unfinished escape sequence")
+ return nil, errors.New("unfinished escape sequence")
}
if buffer.Len() > 0 {
groups = append(groups, buffer.String())
}
if len(groups) == 0 {
- return nil, fmt.Errorf("empty key")
+ return nil, errors.New("empty key")
}
return groups, nil
}
diff --git a/vendor/github.com/pelletier/go-toml/lexer.go b/vendor/github.com/pelletier/go-toml/lexer.go
index eb4d999..4b378d4 100644
--- a/vendor/github.com/pelletier/go-toml/lexer.go
+++ b/vendor/github.com/pelletier/go-toml/lexer.go
@@ -129,7 +129,7 @@ func (l *tomlLexer) lexVoid() tomlLexStateFn {
next := l.peek()
switch next {
case '[':
- return l.lexKeyGroup
+ return l.lexTableKey
case '#':
return l.lexComment
case '=':
@@ -516,21 +516,21 @@ func (l *tomlLexer) lexString() tomlLexStateFn {
return l.lexRvalue
}
-func (l *tomlLexer) lexKeyGroup() tomlLexStateFn {
+func (l *tomlLexer) lexTableKey() tomlLexStateFn {
l.next()
if l.peek() == '[' {
- // token '[[' signifies an array of anonymous key groups
+ // token '[[' signifies an array of tables
l.next()
l.emit(tokenDoubleLeftBracket)
- return l.lexInsideKeyGroupArray
+ return l.lexInsideTableArrayKey
}
- // vanilla key group
+ // vanilla table key
l.emit(tokenLeftBracket)
- return l.lexInsideKeyGroup
+ return l.lexInsideTableKey
}
-func (l *tomlLexer) lexInsideKeyGroupArray() tomlLexStateFn {
+func (l *tomlLexer) lexInsideTableArrayKey() tomlLexStateFn {
for r := l.peek(); r != eof; r = l.peek() {
switch r {
case ']':
@@ -545,15 +545,15 @@ func (l *tomlLexer) lexInsideKeyGroupArray() tomlLexStateFn {
l.emit(tokenDoubleRightBracket)
return l.lexVoid
case '[':
- return l.errorf("group name cannot contain ']'")
+ return l.errorf("table array key cannot contain ']'")
default:
l.next()
}
}
- return l.errorf("unclosed key group array")
+ return l.errorf("unclosed table array key")
}
-func (l *tomlLexer) lexInsideKeyGroup() tomlLexStateFn {
+func (l *tomlLexer) lexInsideTableKey() tomlLexStateFn {
for r := l.peek(); r != eof; r = l.peek() {
switch r {
case ']':
@@ -564,12 +564,12 @@ func (l *tomlLexer) lexInsideKeyGroup() tomlLexStateFn {
l.emit(tokenRightBracket)
return l.lexVoid
case '[':
- return l.errorf("group name cannot contain ']'")
+ return l.errorf("table key cannot contain ']'")
default:
l.next()
}
}
- return l.errorf("unclosed key group")
+ return l.errorf("unclosed table key")
}
func (l *tomlLexer) lexRightBracket() tomlLexStateFn {
diff --git a/vendor/github.com/pelletier/go-toml/parser.go b/vendor/github.com/pelletier/go-toml/parser.go
index 25932d7..20e90a3 100644
--- a/vendor/github.com/pelletier/go-toml/parser.go
+++ b/vendor/github.com/pelletier/go-toml/parser.go
@@ -3,6 +3,7 @@
package toml
import (
+ "errors"
"fmt"
"reflect"
"regexp"
@@ -15,8 +16,8 @@ type tomlParser struct {
flow chan token
tree *TomlTree
tokensBuffer []token
- currentGroup []string
- seenGroupKeys []string
+ currentTable []string
+ seenTableKeys []string
}
type tomlParserStateFn func() tomlParserStateFn
@@ -95,13 +96,13 @@ func (p *tomlParser) parseGroupArray() tomlParserStateFn {
startToken := p.getToken() // discard the [[
key := p.getToken()
if key.typ != tokenKeyGroupArray {
- p.raiseError(key, "unexpected token %s, was expecting a key group array", key)
+ p.raiseError(key, "unexpected token %s, was expecting a table array key", key)
}
- // get or create group array element at the indicated part in the path
+ // get or create table array element at the indicated part in the path
keys, err := parseKey(key.val)
if err != nil {
- p.raiseError(key, "invalid group array key: %s", err)
+ p.raiseError(key, "invalid table array key: %s", err)
}
p.tree.createSubTree(keys[:len(keys)-1], startToken.Position) // create parent entries
destTree := p.tree.GetPath(keys)
@@ -111,32 +112,32 @@ func (p *tomlParser) parseGroupArray() tomlParserStateFn {
} else if target, ok := destTree.([]*TomlTree); ok && target != nil {
array = destTree.([]*TomlTree)
} else {
- p.raiseError(key, "key %s is already assigned and not of type group array", key)
+ p.raiseError(key, "key %s is already assigned and not of type table array", key)
}
- p.currentGroup = keys
+ p.currentTable = keys
- // add a new tree to the end of the group array
+ // add a new tree to the end of the table array
newTree := newTomlTree()
newTree.position = startToken.Position
array = append(array, newTree)
- p.tree.SetPath(p.currentGroup, array)
+ p.tree.SetPath(p.currentTable, array)
- // remove all keys that were children of this group array
+ // remove all keys that were children of this table array
prefix := key.val + "."
found := false
- for ii := 0; ii < len(p.seenGroupKeys); {
- groupKey := p.seenGroupKeys[ii]
- if strings.HasPrefix(groupKey, prefix) {
- p.seenGroupKeys = append(p.seenGroupKeys[:ii], p.seenGroupKeys[ii+1:]...)
+ for ii := 0; ii < len(p.seenTableKeys); {
+ tableKey := p.seenTableKeys[ii]
+ if strings.HasPrefix(tableKey, prefix) {
+ p.seenTableKeys = append(p.seenTableKeys[:ii], p.seenTableKeys[ii+1:]...)
} else {
- found = (groupKey == key.val)
+ found = (tableKey == key.val)
ii++
}
}
// keep this key name from use by other kinds of assignments
if !found {
- p.seenGroupKeys = append(p.seenGroupKeys, key.val)
+ p.seenTableKeys = append(p.seenTableKeys, key.val)
}
// move to next parser state
@@ -148,24 +149,24 @@ func (p *tomlParser) parseGroup() tomlParserStateFn {
startToken := p.getToken() // discard the [
key := p.getToken()
if key.typ != tokenKeyGroup {
- p.raiseError(key, "unexpected token %s, was expecting a key group", key)
+ p.raiseError(key, "unexpected token %s, was expecting a table key", key)
}
- for _, item := range p.seenGroupKeys {
+ for _, item := range p.seenTableKeys {
if item == key.val {
p.raiseError(key, "duplicated tables")
}
}
- p.seenGroupKeys = append(p.seenGroupKeys, key.val)
+ p.seenTableKeys = append(p.seenTableKeys, key.val)
keys, err := parseKey(key.val)
if err != nil {
- p.raiseError(key, "invalid group array key: %s", err)
+ p.raiseError(key, "invalid table array key: %s", err)
}
if err := p.tree.createSubTree(keys, startToken.Position); err != nil {
p.raiseError(key, "%s", err)
}
p.assume(tokenRightBracket)
- p.currentGroup = keys
+ p.currentTable = keys
return p.parseStart
}
@@ -174,26 +175,26 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
p.assume(tokenEqual)
value := p.parseRvalue()
- var groupKey []string
- if len(p.currentGroup) > 0 {
- groupKey = p.currentGroup
+ var tableKey []string
+ if len(p.currentTable) > 0 {
+ tableKey = p.currentTable
} else {
- groupKey = []string{}
+ tableKey = []string{}
}
- // find the group to assign, looking out for arrays of groups
+ // find the table to assign, looking out for arrays of tables
var targetNode *TomlTree
- switch node := p.tree.GetPath(groupKey).(type) {
+ switch node := p.tree.GetPath(tableKey).(type) {
case []*TomlTree:
targetNode = node[len(node)-1]
case *TomlTree:
targetNode = node
default:
- p.raiseError(key, "Unknown group type for path: %s",
- strings.Join(groupKey, "."))
+ p.raiseError(key, "Unknown table type for path: %s",
+ strings.Join(tableKey, "."))
}
- // assign value to the found group
+ // assign value to the found table
keyVals, err := parseKey(key.val)
if err != nil {
p.raiseError(key, "%s", err)
@@ -203,7 +204,7 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
}
keyVal := keyVals[0]
localKey := []string{keyVal}
- finalKey := append(groupKey, keyVal)
+ finalKey := append(tableKey, keyVal)
if targetNode.GetPath(localKey) != nil {
p.raiseError(key, "The following key was defined twice: %s",
strings.Join(finalKey, "."))
@@ -211,7 +212,7 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
var toInsert interface{}
switch value.(type) {
- case *TomlTree:
+ case *TomlTree, []*TomlTree:
toInsert = value
default:
toInsert = &tomlValue{value, key.Position}
@@ -224,7 +225,7 @@ var numberUnderscoreInvalidRegexp *regexp.Regexp
func cleanupNumberToken(value string) (string, error) {
if numberUnderscoreInvalidRegexp.MatchString(value) {
- return "", fmt.Errorf("invalid use of _ in number")
+ return "", errors.New("invalid use of _ in number")
}
cleanedVal := strings.Replace(value, "_", "", -1)
return cleanedVal, nil
@@ -380,8 +381,8 @@ func parseToml(flow chan token) *TomlTree {
flow: flow,
tree: result,
tokensBuffer: make([]token, 0),
- currentGroup: make([]string, 0),
- seenGroupKeys: make([]string, 0),
+ currentTable: make([]string, 0),
+ seenTableKeys: make([]string, 0),
}
parser.run()
return result
diff --git a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
index bf9321b..db3da0d 100644
--- a/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
+++ b/vendor/github.com/pelletier/go-toml/tomltree_conversions.go
@@ -79,11 +79,11 @@ func toTomlValue(item interface{}, indent int) string {
case time.Time:
return tab + value.Format(time.RFC3339)
case []interface{}:
- result := tab + "[\n"
+ values := []string{}
for _, item := range value {
- result += toTomlValue(item, indent+2) + ",\n"
+ values = append(values, toTomlValue(item, 0))
}
- return result + tab + "]"
+ return "[" + strings.Join(values, ",") + "]"
case nil:
return ""
default:
@@ -92,57 +92,66 @@ func toTomlValue(item interface{}, indent int) string {
}
// Recursive support function for ToString()
-// Outputs a tree, using the provided keyspace to prefix group names
+// Outputs a tree, using the provided keyspace to prefix table names
func (t *TomlTree) toToml(indent, keyspace string) string {
- result := ""
+ resultChunks := []string{}
for k, v := range t.values {
// figure out the keyspace
combinedKey := k
if keyspace != "" {
combinedKey = keyspace + "." + combinedKey
}
+ resultChunk := ""
// output based on type
switch node := v.(type) {
case []*TomlTree:
for _, item := range node {
if len(item.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[[%s]]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[[%s]]\n", indent, combinedKey)
}
- result += item.toToml(indent+" ", combinedKey)
+ resultChunk += item.toToml(indent+" ", combinedKey)
}
+ resultChunks = append(resultChunks, resultChunk)
case *TomlTree:
if len(node.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += node.toToml(indent+" ", combinedKey)
+ resultChunk += node.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case map[string]interface{}:
sub := TreeFromMap(node)
if len(sub.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += sub.toToml(indent+" ", combinedKey)
+ resultChunk += sub.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case map[string]string:
sub := TreeFromMap(convertMapStringString(node))
if len(sub.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += sub.toToml(indent+" ", combinedKey)
+ resultChunk += sub.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case map[interface{}]interface{}:
sub := TreeFromMap(convertMapInterfaceInterface(node))
if len(sub.Keys()) > 0 {
- result += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
+ resultChunk += fmt.Sprintf("\n%s[%s]\n", indent, combinedKey)
}
- result += sub.toToml(indent+" ", combinedKey)
+ resultChunk += sub.toToml(indent+" ", combinedKey)
+ resultChunks = append(resultChunks, resultChunk)
case *tomlValue:
- result += fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(node.value, 0))
+ resultChunk = fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(node.value, 0))
+ resultChunks = append([]string{resultChunk}, resultChunks...)
default:
- result += fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(v, 0))
+ resultChunk = fmt.Sprintf("%s%s = %s\n", indent, k, toTomlValue(v, 0))
+ resultChunks = append([]string{resultChunk}, resultChunks...)
}
+
}
- return result
+ return strings.Join(resultChunks, "")
}
func convertMapStringString(in map[string]string) map[string]interface{} {