Parsing and emitting multiple documents in a stream

If an input stream contains several documents, you may load all of them using the yaml.load_all function.

>>> data ="""
... This is the first document
... --- # This is an empty document
... ---
... - this
... - is: the
... last: document
... """>>>for document in yaml.load_all(data):print document
This is the first document
None['this',{'is':'the','last':'document'}]

You may also dump several documents into the same stream using the yaml.dump_all function.

>>>print yaml.dump_all(["The first document",None,["The","last","document"]])
The first document
--- null
---- The
- last
- document

To Do

Deviations from the specification

rules for tabs in YAML are confusing. We are close, but not there yet.
Perhaps both the spec and the parser should be fixed. Anyway, the best
rule for tabs in YAML is to not use them at all.

Byte order mark. The initial BOM is stripped, but BOMs inside the stream
are considered as parts of the content. It can be fixed, but it's not
really important now.

Empty plain scalars are not allowed if alias or tag is specified. This
is done to prevent anomalities like [ !tag, value], which can be
interpreted both as [ !<!tag,> value ] and [ !<!tag> "", "value" ].
The spec should be fixed.

Indentation of flow collections. The spec requires them to be indented
more then their block parent node. Unfortunately this rule many intuitively
correct constructs invalid, for instance,

block: {
} # this is indentation violation according to the spec.

':' is not allowed for plain scalars in the flow mode. {1:2} is
interpreted as { 1 : 2 }.