Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metadata - alternate approach #419

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading