YamlSourceNodes topic

YAML allows nodes to be declared using a block or flow style. You can use flow styles in block but not the other way around. Types of node include:

  1. Scalar - anything that is not a map/list in Dart
  2. Sequence - list in Dart. Set support not yet available
  3. Mapping - map in Dart

Scalars

Any node that is not a Sequence or Mapping. By default, its type is inferred out of the box.

final node = loadYamlNode<Scalar>(source: YamlSource.string('24'));
print(yamlCollectionEquality.equals(24, node)); // True.

Sequences (Lists)

An immutable list. Allows all node types to be used.

import 'package:collection/collection.dart';

const yaml = '''
- rookie_yaml. The
- new kid
- in town
''';

final node = loadYamlNode<Sequence>(source: YamlSource.string(yaml));

// True.
print(
  yamlCollectionEquality.equals(node, [
    'rookie_yaml. The',
    'new kid',
    'in town',
  ]),
);

Mapping (Map)

An immutable map. Allows any node type as a key or value just like a Dart map.

// Let's get funky.
const mappy = {
  'name': 'rookie_yaml',
  'in_active_development': true,
  'supports':  {
    1: 'Full YAML spec',
    2: 'Custom tags and resolvers',
  }
};

// Built-in Dart types as strings are just flow nodes in yaml
final node = loadYamlNode<Mapping>(
  source: YamlSource.string(mappy.toString()),
);

// True.
print(yamlCollectionEquality.equals(node, mappy));

Caution

The parser does not restrict implicit keys to at most 1024 unicode characters as instructed by YAML for flow and for block. This may change in later versions.

Classes

AliasNode Introduction YamlSourceNodes Anchors and Aliases
A node that is a pointer to another node.
Mapping Introduction YamlSourceNodes
A YAML Map which mirrors an actual Dart Map in equality and shape.
Scalar<T> Introduction YamlSourceNodes
Any value that is not a Sequence or Mapping.
Sequence Introduction YamlSourceNodes
A YAML List which mirrors an actual Dart List in equality and shape.
YamlSourceNode Introduction YamlSourceNodes
A node parsed from a YAML source string.

Constants

yamlCollectionEquality → const DeepCollectionEquality YamlSourceNodes
A custom Equality object for deep equality. This includes AliasNodes which wrap their YamlSourceNode subclass references.

Functions

loadNodes(YamlSource source, {bool throwOnMapDuplicate = false, List<ScalarResolver<Object?>>? resolvers, void logger(bool isInfo, String message)?}) Iterable<YamlSourceNode> YamlSourceNodes
Loads every document's root node as a YamlSourceNode.
loadYamlNode<T extends YamlSourceNode>(YamlSource source, {bool throwOnMapDuplicate = false, List<ScalarResolver<Object?>>? resolvers, void logger(bool isInfo, String message)?}) → T? YamlSourceNodes
Loads the first document's root as a YamlSourceNode
yamlSourceNodeDeepEqual(YamlSourceNode thiz, YamlSourceNode that) bool YamlSourceNodes
Checks if 2 YamlSourceNode are equal based on the YAML spec.

Enums

ChompingIndicator YamlSourceNodes
Controls how final line breaks and trailing empty lines are interpreted.
NodeStyle YamlSourceNodes
Indicates how each CompactYamlNode is presented in the serialized yaml string.
ScalarStyle YamlSourceNodes
Indicates how each Scalar is presented in a serialized yaml string.