Re: Top level block scalar without indentation
KOSEKI Kengo <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <CAD93B4Lq-c5vg3BzJ_r4i=r2d3wYebYSbmijrFBoSGuMAPVrSA@mail.gmail.com> |
Hi Oren,
Thanks for the clarification! I created a ticket for this.
http://pyyaml.org/ticket/288
> auto-detect does not return 0, it returns at least 1, but since we start
> with -1 this results with an overall 0 indentation (since production 207
> uses -1 and not 0).
Is YAML 1.1 same?
In YAML 1.1 spec, the rule [117] max(-1, 0) set n = 0.
So I think [166] detect(m) must return 0, not 1..
[117] c-l+block-scalar(n) ::= c-l+folded(max(n,0)) | c-l+literal(max(n,0))
[175] c-l+literal(n) ::= c-b-block-header(literal,m,t)
l-literal-content(n+m,t)
I'm not sure I'm understanding these parametered production rules..
Anyway, I hope I can use top level block scalar with libyaml.
2013/4/14 Oren Ben-Kiki <[email protected]>:
> Well, example 9.5 is pretty explicit in what the spec says. Note that the
> auto-detect does not return 0, it returns at least 1, but since we start
> with -1 this results with an overall 0 indentation (since production 207
> uses -1 and not 0).
>
> The same logic holds for both of your samples; example 9.3 shows an
> unindented plain at the top level.
>
> Oren.
>
>
>
> On Sat, Apr 13, 2013 at 2:10 PM, KOSEKI Kengo <[email protected]> wrote:
>>
>> 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: [email protected]
>> To: [email protected]
>> --- |
>> 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
>> _______________________________________________
>> Yaml-core mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/yaml-core
>
>
--
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