Skip to content

Commit

Permalink
Fix metadata - alternate approach
Browse files Browse the repository at this point in the history
  • Loading branch information
maroux committed Jul 9, 2024
1 parent eb72747 commit ec44906
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
16 changes: 16 additions & 0 deletions internal/toml-test/tests/valid/table/sub-sub-subtable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"x": {
"y": {
"z": {
"a": {
"type": "integer",
"value": "1"
},
"b": {
"type": "integer",
"value": "2"
}
}
}
}
}
3 changes: 3 additions & 0 deletions internal/toml-test/tests/valid/table/sub-sub-subtable.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[x.y.z]
a = 1
b = 2
16 changes: 8 additions & 8 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ func (p *parser) valueInlineTable(it item, parentIsArray bool) (any, tomlType) {
outerKey = p.currentKey
)

p.context = append(p.context, p.currentKey)
p.context = p.context.add(p.currentKey)
prevContext := p.context
p.currentKey = ""

Expand Down Expand Up @@ -603,7 +603,7 @@ func (p *parser) addContext(key Key, array bool) {
} else {
p.setValue(key.last(), make(map[string]any))
}
p.context = append(p.context, key.last())
p.context = p.context.add(key.last())
}

// setValue sets the given key to the given value in the current context.
Expand All @@ -614,10 +614,10 @@ func (p *parser) setValue(key string, value any) {
tmpHash any
ok bool
hash = p.mapping
keyContext = make(Key, 0, len(p.context)+1)
keyContext = make(Key, len(p.context)+1)
)
for _, k := range p.context {
keyContext = append(keyContext, k)
for i, k := range p.context {
keyContext[i] = k
if tmpHash, ok = hash[k]; !ok {
p.bug("Context for key '%s' has not been established.", keyContext)
}
Expand All @@ -632,7 +632,7 @@ func (p *parser) setValue(key string, value any) {
p.panicf("Key '%s' has already been defined.", keyContext)
}
}
keyContext = append(keyContext, key)
keyContext[len(p.context)] = key

if _, ok := hash[key]; ok {
// Normally redefining keys isn't allowed, but the key could have been
Expand Down Expand Up @@ -667,8 +667,8 @@ func (p *parser) setValue(key string, value any) {
// Note that if `key` is empty, then the type given will be applied to the
// current context (which is either a table or an array of tables).
func (p *parser) setType(key string, typ tomlType, pos Position) {
keyContext := make(Key, 0, len(p.context)+1)
keyContext = append(keyContext, p.context...)
keyContext := make(Key, len(p.context), len(p.context)+1)
copy(keyContext, p.context)
if len(key) > 0 { // allow type setting for hashes
keyContext = append(keyContext, key)
}
Expand Down

0 comments on commit ec44906

Please sign in to comment.