Top level block scalar without indentation
Hi,
I noticed that LibYAML doesn't parse block scalar without indentation.
Sample: 1
---
XXX
YYY
ZZZ
Sample: 2
--- |
XXX
YYY
ZZZ
I expected that these samples would be parsed like this:
[{"Sample": 1}, "XXX YYY ZZZ"]
[{"Sample": 2}, "XXX\nYYY\nZZZ\n"]
LibYAML can parse Sample 1 but not Sample 2.
$ ./run-parser Sample1.yaml
[1] Parsing 'Sample1.yaml': SUCCESS (11 events)
$ ./run-parser Sample2.yaml
[1] Parsing 'Sample2.yaml': FAILURE (10 events)
PyYAML returned error.
expected '<document start>', but found '<scalar>'
I checked some implementations. The results are:
Syck (YAML 1.0) - Ruby
Sample1 ... PASS
Sample2 ... PASS
YAML.pm (YAML 1.0) - Perl
Sample1 ... FAIL
Sample2 ... PASS
PyYAML (YAML 1.1) - Python / LibYAML
Sample1 ... PASS
Sample2 ... FAIL
Psych (YAML 1.1) - Ruby / LibYAML
Sample1 ... PASS
Sample2 ... FAIL
SnakeYAML (YAML 1.1) - Java / based on LibYAML
Sample1 ... PASS
Sample2 ... FAIL
JS-YAML (YAML 1.2) - JavaScript
Sample1 ... PASS
Sample2 ... PASS
Yamerl (YAML 1.2) - Erlang
Sample1 ... PASS
Sample2 ... PASS
My questions are:
(1) Which parsers are implemented properly, at this point?
(2) Is there possibility that LibYAML support Sample2?
At YAML 1.1 trunk or future 1.2 branch?
In YAML 1.0 spec, Example 4.21 says:
--- |
Usually top level nodes are not indented.
In YAML 1.2 spec, Example 9.5 says:
%YAML 1.2
--- |
%!PS-Adobe-2.0
...
%YAML 1.2
---
!!str "%!PS-Adobe-2.0\n"
...
I couldn't find an example like these in the YAML 1.1 spec.
It may be determined by [161] detect(m) being able to return 0 or not.
I found this message.
* http://osdir.com/ml/text.yaml.general/2008-07/msg00001.html
> The spec requires that continuation lines of a flow scalar are indented
> with at least one space. LibYAML relaxes this rule by allowing
> multi-line flow scalars not to be indented,
So I realized that the Sample1 result was came from relaxing
the spec. But how about the block scalar, Sample 2?
I think this notation is important, because this enable to append
metadata to the plain text.
An email will be represented like this.
Date: 2013-04-13 20:10:53+09:00
Subject: Top level block scalar without indentation
From: koseki@...
To: yaml-core@...
--- |
Hi,
I noticed that ...
Using template engine to generate HTML.
title: YAML block scalar
template: blog
published: 2013-04-13
--- |
<article>
<h1>xxxxxx</h1>
<pre>
Here must
be written in
multi lines.
</pre>
</article>
Best regards,
--
--
koseki
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter