Loading a YamlSourceNode 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: '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: 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: mappy.toString());

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

Caution

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

Classes

AliasNode Introduction Loading a YamlSourceNode Anchors and Aliases
A node that is a pointer to another node.
CompactYamlNode Introduction Loading a YamlSourceNode Dumping YAML Nodes
A YamlNode with a set of node properties. This node is not necessarily limited to YAML's compact notation unless such a notation is required when the object is being dumped.
DartNode<T> Loading a YamlSourceNode
A simple wrapper for most Dart types. Effective if you want to access keys in a Mapping
Mapping Introduction Loading a YamlSourceNode
A read-only YAML Map which mirrors an actual Dart Map in equality but not shape.
Scalar<T> Introduction Loading a YamlSourceNode
Any value that is not a Sequence or Mapping.
Sequence Introduction Loading a YamlSourceNode
A read-only YAML List which mirrors an actual Dart List in equality but not shape.
YamlCollectionEquality Loading a YamlSourceNode
A DeepCollectionEquality implementation that treats YamlSourceNodes as immutable Dart objects.
YamlNode Introduction Loading a YamlSourceNode
A simple node dumpable to a YAML source string
YamlSourceNode Introduction Loading a YamlSourceNode
A node parsed from a YAML source string.

Constants

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

Functions

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

Enums

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