loadYamlDocument function
Loads a single document from a YAML string as a YamlDocument.
This is just like loadYaml, except that where loadYaml would return a normal Dart value this returns a YamlDocument instead. This allows the caller to access document metadata.
Implementation
YamlDocument loadYamlDocument(String yaml,
{Uri? sourceUrl, bool recover = false, ErrorListener? errorListener}) {
var loader = Loader(yaml,
sourceUrl: sourceUrl, recover: recover, errorListener: errorListener);
var document = loader.load();
if (document == null) {
return YamlDocument.internal(YamlScalar.internalWithSpan(null, loader.span),
loader.span, null, const []);
}
var nextDocument = loader.load();
if (nextDocument != null) {
throw YamlException('Only expected one document.', nextDocument.span);
}
return document;
}