locateValues function

Map<String, ValueLocation> locateValues(
  1. String yamlText,
  2. SomMetaTree tree
)

Walks a v2 document's YAML text and returns every content value's location, keyed by document path.

Throws SpecYamlFormatException when a key fits no member — the same condition on which the decoder fails.

Implementation

Map<String, ValueLocation> locateValues(String yamlText, SomMetaTree tree) {
  final root = loadYamlNode(yamlText);
  final docPass = _mapping(root, 'the file')['document'];
  final walker = _Walker(tree);
  final body = _mapping(docPass, '`document:`');
  final rootEntry = body.nodes.entries.single;
  final rootKey = rootEntry.key as YamlNode;
  walker.walkMapping(
    tree.root,
    tree.root.segment,
    _idOf(rootKey.value),
    rootEntry.value,
  );
  return walker.locations;
}