loadYamlStream function
Loads a stream of documents from a YAML string.
The return value is mostly normal Dart objects. However, since YAML mappings support some key types that the default Dart map implementation doesn't (NaN, lists, and maps), all maps in the returned document are YamlMaps. These have a few small behavioral differences from the default Map implementation; for details, see the YamlMap class.
In future versions, maps will instead be HashMaps with a custom equality operation.
If sourceUrl
is passed, it's used as the URL from which the YAML
originated for error reporting.
Implementation
YamlList loadYamlStream(String yaml, {Uri? sourceUrl}) {
var loader = Loader(yaml, sourceUrl: sourceUrl);
var documents = <YamlDocument>[];
var document = loader.load();
while (document != null) {
documents.add(document);
document = loader.load();
}
// TODO(jmesserly): the type on the `document` parameter is a workaround for:
// https://github.com/dart-lang/dev_compiler/issues/203
return YamlList.internal(
documents.map((YamlDocument document) => document.contents).toList(),
loader.span,
CollectionStyle.ANY);
}