Parsing Documents 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 = YamlParser(yaml).parseDocuments();
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 = YamlParser(yaml).parseDocuments();
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 = YamlParser(yaml).parseDocuments().first;
// True
print(
doc.hasExplicitStart &&
doc.docType == YamlDocType.directiveDoc &&
doc.tagDirectives.isNotEmpty &&
doc.otherDirectives.isNotEmpty &&
doc.versionDirective == YamlDirective.ofVersion('1.1'),
);
Classes
- Directive Parsing Documents
-
A valid
YAML
directive -
GlobalTag<
T> Parsing Documents -
Describes a tag shorthand notation for specifying node tags. It must begin
with the
%TAG
directive. - ReservedDirective Parsing Documents
-
Represents any unknown directive which
YAML
, by default, reserves for future use. Typically any that is not a YamlDirective or a GlobalTag. - YamlComment Parsing Documents
- A comment parsed in a document
- YamlDirective Parsing Documents
-
Specifies the version a
YAML
document conforms to. - YamlDocument Parsing Documents Dumping YAML Documents
-
A document representing the entire
YAML
string or a single scalar/collection node within a group of documents inYAML
. - YamlParser Introduction Parsing Documents
-
An intuitive top level
YAML
parser
Properties
- parserVersion → YamlDirective Parsing Documents
-
YAML
version that is used to implement the currentYamlParser
version.final
Enums
- DocumentMarker Parsing Documents
- YamlDocType Parsing Documents
-
Represents the type of YAML document based on the use of directives,
directives end marker (
---
) and document end marker (...
)