aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/pelletier/go-toml/parser.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pelletier/go-toml/parser.go')
-rw-r--r--vendor/github.com/pelletier/go-toml/parser.go71
1 files changed, 61 insertions, 10 deletions
diff --git a/vendor/github.com/pelletier/go-toml/parser.go b/vendor/github.com/pelletier/go-toml/parser.go
index a7498e49b3..7bf40bbdc7 100644
--- a/vendor/github.com/pelletier/go-toml/parser.go
+++ b/vendor/github.com/pelletier/go-toml/parser.go
@@ -158,6 +158,11 @@ func (p *tomlParser) parseGroup() tomlParserStateFn {
if err := p.tree.createSubTree(keys, startToken.Position); err != nil {
p.raiseError(key, "%s", err)
}
+ destTree := p.tree.GetPath(keys)
+ if target, ok := destTree.(*Tree); ok && target != nil && target.inline {
+ p.raiseError(key, "could not re-define exist inline table or its sub-table : %s",
+ strings.Join(keys, "."))
+ }
p.assume(tokenRightBracket)
p.currentTable = keys
return p.parseStart
@@ -201,6 +206,11 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
strings.Join(tableKey, "."))
}
+ if targetNode.inline {
+ p.raiseError(key, "could not add key or sub-table to exist inline table or its sub-table : %s",
+ strings.Join(tableKey, "."))
+ }
+
// assign value to the found table
keyVal := parsedKey[len(parsedKey)-1]
localKey := []string{keyVal}
@@ -313,7 +323,41 @@ func (p *tomlParser) parseRvalue() interface{} {
}
return val
case tokenDate:
- val, err := time.ParseInLocation(time.RFC3339Nano, tok.val, time.UTC)
+ layout := time.RFC3339Nano
+ if !strings.Contains(tok.val, "T") {
+ layout = strings.Replace(layout, "T", " ", 1)
+ }
+ val, err := time.ParseInLocation(layout, tok.val, time.UTC)
+ if err != nil {
+ p.raiseError(tok, "%s", err)
+ }
+ return val
+ case tokenLocalDate:
+ v := strings.Replace(tok.val, " ", "T", -1)
+ isDateTime := false
+ isTime := false
+ for _, c := range v {
+ if c == 'T' || c == 't' {
+ isDateTime = true
+ break
+ }
+ if c == ':' {
+ isTime = true
+ break
+ }
+ }
+
+ var val interface{}
+ var err error
+
+ if isDateTime {
+ val, err = ParseLocalDateTime(v)
+ } else if isTime {
+ val, err = ParseLocalTime(v)
+ } else {
+ val, err = ParseLocalDate(v)
+ }
+
if err != nil {
p.raiseError(tok, "%s", err)
}
@@ -356,12 +400,15 @@ Loop:
}
key := p.getToken()
p.assume(tokenEqual)
+
+ parsedKey, err := parseKey(key.val)
+ if err != nil {
+ p.raiseError(key, "invalid key: %s", err)
+ }
+
value := p.parseRvalue()
- tree.Set(key.val, value)
+ tree.SetPath(parsedKey, value)
case tokenComma:
- if previous == nil {
- p.raiseError(follow, "inline table cannot start with a comma")
- }
if tokenIsComma(previous) {
p.raiseError(follow, "need field between two commas in inline table")
}
@@ -374,12 +421,13 @@ Loop:
if tokenIsComma(previous) {
p.raiseError(previous, "trailing comma at the end of inline table")
}
+ tree.inline = true
return tree
}
func (p *tomlParser) parseArray() interface{} {
var array []interface{}
- arrayType := reflect.TypeOf(nil)
+ arrayType := reflect.TypeOf(newTree())
for {
follow := p.peek()
if follow == nil || follow.typ == tokenEOF {
@@ -390,11 +438,8 @@ func (p *tomlParser) parseArray() interface{} {
break
}
val := p.parseRvalue()
- if arrayType == nil {
- arrayType = reflect.TypeOf(val)
- }
if reflect.TypeOf(val) != arrayType {
- p.raiseError(follow, "mixed types in array")
+ arrayType = nil
}
array = append(array, val)
follow = p.peek()
@@ -408,6 +453,12 @@ func (p *tomlParser) parseArray() interface{} {
p.getToken()
}
}
+
+ // if the array is a mixed-type array or its length is 0,
+ // don't convert it to a table array
+ if len(array) <= 0 {
+ arrayType = nil
+ }
// An array of Trees is actually an array of inline
// tables, which is a shorthand for a table array. If the
// array was not converted from []interface{} to []*Tree,