MCPcopy
hub / github.com/pelletier/go-toml / handleKeyValueExpression

Method handleKeyValueExpression

unmarshaler.go:1341–1379  ·  view source on GitHub ↗

handleKeyValueExpression stores the value of a top-level key-value expression, relative to the current table.

(expr *unstable.Node, root reflect.Value)

Source from the content-addressed store, hash-verified

1339// handleKeyValueExpression stores the value of a top-level key-value
1340// expression, relative to the current table.
1341func (d *decoder) handleKeyValueExpression(expr *unstable.Node, root reflect.Value) error {
1342 d.path = d.path[:0]
1343
1344 target := root
1345 useCache := d.tableTargetValid && len(d.tableKey) > 0
1346 if useCache {
1347 target = d.tableTarget
1348 } else {
1349 for _, name := range d.tableKey {
1350 d.path = append(d.path, pathPart{name: name})
1351 }
1352 }
1353
1354 it := expr.Key()
1355 for it.Next() {
1356 d.path = append(d.path, pathPart{node: it.Node()})
1357 }
1358
1359 nv, err := d.descend(target, d.path, 0, expr, expr.Value())
1360 if err != nil {
1361 return d.contextualizeError(err, useCache)
1362 }
1363 if !nv.IsValid() {
1364 return nil
1365 }
1366 if useCache {
1367 // The target may have been replaced (e.g. a nil map allocated):
1368 // re-link it into its parent.
1369 if nv.Kind() == reflect.Map && nv.Pointer() != d.tableTarget.Pointer() {
1370 d.storeSlot(&d.tableParentSlot, nv)
1371 d.tableTarget = nv
1372 }
1373 } else {
1374 if root.CanSet() {
1375 root.Set(nv)
1376 }
1377 }
1378 return nil
1379}
1380
1381// descend walks the given key path into v, and assigns the value at the
1382// end. It returns the value to store back at this level. An invalid value

Callers 1

handleRootExpressionMethod · 0.95

Calls 7

descendMethod · 0.95
contextualizeErrorMethod · 0.95
storeSlotMethod · 0.95
NodeMethod · 0.80
ValueMethod · 0.80
KeyMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected