Loading a YamlDocument topic

A single YAML source string is considered a YAML document. The presence/absence of directives determines what type of document it is.

Bare Documents

Clean YamlDocument with no directives.

  const yaml = '''

# Okay if empty
...

Wow! Nice! This looks clean
...
''';

final docs = loadAllDocuments(source: yaml);

print(docs.length); // 2

// True
print(
  docs.every(
    (doc) =>
        doc.hasExplicitEnd &&
        !doc.hasExplicitStart &&
        doc.docType == YamlDocType.bare,
  ),
);

Explicit Documents

Documents with directive end markers (---) and optionally document end markers (...). Why optionally? The directive end markers signify the start of a document.

  const yaml = '''
--- # Ends after the next comment
    # LFG
...

---
"This one has a double quoted scalar, but no doc end"

---
status: Started immediately the marker was seen.
''';

final docs = loadAllDocuments(source: yaml);

print(docs.length); // 3

// True
print(
  docs.every(
    (doc) => doc.hasExplicitStart && doc.docType == YamlDocType.explicit,
  ),
);

Directive Documents

Documents with directives. The directives must always end with marker (---) even if the document is empty!

  const yaml = '''
%YAML 1.1
%SUPPORT on that version is limited
%TAG !for-real! !yah-for-real
---

"You can just do this things. Do them with version 1.2+ features"
''';

final doc = loadAllDocuments(source: yaml).first;

// True
print(
  doc.hasExplicitStart &&
      doc.docType == YamlDocType.directiveDoc &&
      doc.tagDirectives.isNotEmpty &&
      doc.otherDirectives.isNotEmpty &&
      doc.versionDirective == YamlDirective.ofVersion('1.1'),
);

Classes

Directive Loading a YamlDocument
A valid YAML directive
GlobalTag<T> Loading a YamlDocument Types of Tags Declaring Tags in Code
Describes a tag shorthand notation for specifying node tags. It must begin with the %TAG directive.
ReservedDirective Loading a YamlDocument
Represents any unknown directive which YAML, by default, reserves for future use. Typically any that is not a YamlDirective or a GlobalTag.
YamlComment Loading a YamlDocument
A comment parsed in a document
YamlDirective Loading a YamlDocument
Specifies the version a YAML document conforms to.
YamlDocument Loading a YamlDocument Dumping YAML Documents
A document representing the entire YAML string or a single scalar/collection node within a group of documents in YAML.

Properties

parserVersion YamlDirective Loading a YamlDocument
YAML version that is used to implement the current YamlParser version.
final

Functions

loadAllDocuments({String? source, Iterable<int>? byteSource, bool throwOnMapDuplicate = false, List<Resolver>? resolvers, void logger(bool isInfo, String message)?}) List<YamlDocument> Loading a YamlDocument
Loads every document. Each document's root node will always be a YamlSourceNode.

Enums

DocumentMarker Loading a YamlDocument
YamlDocType Loading a YamlDocument
Represents the type of YAML document based on the use of directives, directives end marker (---) and document end marker (...)